make member a pointer for nil json

This commit is contained in:
Stephen McQuay 2013-09-04 00:05:38 -07:00
parent 0cc03e5768
commit 9bccf60abc
2 changed files with 6 additions and 6 deletions

View File

@ -84,8 +84,8 @@ func (g *game) run() {
p.scan() p.scan()
p.nudge() p.nudge()
// XXX: change to pointer, check for pointer as (0, 0) is valid target // XXX: change to pointer, check for pointer as (0, 0) is valid target
if p.Robot.FireAt.X != 0 && p.Robot.FireAt.Y != 0 { if p.Robot.FireAt != nil {
proj := p.fire() proj := p.fire(g.projectiles)
if proj != nil { if proj != nil {
g.projectiles[proj] = true g.projectiles[proj] = true
} }

View File

@ -41,10 +41,10 @@ func (p *player) recv() {
break break
} }
if msg.MoveTo != nil { if msg.MoveTo != nil {
p.Robot.MoveTo = *msg.MoveTo p.Robot.MoveTo = msg.MoveTo
} }
if msg.FireAt != nil { if msg.FireAt != nil {
p.Robot.FireAt = *msg.FireAt p.Robot.FireAt = msg.FireAt
} }
if msg.Stats.Speed > 0 { if msg.Stats.Speed > 0 {
p.Robot.Stats = msg.Stats p.Robot.Stats = msg.Stats
@ -90,7 +90,7 @@ func (p *player) fire() *bot.Projectile {
return &bot.Projectile{ return &bot.Projectile{
Id: p.Robot.Id, Id: p.Robot.Id,
Position: p.Robot.Position, Position: p.Robot.Position,
MoveTo: p.Robot.FireAt, MoveTo: *p.Robot.FireAt,
Damage: 10, Damage: 10,
Radius: p.Robot.Stats.WeaponRadius, Radius: p.Robot.Stats.WeaponRadius,
Speed: float64(p.Robot.Stats.Speed * 2), Speed: float64(p.Robot.Stats.Speed * 2),
@ -102,7 +102,7 @@ func (p *player) reset() {
X: rand.Float64() * *width, X: rand.Float64() * *width,
Y: rand.Float64() * *height, Y: rand.Float64() * *height,
} }
p.Robot.MoveTo = start_pos p.Robot.MoveTo = &start_pos
p.Robot.Position = start_pos p.Robot.Position = start_pos
p.Robot.Health = p.Robot.Stats.Hp p.Robot.Health = p.Robot.Stats.Hp
} }