Workshop › Endless Runner › Step 10 of 19

Wait for the start

What we are doing

The world should not start rushing before the player is ready. The game has a state; it starts as 'ready' and the first jump switches it to 'running'.

```js
let state = 'ready' // 'ready', 'running' or 'over'

  state = 'running'

  if (state !== 'running') return

  ctx.textAlign = 'center'
  if (state === 'ready') {
    ctx.font = '16px sans-serif'
    ctx.fillText('Press Space to start', canvas.width / 2, canvas.height / 2)
  }
```

What it means

Your turn

  1. Under runner, write state.
  2. Make state = 'running' the first line of jump.
  3. Make the state check the first line of update, with an empty line after it.
  4. At the end of draw, write the ready message.

Skills: Game states

All steps

  1. The ground
  2. The runner
  3. Draw again and again
  4. Gravity
  5. Jump
  6. Short hops
  7. Tap to jump
  8. Things that come at you
  9. Cacti keep coming
  10. Wait for the start
  11. Crash
  12. Try again
  13. Faster and faster
  14. Remember the best run
  15. The score counter
  16. Birds
  17. Which keys are down?
  18. Duck
  19. Build it yourself: jump buffering