stop racers when battery dead
This commit is contained in:
parent
a62363bcbc
commit
b9dd5326f6
10
game/game.go
10
game/game.go
|
@ -12,9 +12,11 @@ func UpdateState(s State, sOld State) State {
|
|||
}
|
||||
|
||||
for _, t := range s.Teams {
|
||||
if r := ActiveRacer(t); r != nil && won(*r, s) {
|
||||
log.Printf("team %d won", t.id)
|
||||
s.GameOver = true
|
||||
if r := ActiveRacer(t); r != nil {
|
||||
if won(*r, s) {
|
||||
log.Printf("team %d won", t.id)
|
||||
s.GameOver = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,5 +211,5 @@ const (
|
|||
numRacers = 3
|
||||
NumTeams = 8
|
||||
NumLanes = NumTeams
|
||||
baseCharge = 4
|
||||
baseCharge = 10
|
||||
)
|
||||
|
|
|
@ -25,6 +25,12 @@ func accelerate(r Racer) Racer {
|
|||
}
|
||||
|
||||
func moveRacer(s State, r Racer) State {
|
||||
r.Battery.Charge--
|
||||
s = updateRacer(s, r)
|
||||
if r.Battery.Charge <= 0 {
|
||||
return destroyRacer(s, r)
|
||||
}
|
||||
|
||||
for i := 0; i < r.Kinetics.V; i++ {
|
||||
if o := collide(r.Position.Pos+1, r.Position.Lane, s); o != nil {
|
||||
return destroyRacer(s, r)
|
||||
|
|
Loading…
Reference in New Issue