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.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
}

View File

@ -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
}