Workshop › Doodle Jump-style Climber › Step 16 of 24

Play again

What we are doing

After a fall, Space starts a new climb. All the starting values move into reset, which runs at the start and after every game over.

```js
let player
let platforms
let cameraY // the world y shown at the top of the screen: the camera
let highest // world y of the highest platform so far
let state // 'playing' or 'over'

function reset() {
  player = { x: 180, y: START_Y - 40, w: 40, h: 40, vy: 0 }
  platforms = [{ x: 170, y: START_Y, w: 60, h: 12 }]
  cameraY = 0
  highest = START_Y
  state = 'playing'
  fillPlatforms()
}

  if (event.key === ' ' && state === 'over') reset()

reset()
```

What it means

Your turn

  1. Replace the five variable lines with plain declarations, and write reset under const keys = {}.
  2. In keydown, add the Space line.
  3. Replace fillPlatforms() at the bottom with reset().

Skills: Game states, Functions

All steps

  1. The jumper
  2. Draw again and again
  3. Gravity
  4. Bounce
  5. Steer left and right
  6. Through the sides
  7. Half here, half there
  8. Touch steering
  9. Platforms
  10. Land on platforms
  11. A camera that follows
  12. Lines on the wall
  13. How hard should it be?
  14. Endless platforms
  15. Miss and fall
  16. Play again
  17. Tap to play again
  18. Score is height
  19. Best score
  20. Kinds of platform
  21. Moving platforms
  22. Traps
  23. It breaks!
  24. Build it yourself: springs