Workshop › Lunar Lander › Step 29 of 31

Pieces fall and fade

What we are doing

Every frame each piece falls with the same gravity as the lander and loses one frame of life. Pieces with no life left are removed. This runs even after the crash, so it goes before the "not flying" check.

```js
for (const d of debris) {
  d.vy += gravity
  d.x += d.vx
  d.y += d.vy
  d.life -= 1
}
debris = debris.filter((d) => d.life > 0)
```

What it means

Your turn

In update, write the lines at the very top, above if (state !== 'flying') return.

Skills: Velocity and gravity

All steps

  1. Random hills
  2. Draw the hills
  3. A landing pad
  4. The height at any x
  5. The lander
  6. Draw it around its own middle
  7. Two feet
  8. The game loop
  9. Moon gravity
  10. Around the sides
  11. Flying or not
  12. Touching the ground
  13. Remember held keys
  14. Tilt
  15. The engine
  16. A flickering flame
  17. Fuel
  18. Touch controls
  19. Landing or crashing
  20. Fly again
  21. Landed or crashed?
  22. Readouts
  23. Levels
  24. Score
  25. Next level or new game
  26. A narrower pad
  27. A high score
  28. Burst into pieces
  29. Pieces fall and fade
  30. Draw the wreck
  31. Build it yourself: wind