stats stats stats stats
This commit is contained in:
parent
3fa53daadb
commit
72d5a1a64c
@ -131,7 +131,7 @@ func gameStats(w http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
g.stats.RLock()
|
g.stats.RLock()
|
||||||
defer g.stats.RUnlock()
|
defer g.stats.RUnlock()
|
||||||
if err := json.NewEncoder(w).Encode(g.stats); err != nil {
|
if err := json.NewEncoder(w).Encode(g.stats.PlayerStats); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
game.go
13
game.go
@ -41,12 +41,13 @@ func (ml *MapLock) add(g *game) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type BotStats struct {
|
type BotStats struct {
|
||||||
Kills int
|
Kills int
|
||||||
Deaths int
|
Deaths int
|
||||||
Suicides int
|
Suicides int
|
||||||
Shots int
|
Shots int
|
||||||
Hits int
|
DirectHits int
|
||||||
Wins int
|
Hits int
|
||||||
|
Wins int
|
||||||
}
|
}
|
||||||
|
|
||||||
type PlayerStats struct {
|
type PlayerStats struct {
|
||||||
|
@ -32,6 +32,8 @@ func (p *Projectile) Tick(g *game) {
|
|||||||
collision, _, _ := v.RectIntersection(player_rect, p.Position, v_scaled)
|
collision, _, _ := v.RectIntersection(player_rect, p.Position, v_scaled)
|
||||||
if collision {
|
if collision {
|
||||||
hit_player = true
|
hit_player = true
|
||||||
|
p.Owner.gameStats.Hits++
|
||||||
|
p.Owner.gameStats.DirectHits++
|
||||||
|
|
||||||
if r.Health > 0 {
|
if r.Health > 0 {
|
||||||
// Direct hit causes more damage
|
// Direct hit causes more damage
|
||||||
@ -39,6 +41,11 @@ func (p *Projectile) Tick(g *game) {
|
|||||||
|
|
||||||
r.Health -= p.Damage
|
r.Health -= p.Damage
|
||||||
r.Hit = true
|
r.Hit = true
|
||||||
|
|
||||||
|
if r.Health <= 0 {
|
||||||
|
r.gameStats.Deaths++
|
||||||
|
p.Owner.gameStats.Kills++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,6 +93,11 @@ func (p *Projectile) Tick(g *game) {
|
|||||||
r.Health -= p.Damage
|
r.Health -= p.Damage
|
||||||
r.Hit = true
|
r.Hit = true
|
||||||
}
|
}
|
||||||
|
p.Owner.gameStats.Hits++
|
||||||
|
if r.Health <= 0 {
|
||||||
|
r.gameStats.Deaths++
|
||||||
|
p.Owner.gameStats.Kills++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
9
robot.go
9
robot.go
@ -281,6 +281,10 @@ func (r *Robot) Tick(g *game) {
|
|||||||
hit_robot.Health -= dmg
|
hit_robot.Health -= dmg
|
||||||
hit_robot.Speed = (hit_robot.Speed * 0.5)
|
hit_robot.Speed = (hit_robot.Speed * 0.5)
|
||||||
// hit_robot.Heading = r.Heading
|
// hit_robot.Heading = r.Heading
|
||||||
|
if hit_robot.Health <= 0 {
|
||||||
|
hit_robot.gameStats.Deaths++
|
||||||
|
r.gameStats.Kills++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Position != intersection_point {
|
if r.Position != intersection_point {
|
||||||
@ -291,6 +295,11 @@ func (r *Robot) Tick(g *game) {
|
|||||||
r.MoveTo = &r.Position
|
r.MoveTo = &r.Position
|
||||||
r.Speed = (r.Speed * -0.5)
|
r.Speed = (r.Speed * -0.5)
|
||||||
// r.Heading = r.Heading.Scale(-1.0)
|
// r.Heading = r.Heading.Scale(-1.0)
|
||||||
|
|
||||||
|
if r.Health <= 0 {
|
||||||
|
r.gameStats.Deaths++
|
||||||
|
r.gameStats.Suicides++
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
r.Position = r.Position.Add(move_vector)
|
r.Position = r.Position.Add(move_vector)
|
||||||
if new_heading.Mag() > 0 {
|
if new_heading.Mag() > 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user