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.FireAt = msg.FireAt
} }
p.Robot.TargetSpeed = p.Robot.Stats.Speed if msg.TargetSpeed != nil {
p.Robot.TargetSpeed = float32(*msg.TargetSpeed)
if msg.Stats.Speed > 0 { } else {
p.Robot.Stats = msg.Stats
p.Robot.Health = p.Robot.Stats.Hp
p.Robot.Speed = 0
p.Robot.TargetSpeed = p.Robot.Stats.Speed p.Robot.TargetSpeed = p.Robot.Stats.Speed
} }
} }
@ -102,7 +99,11 @@ func (p *player) Tick(g *game) {
// Adjust Speed // Adjust Speed
if p.Robot.Speed < p.Robot.TargetSpeed { if p.Robot.Speed < p.Robot.TargetSpeed {
p.Robot.Speed += (p.Robot.Stats.Acceleration * delta) 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) p.Robot.Speed -= (p.Robot.Stats.Acceleration * delta)
} else { } else {
p.Robot.Speed = p.Robot.TargetSpeed p.Robot.Speed = p.Robot.TargetSpeed

View File

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