Workshop › Tower Defense › Step 41 of 42
The cannon's shot now hurts every enemy within its splash distance of the target. Arrows have a splash of 0, so they still hit only their target.
```js
const center = pointAt(bullet.target.d)
for (const e of enemies) {
const p = pointAt(e.d)
const close = e === bullet.target || Math.hypot(p.x - center.x, p.y - center.y) <= kind.splash
if (close) e.hp -= kind.damage
}
```center is where the target is on the map.Math.hypot(dx, dy) is the straight-line distance between two points (Pythagoras).In hit, replace the bullet.target.hp -= kind.damage line with the new lines.
Skills: Collision detection
← Tower buttons Build it yourself: sell a tower →