players can now set target speed in bot code
This commit is contained in:
parent
cd9bb45ddc
commit
e562e2fefb
15
player.go
15
player.go
@ -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
|
||||
|
7
robot.go
7
robot.go
@ -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"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user