Workshop › Missile Command-style Defense › Step 11 of 35
A missile that arrives destroys the living city under it and is removed from the list.
```js
for (const m of incoming) {
if (stepTowards(m, m.speed)) {
m.done = true
const city = cities.find((c) => c.alive && Math.abs(c.x - m.x) < 20)
if (city) city.alive = false
}
}
incoming = incoming.filter((m) => !m.done)
```stepTowards returns true on arrival; then the missile is marked done.find returns the first living city within 20 pixels of the missile, or undefined.filter keeps only the missiles that are not done.In update, replace the missile loop with the new one and write the filter line under it.
Skills: Collision detection, Game states
← Smoke trails Fire an interceptor →