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

Steer left and right

What we are doing

While bouncing, the arrow keys move the player sideways. A keys object remembers which keys are held down, and every frame the player moves 5 pixels toward the held arrow.

```js
const SPEED = 5 // sideways pixels per frame

const keys = {}

document.addEventListener('keydown', (event) => {
  keys[event.key] = true
  if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') event.preventDefault()
})
document.addEventListener('keyup', (event) => {
  keys[event.key] = false
})

  const direction = (keys.ArrowRight ? 1 : 0) - (keys.ArrowLeft ? 1 : 0)
  player.x += direction * SPEED
```

What it means

Your turn

  1. Under JUMP, write SPEED.
  2. Under player, write keys and the two key listeners.
  3. At the top of update, write the two steering lines.

Skills: Keyboard and mouse input

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