Workshop › Space Invaders-style › Step 17 of 21
When all invaders are gone, a new wave should come. So building the formation moves into a function, spawnWave,
which also clears the bullets and bombs and starts the march fresh. The game calls it once at the start.
```js
let bullets
let invaders
let bombs
let dir // +1 marching right, -1 marching left
let lastStep
let lastShot = -COOLDOWN
function spawnWave() {
invaders = []
for (let row = 0; row < ROWS; row++) {
for (let col = 0; col < COLS; col++) {
invaders.push({ x: 40 + col * SPACING_X, y: 60 + row * SPACING_Y, w: INVADER_W, h: INVADER_H, row, alive: true })
}
}
bullets = []
bombs = []
dir = 1
lastStep = now
}
spawnWave()
```spawnWave gives them their values.lastStep = now makes the first march step come half a second after the wave appears.bullets to lastStep with the short list.overlaps, write spawnWave.spawnWave() above requestAnimationFrame(loop).Skills: Functions