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.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
|
||||||
|
1
robot.go
1
robot.go
@ -156,5 +156,6 @@ 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"`
|
||||||
|
TargetSpeed *float32 `json:"target_speed,omitempty"`
|
||||||
Stats Stats `json:"stats"`
|
Stats Stats `json:"stats"`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user