For the games that I’ve made, I have an array of bytes where each byte is a different image.
For instance, a my could look like this:
const unsigned char levelmap[][112] PROGMEM = {
{ // Level 1
1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2,
6, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 6,
6, 50, 50, 50, 50, 37, 50, 37, 50, 12, 50, 50, 50, 6,
6, 50, 51, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 6,
6, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 6,
6, 50, 50, 50, 50, 37, 50, 37, 50, 12, 50, 38, 50, 6,
6, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 6,
3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4
},
//...
}
Whenever I move the character around, I check which space he’s going to move into. If it’s higher than 25, I don’t allow movement since I consider it to be a solid object that I don’t want the player to walk through.
You could alternatively use halfbytes if you know how to do that where every byte either starts with 0
or 1
, which makes the tile solid or walkable.
My Circuit Dude game has a really simple/easy map system that includes collision detection. Try to check out the source code whenever it’s out for a more detailed explaination on that.