Workshop › Wolfenstein-style 3D Maze › Step 6 of 18
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
}
```Math.floor turns a position like 2.7 into the tile number 2. The row comes from y, the column from x.[cx, cy] unpacks each pair.MINI, write RADIUS.move, write tileAt and blocked.Skills: Collision detection, Functions
← Walk Stop at walls, slide along them →