Workshop › Angry Birds-style Slingshot › Step 31 of 47
How hard was a hit? collide already knows: closing. Only the speed above 2 hurts, 25 hp per unit, so a block
settling on another is never hurt. Landing on the ground hurts with the falling speed.
```js
damage(a, closing)
damage(b, closing)
}
// Hits harder than a gentle landing hurt; things fall apart at 0 hp.
function damage(b, speed) {
if (speed > 2) b.hp -= (speed - 2) * 25
}
if (b.y + b.h > GROUND) {
if (b.vy > 0) damage(b, b.vy)
```collide, both bodies are damaged by the closing speed.damage takes away (speed - 2) * 25 hp, only when speed is over 2.vy > 0) damages a body by its falling speed.collide, under the last friction line, write the two damage calls.collide and step, write the damage function.step, write the ground-damage line as the first line inside if (b.y + b.h > GROUND) {.Skills: Collision detection