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

Missile Command-style Defense: Six cities to protect

Click the sky to fire interceptors and protect six cities from falling missiles. Moving towards a target at a set speed, explosions that grow and shrink, chain reactions, limited ammo, waves and missiles that split.

What we are doing

Every game needs something to lose. Here it is six cities standing on the ground under a night sky.

```js
const canvas = document.getElementById('game')
const ctx = canvas.getContext('2d')

const GROUND = 370
const CITY_XS = [50, 110, 170, 310, 370, 430]

ctx.fillStyle = '#020617'
ctx.fillRect(0, 0, canvas.width, canvas.height)
ctx.fillStyle = '#854d0e'
ctx.fillRect(0, GROUND, canvas.width, canvas.height - GROUND)

ctx.fillStyle = '#38bdf8'
for (const x of CITY_XS) {
  ctx.fillRect(x - 16, GROUND - 14, 32, 14)
}
```

What it means

Your turn

Write the code under the three comment lines, then press Run.

Skills: Drawing on a canvas, Arrays and objects

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