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

Interceptors fly

What we are doing

Interceptors fly like enemy missiles, only much faster (7 pixels per frame), and are drawn as green lines from the base.

```js
const SHOT_SPEED = 7

  for (const s of shots) {
    if (stepTowards(s, SHOT_SPEED)) {
      s.done = true
    }
  }
  shots = shots.filter((s) => !s.done)

  ctx.strokeStyle = '#a3e635'
  for (const s of shots) {
    ctx.beginPath()
    ctx.moveTo(BASE.x, BASE.y)
    ctx.lineTo(s.x, s.y)
    ctx.stroke()
  }
```

What it means

Your turn

  1. Under const CITY_XS = ... write const SHOT_SPEED = 7.
  2. In update, between the countdown block and the missile loop, write the shots loop and its filter (empty line above).
  3. In draw, under the missile trail loop, write the green lines.

Skills: Velocity and gravity, Drawing on a canvas

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