From 5c77e373c3289085e2b60c1dbb6045648224b649 Mon Sep 17 00:00:00 2001 From: Fraser Graham Date: Fri, 25 Oct 2013 22:51:41 -0700 Subject: [PATCH] scanners for projectiles --- player.go | 28 +++++++++++++++++++++++++--- projectile.go | 1 + 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/player.go b/player.go index f66d074..88488f6 100644 --- a/player.go +++ b/player.go @@ -97,7 +97,7 @@ func (p *player) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point func (p *player) Tick(g *game) { p.Robot.Collision = false - p.scan(g.players) + p.scan(g) // Adjust Speed if p.Robot.Speed < p.Robot.TargetSpeed { @@ -169,9 +169,9 @@ func (p *player) Tick(g *game) { } } -func (p *player) scan(players map[*player]bool) { +func (p *player) scan(g *game) { p.Robot.Scanners = p.Robot.Scanners[:0] - for player, _ := range players { + for player, _ := range g.players { if player.Robot.Id == p.Robot.Id || player.Robot.Health <= 0 { continue } @@ -183,10 +183,31 @@ func (p *player) scan(players map[*player]bool) { X: player.Robot.Position.X, Y: player.Robot.Position.Y, }, + Type: "robot", } p.Robot.Scanners = append(p.Robot.Scanners, s) } } + + for proj, _ := range g.projectiles { + if proj.Owner.Robot.Id == p.Robot.Id { + continue + } + + dist := v.Distance(proj.Position, p.Robot.Position) + if dist < float32(p.Robot.Stats.ScannerRadius) { + s := Scanner{ + Id: proj.Id, + Position: v.Point2d{ + X: proj.Position.X, + Y: proj.Position.Y, + }, + Type: "projectile", + } + p.Robot.Scanners = append(p.Robot.Scanners, s) + } + } + } func (p *player) fire(projectiles map[*Projectile]bool, turn int) *Projectile { @@ -205,6 +226,7 @@ func (p *player) fire(projectiles map[*Projectile]bool, turn int) *Projectile { Damage: 10, Radius: p.Robot.Stats.WeaponRadius, Speed: float32(p.Robot.Stats.Speed * 3), + Owner: p, } } diff --git a/projectile.go b/projectile.go index 65f1df4..f5871fc 100644 --- a/projectile.go +++ b/projectile.go @@ -11,6 +11,7 @@ type Projectile struct { Radius int `json:"radius"` Speed float32 `json:"-"` Damage int `json:"-"` + Owner *player `json:"-"` } func (p *Projectile) Tick(g *game) {