changes to how acceleration works

This commit is contained in:
Fraser Graham 2014-04-27 00:48:01 -06:00 committed by Stephen McQuay
parent af418f1e6f
commit b05e17709c

View File

@ -15,7 +15,7 @@ type Robot struct {
Name string `json:"name"` Name string `json:"name"`
Message string `json:"-"` Message string `json:"-"`
Stats Stats `json:"-"` Stats Stats `json:"-"`
TargetSpeed float64 `json:"-"` TargetSpeed float64 `json:"target_speed"`
Speed float64 `json:"speed"` Speed float64 `json:"speed"`
Health int `json:"health"` Health int `json:"health"`
RepairCounter float64 `json:"repair"` RepairCounter float64 `json:"repair"`
@ -136,11 +136,11 @@ func DeriveStats(request StatsRequest) Stats {
s.Hp = int((float64(request.Hp) / 100.0 * (hp_max - hp_min)) + hp_min) s.Hp = int((float64(request.Hp) / 100.0 * (hp_max - hp_min)) + hp_min)
speed_min := 40.0 speed_min := 40.0
speed_max := 200.0 speed_max := 250.0
s.Speed = float64(request.Speed)/100.0*(speed_max-speed_min) + speed_min s.Speed = float64(request.Speed)/100.0*(speed_max-speed_min) + speed_min
accel_min := 20.0 accel_min := 20.0
accel_max := 200.0 accel_max := 100.0
s.Acceleration = ((float64(request.Acceleration) / 100.0) * (accel_max - accel_min)) + accel_min s.Acceleration = ((float64(request.Acceleration) / 100.0) * (accel_max - accel_min)) + accel_min
wep_rad_min := 5.0 wep_rad_min := 5.0
@ -276,13 +276,13 @@ func (r *Robot) Tick(g *Game) {
r.TargetSpeed = r.Stats.Speed r.TargetSpeed = r.Stats.Speed
} }
if r.TargetSpeed < -1.0*r.Stats.Speed { if r.TargetSpeed < -0.25 * r.Stats.Speed {
r.TargetSpeed = -1.0 * r.Stats.Speed r.TargetSpeed = -0.25 * r.Stats.Speed
} }
// Are we speeding up or slowing down? // Are we speeding up or slowing down?
increase := true increase := true
if float32(math.Abs(float64(r.Speed-r.TargetSpeed))) > v.Epsilon { if r.Speed - r.TargetSpeed > v.Epsilon {
increase = false increase = false
} }
@ -293,17 +293,12 @@ func (r *Robot) Tick(g *Game) {
r.Speed = r.TargetSpeed r.Speed = r.TargetSpeed
} }
} else { } else {
r.Speed -= (r.Stats.Acceleration * r.Delta) r.Speed -= (r.Stats.Acceleration * 8 * r.Delta)
// Dont go too far // Dont go too far
if r.Speed < r.TargetSpeed { if r.Speed < r.TargetSpeed {
r.Speed = r.TargetSpeed r.Speed = r.TargetSpeed
} }
// Cap reverse at 1/4 top speed
if r.Speed < (-0.25 * r.Stats.Speed) {
r.Speed = (-0.25 * r.Stats.Speed)
}
} }
// Adjust Heading // Adjust Heading