Workshop › Mario-style Platformer › Step 4 of 37
Everything the player does will ask one question: is this point inside a solid tile? solidAt(x, y) turns pixels
into a tile and answers, including what happens outside the level.
```js
function solidAt(x, y) {
const col = Math.floor(x / TILE)
const row = Math.floor(y / TILE)
if (col < 0 || col >= COLS) return true // invisible walls at both ends of the level
if (row < 0 || row >= ROWS) return false // open sky above, bottomless pits below
const tile = LEVEL[row][col]
return tile === '#' || tile === 'B'
}
```Math.floor(x / TILE) turns a pixel into a column: pixel 100 is in column 3 (100 / 32 = 3.1, floored).Above function draw() { write solidAt, with an empty line between them.
Skills: Collision detection, Functions
← Draw the tiles Is a box touching anything? →