Workshop › Lunar Lander › Step 8 of 31

The game loop

What we are doing

A game loop moves the lander by its velocity and redraws the picture, about 60 times a second.

```js
function update() {
  lander.x += lander.vx
  lander.y += lander.vy
}

function loop() {
  update()
  draw()
  requestAnimationFrame(loop)
}

reset()
requestAnimationFrame(loop)
```

What it means

Your turn

  1. Write update just above function drawLander() {, with an empty line between.
  2. At the bottom, replace draw() with the loop function and requestAnimationFrame(loop) as shown.

Skills: The game loop

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