Workshop › Lunar Lander › Step 23 of 31

Levels

What we are doing

The game gets levels. One flight is startLevel(): new hills, a new lander, and gravity that grows with the level. reset() now starts a whole new game: level 1, no score.

```js
let level
let score

function startLevel() {
  makeGround()
  lander = { x: 60, y: 40, vx: 1, vy: 0, angle: 0, fuel: 400 }
  gravity = 0.02 + level * 0.005
  state = 'flying'
}

function reset() {
  level = 1
  score = 0
  startLevel()
}
```

What it means

Your turn

  1. Above let state write let level and let score.
  2. Rename reset to startLevel and change its gravity line.
  3. Under it, leave an empty line and write the new reset.

Skills: Game states, Functions

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