Workshop › Mario-style Platformer › Step 6 of 37
loadLevel scans every tile of the level text once. At the P it creates the player: a 24×30 box standing on the
ground of that tile. The level text stays an unchanging blueprint; player is live state built from it.
```js
let player
function loadLevel() {
LEVEL.forEach((line, row) => {
for (let col = 0; col < COLS; col++) {
const x = col * TILE
const y = row * TILE
if (line[col] === 'P') player = { x: x + 4, y: y + 2, w: 24, h: 30 }
}
})
}
loadLevel()
```forEach((line, row) => ...) calls the function once for every row, with the row's string and its number.'P' the player is placed 4 pixels in from the tile's left (it is 24 wide, the tile 32) and 2 pixels down, so its
bottom (2 + 30 = 32) is exactly on the tile's bottom: standing on the ground below.loadLevel() runs once before the loop starts.function solidAt(x, y) { write let player and an empty line.function draw() { write loadLevel, with an empty line between them.loadLevel() just above the last line, requestAnimationFrame(loop).Skills: Arrays and objects, Game states
← Is a box touching anything? Draw the player →