Workshop › Missile Command-style Defense › Step 27 of 35

The end of a wave

What we are doing

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
  }
```

What it means

Your turn

  1. Under let score write let state (with its comment) and let pause.
  2. At the end of nextWave, write state = 'playing'.
  3. At the very top of update, write the between block, followed by an empty line.
  4. At the end of update, under incoming = incoming.filter(...), leave an empty line and write the wave-end block.

Skills: Game states

All steps

  1. Six cities to protect
  2. Your missile base
  3. Draw again and again
  4. Cities that can fall
  5. Rubble
  6. Move towards a point
  7. Launch an enemy missile
  8. One missile a second
  9. Missiles on their way
  10. Smoke trails
  11. Impact
  12. Fire an interceptor
  13. Click the sky
  14. Interceptors fly
  15. An explosion that grows and shrinks
  16. Explode on arrival
  17. Draw the explosions
  18. Impacts explode too
  19. Caught in the blast
  20. Chain reactions
  21. Only your explosions count
  22. Points for every missile
  23. Show the score
  24. Limited ammo
  25. Waves
  26. Each wave is harder
  27. The end of a wave
  28. The end
  29. Play again
  30. Wave, ammo and messages
  31. Launch from anywhere
  32. Some missiles will split
  33. Split into three
  34. A high score
  35. Build it yourself: a crosshair