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

An explosion that grows and shrinks

What we are doing

Interceptors will explode where they arrive. An explosion is a position and an age; its radius is worked out from the age: it grows for the first half of its life and shrinks in the second.

```js
const BLAST = 32 // the biggest radius of an explosion
const BLAST_FRAMES = 50 // how long an explosion lasts, growing then shrinking

// How big an explosion is at its age: it grows for the first half and shrinks in the second.
function radius(b) {
  const t = b.age / BLAST_FRAMES
  return BLAST * (t < 0.5 ? t * 2 : (1 - t) * 2)
}
```

What it means

Your turn

  1. Under const SHOT_SPEED = 7 write the two constants.
  2. Above function update() {, write radius with its comment, followed by an empty line.

Skills: Velocity and gravity

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