Workshop › Missile Command-style Defense › Step 8 of 35
The attack comes in a wave of 20 missiles. A countdown in update launches one, waits 60 frames (about a second),
launches the next.
```js
let toLaunch // enemy missiles still to come in this wave
let launchIn
toLaunch = 20
launchIn = 30
function update() {
if (toLaunch > 0) {
launchIn -= 1
if (launchIn <= 0) {
launch()
toLaunch -= 1
launchIn = 60
}
}
}
function loop() {
update()
```reset sets 20 missiles to launch, the first one after 30 frames.update counts launchIn down; at 0 it launches a missile, counts it off and waits 60 frames again.update() before draw().let incoming ... write let toLaunch (with its comment) and let launchIn.reset, under incoming = [], write the two lines.update just above function draw() {, with an empty line between.loop, call update() above draw().Skills: The game loop
← Launch an enemy missile Missiles on their way →