From 9bccf60abc67c555f40724f3609b4bea48ea8ec2 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Wed, 4 Sep 2013 00:05:38 -0700 Subject: [PATCH] make member a pointer for nil json --- game.go | 4 ++-- player.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/game.go b/game.go index 2eb04ba..147b185 100644 --- a/game.go +++ b/game.go @@ -84,8 +84,8 @@ func (g *game) run() { p.scan() p.nudge() // XXX: change to pointer, check for pointer as (0, 0) is valid target - if p.Robot.FireAt.X != 0 && p.Robot.FireAt.Y != 0 { - proj := p.fire() + if p.Robot.FireAt != nil { + proj := p.fire(g.projectiles) if proj != nil { g.projectiles[proj] = true } diff --git a/player.go b/player.go index 4f898d8..ba91576 100644 --- a/player.go +++ b/player.go @@ -41,10 +41,10 @@ func (p *player) recv() { break } if msg.MoveTo != nil { - p.Robot.MoveTo = *msg.MoveTo + p.Robot.MoveTo = msg.MoveTo } if msg.FireAt != nil { - p.Robot.FireAt = *msg.FireAt + p.Robot.FireAt = msg.FireAt } if msg.Stats.Speed > 0 { p.Robot.Stats = msg.Stats @@ -90,7 +90,7 @@ func (p *player) fire() *bot.Projectile { return &bot.Projectile{ Id: p.Robot.Id, Position: p.Robot.Position, - MoveTo: p.Robot.FireAt, + MoveTo: *p.Robot.FireAt, Damage: 10, Radius: p.Robot.Stats.WeaponRadius, Speed: float64(p.Robot.Stats.Speed * 2), @@ -102,7 +102,7 @@ func (p *player) reset() { X: rand.Float64() * *width, Y: rand.Float64() * *height, } - p.Robot.MoveTo = start_pos + p.Robot.MoveTo = &start_pos p.Robot.Position = start_pos p.Robot.Health = p.Robot.Stats.Hp }