players can now set target speed in bot code

This commit is contained in:
Fraser Graham 2013-11-06 21:24:10 -08:00
parent cd9bb45ddc
commit e562e2fefb
2 changed files with 12 additions and 10 deletions

View File

@ -46,12 +46,9 @@ func (p *player) recv() {
p.Robot.FireAt = msg.FireAt
}
p.Robot.TargetSpeed = p.Robot.Stats.Speed
if msg.Stats.Speed > 0 {
p.Robot.Stats = msg.Stats
p.Robot.Health = p.Robot.Stats.Hp
p.Robot.Speed = 0
if msg.TargetSpeed != nil {
p.Robot.TargetSpeed = float32(*msg.TargetSpeed)
} else {
p.Robot.TargetSpeed = p.Robot.Stats.Speed
}
}
@ -102,7 +99,11 @@ func (p *player) Tick(g *game) {
// Adjust Speed
if p.Robot.Speed < p.Robot.TargetSpeed {
p.Robot.Speed += (p.Robot.Stats.Acceleration * delta)
} else if (p.Robot.Speed - p.Robot.TargetSpeed) > v.Epsilon {
if p.Robot.Speed > p.Robot.TargetSpeed {
p.Robot.Speed = p.Robot.TargetSpeed
}
} else if float32(math.Abs(float64(p.Robot.Speed-p.Robot.TargetSpeed))) > v.Epsilon {
p.Robot.Speed -= (p.Robot.Stats.Acceleration * delta)
} else {
p.Robot.Speed = p.Robot.TargetSpeed

View File

@ -154,7 +154,8 @@ func (s StatsRequest) Valid() bool {
}
type Instruction struct {
MoveTo *v.Point2d `json:"move_to,omitempty"`
FireAt *v.Point2d `json:"fire_at,omitempty"`
Stats Stats `json:"stats"`
MoveTo *v.Point2d `json:"move_to,omitempty"`
FireAt *v.Point2d `json:"fire_at,omitempty"`
TargetSpeed *float32 `json:"target_speed,omitempty"`
Stats Stats `json:"stats"`
}