Workshop › Bomberman-style Arena › Step 10 of 42

Keys being held

What we are doing

Which way does the player want to go? We keep the arrow keys being held in a list: a key goes on the end when it is pressed and leaves when it is let go. The last one is in charge, as players expect.

```js
const DIRS = { ArrowUp: [-1, 0], ArrowDown: [1, 0], ArrowLeft: [0, -1], ArrowRight: [0, 1] }

let held // arrow keys being held, the last one pressed at the end

  held = []

document.addEventListener('keydown', (event) => {
  if (DIRS[event.key]) {
    event.preventDefault()
    if (!held.includes(event.key)) held.push(event.key)
  }
})

document.addEventListener('keyup', (event) => {
  held = held.filter((k) => k !== event.key)
})
```

What it means

Your turn

  1. Above ENEMY_STARTS write DIRS.
  2. Under let player write let held; in reset, under the player line, write held = [].
  3. Above function drawCircle( write the two listeners.

Skills: Keyboard and mouse input

All steps

  1. Measure the arena
  2. A floor of tiles
  3. Draw it every frame
  4. The arena as data
  5. Draw what the grid says
  6. Pillars
  7. Crates
  8. Keep the corners clear
  9. The player
  10. Keys being held
  11. Slide towards a target
  12. Walk
  13. Drop a bomb
  14. Space drops, bombs show
  15. One bomb at a time
  16. Bombs are in the way
  17. The fuse burns down
  18. Fire!
  19. Flames die down
  20. A cross of flames
  21. Crates burn
  22. Chain reactions
  23. Bombs blink
  24. Flames hurt
  25. A moment of safety
  26. Hearts
  27. Out of lives
  28. Game over
  29. Enemies
  30. Enemies wander
  31. No turning back
  32. Fight and touch
  33. All enemies gone
  34. Hidden power-ups
  35. Uncover the power-ups
  36. Pick them up
  37. Show the powers
  38. Which way is the finger?
  39. Play with a finger
  40. A clock
  41. The fastest win
  42. Build it yourself: a smarter enemy