Workshop › Space Invaders-style › Step 19 of 21

Waves

What we are doing

When every invader is down, the wave number goes up and a new formation arrives. The wave is shown in the middle of the top bar.

```js
if (alive().length === 0) {
  wave += 1
  spawnWave()
  return
}

ctx.textAlign = 'center'
ctx.fillText('WAVE ' + wave, canvas.width / 2, 24)
```

What it means

Your turn

  1. In update, under the second stop line, start a new wave when none are left.
  2. In draw, write the wave between the score and the lives.

Skills: Game states

All steps

  1. The ship
  2. The game loop
  3. Move the ship
  4. Stay on screen
  5. Fire
  6. Bullets fly
  7. A short reload
  8. The invaders
  9. The march
  10. Hit!
  11. Score
  12. They shoot back
  13. Bombs fall
  14. Lives
  15. Game over
  16. Best score
  17. A wave in a function
  18. Play again
  19. Waves
  20. Faster and faster
  21. Build it yourself: an extra life