Workshop › Missile Command-style Defense › Step 15 of 35
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)
}
```t goes from 0 to 1 over the explosion's life.t * 2 goes 0 → 1; in the second (1 - t) * 2 goes 1 → 0. Times BLAST that is 0 → 32 → 0.const SHOT_SPEED = 7 write the two constants.function update() {, write radius with its comment, followed by an empty line.Skills: Velocity and gravity
← Interceptors fly Explode on arrival →