Workshop › Missile Command-style Defense › Step 27 of 35
A wave is over when nothing is left to launch, nothing is in the air and no explosion is still going. You get a bonus, a short pause, then the next wave.
```js
let state // 'playing', 'between' (a pause after a wave) or 'over'
let pause
state = 'playing'
if (state === 'between') {
pause -= 1
if (pause <= 0) nextWave()
return
}
if (toLaunch === 0 && incoming.length === 0 && blasts.length === 0) {
// Bonus for every city still standing and every interceptor left.
score += cities.filter((c) => c.alive).length * 100 + ammo * 5
state = 'between'
pause = 90
}
```nextWave sets the state to 'playing'.update only counts pause down; at 0 the next wave starts. return skips everything else.update: when the wave is finished, add the bonus, switch to 'between' and pause 90 frames.let score write let state (with its comment) and let pause.nextWave, write state = 'playing'.update, write the between block, followed by an empty line.update, under incoming = incoming.filter(...), leave an empty line and write the wave-end block.Skills: Game states
← Each wave is harder The end →