Workshop › Sokoban › Step 15 of 29
boxAt(x, y) finds the box on a tile, if there is one. For now a box blocks the player like a wall; pushing comes
next.
```js
function boxAt(x, y) {
return boxes.find((box) => box.x === x && box.y === y)
}
function move(dx, dy) {
const x = player.x + dx
const y = player.y + dy
if (walls.has(key(x, y))) return
if (boxAt(x, y)) return // pushing comes in the next step
player = { x, y }
}
```boxes.find(...) gives the first box for which the test is true, or undefined if there is none.x equals x and (&&) its y equals y.return gives the found box back to the caller.move, a box on the target tile stops the step for now.function move, write boxAt and leave an empty line.move, under the wall line, write the box line. Press Run.Skills: Arrays and objects, Collision detection
← Walk with the arrows Push a box →