Ok so basically the idea is that you have a Player class that represents your player. It has two values : x and y which are respectively the column and row indices where the player is.
If you are new to objects, I recommend you take a look at this tutorial :
https://processing.org/tutorials/objects/
Here is the skeleton of the class :
class Player {
int x, y;
Player(int startX, int startY) {
// The player starting location
x = startX;
y = startY;
}
void move(int dx, int dy) {
// As described above...
}
void left() {
move(-1, 0);
}
void down() {
move(0, 1);
}
// Same for other directions
}
So the player class is holding the data but you need to display it on the grid. For this, add a display method to it :
class Player {
void display() {
// Compute the position of the image according to the tile size
int spriteX = x * tileSize;
int spriteY = y * tileSize;
image(playerSprite, spriteX, spriteY);
}
}
In this method, I assume that tileSize (the size of a tile in pixels, in your case 16) and playerSprite (a PImage holding the image of the player) are both global variables accessible from everywhere (declared outside of draw and setup).
For now this is a simple approach but later you might consider passing those variables to the method or display the player from outsideā¦