Workshop › Scorched Earth-style Artillery › Step 12 of 23

Falling tanks

What we are doing

A tank whose ground was blown away should not float. Each frame, a tank above the ground falls 2 pixels, until it lands on the ground again.

```js
const FALL = 2 // pixels per frame a tank drops when the ground under it is gone

  for (const t of tanks) {
    if (t.y < groundAt(t.x)) t.y = Math.min(groundAt(t.x), t.y + FALL) // nothing under it: it falls
    else t.y = groundAt(t.x)
  }
```

What it means

Your turn

  1. Under MAX_POWER, write FALL.
  2. At the top of update, let the tanks fall.

Skills: Velocity and gravity

All steps

  1. The ground
  2. Hills
  3. Two tanks
  4. The barrel
  5. The game loop
  6. Aim
  7. Angle and power
  8. Fire!
  9. Flight
  10. Boom
  11. Craters
  12. Falling tanks
  13. Damage
  14. Taking turns
  15. The computer's shot
  16. Hitting a tank
  17. Win or lose
  18. Wind
  19. The computer aims
  20. Aim with the mouse
  21. Drag and let go
  22. The atan2 trap
  23. Build it yourself: a trail