Workshop › Wolfenstein-style 3D Maze › Step 6 of 18

Is it a wall?

What we are doing

To stop at walls we need two questions. tileAt tells which tile a point is on. blocked tells whether the player, standing at a point, would be inside a wall. The player is not a point but a small square, 0.2 tiles each way from the middle, so we check its four corners.

```js
const RADIUS = 0.2 // how close the player can get to a wall

function tileAt(x, y) {
  return MAP[Math.floor(y)][Math.floor(x)]
}

// Is any corner of the player's little square inside a wall?
function blocked(x, y) {
  for (const [cx, cy] of [[-RADIUS, -RADIUS], [RADIUS, -RADIUS], [-RADIUS, RADIUS], [RADIUS, RADIUS]]) {
    if (tileAt(x + cx, y + cy) !== '.') return true
  }
  return false
}
```

What it means

Your turn

  1. Above MINI, write RADIUS.
  2. Above move, write tileAt and blocked.

Skills: Collision detection, Functions

All steps

  1. The map
  2. The player
  3. Ceiling, floor and a loop
  4. Turn around
  5. Walk
  6. Is it a wall?
  7. Stop at walls, slide along them
  8. A ray: where it starts
  9. A ray: the grid lines
  10. A ray: walk to the wall
  11. The 3D view
  12. No fish-eye
  13. Light and shade
  14. A timer
  15. Escape!
  16. Best time
  17. Touch controls
  18. Build it yourself: run