Let’s say the player is a bitmap that is 8 x 8 pixels. You could track the player’s location using a Rect object.
constexpr uint8_t PlayerWidth = 8, PlayerHeight = 8;
Rect player(0, 0, PlayerWidth, PlayerHeight);
This creates a Rect object named player at location 0, 0 with size 8 x 8. To move the player, you change the x and y members.
player.x = 5;
player.y = 13;
moves the player to location x = 5, y = 13.
You could draw it there:
arduboy.drawBitmap(player.x, player.y, playerSprite, PlayerWidth, PlayerHeight);
Let’s say there’s a 16 x 12 block, with the top left corner at location 45, 37. You define this as another Rect object.
constexpr uint8_t BlockWidth = 16, BlockHeight = 12;
Rect block1(45, 37, BlockWidth, BlockHeight);
If you wanted the block to actually just be a rectangle you could draw it using the drawRect() function
arduboy.drawRect(block1.x, block1.y, BlockWidth, BlockHeight);
Now, to test if the player is in contact with the block (at least one pixel of their rectangular areas is overlapping), you can use the collide() function.
if (arduboy.collide(player, block1)) {
arduboy.print("Player is touching the block");
}
Note that with the above example, the check is for overlapping areas. If you want to check for “touching” you may have to adjust the area or what is drawn, for one of the objects, by one pixel on each side.
arduboy.drawRect(block1.x + 1, block1.y + 1, BlockWidth - 2, BlockHeight - 2);