sprout Kinetics struct
This commit is contained in:
parent
794c54764e
commit
47bf19265d
|
@ -20,7 +20,7 @@ func chooseCommand(s State, teamID int) command {
|
||||||
|
|
||||||
if nextRacer != nil {
|
if nextRacer != nil {
|
||||||
if h.Position.Lane != nextRacer.Position.Lane {
|
if h.Position.Lane != nextRacer.Position.Lane {
|
||||||
if abs(nextRacer.Position.Pos-h.Position.Pos) < h.v {
|
if abs(nextRacer.Position.Pos-h.Position.Pos) < h.Kinetics.V {
|
||||||
return slowDown
|
return slowDown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,11 @@ func doCommand(cmd command, s State, teamID int) State {
|
||||||
|
|
||||||
switch cmd {
|
switch cmd {
|
||||||
case speedUp:
|
case speedUp:
|
||||||
r.a += da
|
r.Kinetics.A += da
|
||||||
*r = accelerate(*r)
|
*r = accelerate(*r)
|
||||||
s = updateRacer(s, *r)
|
s = updateRacer(s, *r)
|
||||||
case slowDown:
|
case slowDown:
|
||||||
r.a -= da
|
r.Kinetics.A -= da
|
||||||
*r = accelerate(*r)
|
*r = accelerate(*r)
|
||||||
s = updateRacer(s, *r)
|
s = updateRacer(s, *r)
|
||||||
case left:
|
case left:
|
||||||
|
@ -40,7 +40,7 @@ func doCommand(cmd command, s State, teamID int) State {
|
||||||
pos := r.Position
|
pos := r.Position
|
||||||
pos.Pos++
|
pos.Pos++
|
||||||
s = removeObstacle(s, pos)
|
s = removeObstacle(s, pos)
|
||||||
r.v = 0
|
r.Kinetics.V = 0
|
||||||
s = updateRacer(s, *r)
|
s = updateRacer(s, *r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
game/game.go
14
game/game.go
|
@ -33,11 +33,11 @@ func maybePassBaton(s State, teamID int) State {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if abs(r.Position.Pos-h.Position.Pos) <= PassDistance {
|
if abs(r.Position.Pos-h.Position.Pos) <= PassDistance {
|
||||||
h.v = 0
|
h.Kinetics.V = 0
|
||||||
h.a = 0
|
h.Kinetics.A = 0
|
||||||
s = updateRacer(s, *h)
|
s = updateRacer(s, *h)
|
||||||
newH := t.Racers[i]
|
newH := t.Racers[i]
|
||||||
newH.a = baseAccel
|
newH.Kinetics.A = baseAccel
|
||||||
t.Baton.HolderID = newH.ID
|
t.Baton.HolderID = newH.ID
|
||||||
s = updateTeam(s, t)
|
s = updateTeam(s, t)
|
||||||
return updateRacer(s, newH)
|
return updateRacer(s, newH)
|
||||||
|
@ -146,8 +146,12 @@ type Racer struct {
|
||||||
TeamID int
|
TeamID int
|
||||||
Position Position
|
Position Position
|
||||||
StartPos Position
|
StartPos Position
|
||||||
v int
|
Kinetics Kinetics
|
||||||
a int
|
}
|
||||||
|
|
||||||
|
type Kinetics struct {
|
||||||
|
V int
|
||||||
|
A int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Position struct {
|
type Position struct {
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
package game
|
package game
|
||||||
|
|
||||||
func accelerate(r Racer) Racer {
|
func accelerate(r Racer) Racer {
|
||||||
if r.a < -MaxA {
|
if r.Kinetics.A < -MaxA {
|
||||||
r.a = -MaxA
|
r.Kinetics.A = -MaxA
|
||||||
}
|
}
|
||||||
if r.a > MaxA {
|
if r.Kinetics.A > MaxA {
|
||||||
r.a = MaxA
|
r.Kinetics.A = MaxA
|
||||||
}
|
}
|
||||||
|
|
||||||
r.v += r.a
|
r.Kinetics.V += r.Kinetics.A
|
||||||
if r.v > MaxV {
|
if r.Kinetics.V > MaxV {
|
||||||
r.v = MaxV
|
r.Kinetics.V = MaxV
|
||||||
}
|
}
|
||||||
if r.v < -MaxV {
|
if r.Kinetics.V < -MaxV {
|
||||||
r.v = -MaxV
|
r.Kinetics.V = -MaxV
|
||||||
}
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func moveRacer(s State, r Racer) State {
|
func moveRacer(s State, r Racer) State {
|
||||||
for i := 0; i < r.v; i++ {
|
for i := 0; i < r.Kinetics.V; i++ {
|
||||||
if o := collide(r.Position.Pos+1, r.Position.Lane, s); o != nil {
|
if o := collide(r.Position.Pos+1, r.Position.Lane, s); o != nil {
|
||||||
return destroyRacer(s, r)
|
return destroyRacer(s, r)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue