Workshop › Bomberman-style Arena › Step 8 of 42

Keep the corners clear

What we are doing

If the player started boxed in by crates, their first bomb would have no escape. So the tiles next to the start corners (the player's at row 1, column 1 and three for the enemies) are always floor.

```js
const ENEMY_STARTS = [[ROWS - 2, COLS - 2], [1, COLS - 2], [ROWS - 2, 1]]

const near = (r, c, spots) => spots.some(([sr, sc]) => Math.abs(sr - r) + Math.abs(sc - c) <= 1)

// Walls all round, a pillar on every even row and column, and crates on about half of the rest,
// but never next to where the player and the enemies start.
function makeGrid() {

      else if (near(r, c, [[1, 1], ...ENEMY_STARTS]) || Math.random() > 0.55) grid[r].push(' ')
```

What it means

Your turn

  1. Under TOP write ENEMY_STARTS.
  2. Under let grid, after an empty line, write near.
  3. Above function makeGrid() { write the two comment lines.
  4. In makeGrid, put near(r, c, [[1, 1], ...ENEMY_STARTS]) || before Math.random() > 0.55.

Skills: Arrays and objects, Functions

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