Workshop › Bomberman-style Arena › Step 14 of 42
Space drops, bombs show
What we are doing
Space calls dropBomb, and every bomb is drawn as a black circle, under the player.
```js
} else if (event.key === ' ') {
event.preventDefault()
dropBomb()
}
for (const b of bombs) drawCircle({ x: b.c, y: b.r }, '#020617', 12)
```
What it means
else if adds a second case to the keydown listener: ' ' is the Space key.
drawCircle expects something with x and y; a bomb has r and c, so we hand it { x: b.c, y: b.r }.
Your turn
- In the
keydown listener, after the arrow block's }, add the else if for Space.
- In
draw, above the player's drawCircle, write the bombs line.
Skills: Keyboard and mouse input, Drawing on a canvas
← Drop a bomb One bomb at a time →
All steps
- Measure the arena
- A floor of tiles
- Draw it every frame
- The arena as data
- Draw what the grid says
- Pillars
- Crates
- Keep the corners clear
- The player
- Keys being held
- Slide towards a target
- Walk
- Drop a bomb
- Space drops, bombs show
- One bomb at a time
- Bombs are in the way
- The fuse burns down
- Fire!
- Flames die down
- A cross of flames
- Crates burn
- Chain reactions
- Bombs blink
- Flames hurt
- A moment of safety
- Hearts
- Out of lives
- Game over
- Enemies
- Enemies wander
- No turning back
- Fight and touch
- All enemies gone
- Hidden power-ups
- Uncover the power-ups
- Pick them up
- Show the powers
- Which way is the finger?
- Play with a finger
- A clock
- The fastest win
- Build it yourself: a smarter enemy