The Player
The player
is the character you control in the game. It is defined by two properties: its appearance and its starting position.
Player Appearance
The player’s appearance is set using the sprite
property. It can be:
A number between 0
and 9
In this case, the player will be shown as a solid-colored rectangle using the corresponding color:
createGame({
player: {
sprite: 7
}
})
A string
This allows you to define a more complex sprite, line by line. Each digit corresponds to a color, and .
represents a transparent pixel:
createGame({
player: {
sprite: `
...44...
...88...
...88...
.434434.
4.3443.4
1.3333.1
..3333..
..3..3..
`
}
})
Note
Sprites are explained in more detail in the dedicated section.
Starting Position
You can define the player’s initial position on the map using the position
key.
It should be an array in the form [x, y]
, where x
is the column and y
is the row in the grid.
For example, [2, 5]
places the character in the 2nd column and 5th row (from the top):
createGame({
player: {
sprite: 7,
position: [3, 4]
}
})
By default, the player appears at the top-left corner of the map, at position [0, 0]
.