Title says it all really. I'm not sure how to design my map.
At the moment I have in my map object a vector of layers, which in their turn have a vector of tiles. But for collision checking I now have to go through every layer...
In what case do you have more than one sprite on the same tile? Are you counting background? Maybe some sort of projectiles?
Anyway, objects capable of collision can't overlap, right? In that case you can have them all in one layer.
How do you want your map to "behave"? Is there like several "levels" that the player can go up/down that need to be layered? Or are the layers purely graphical?
What you could do is have only one layer be "interactive" (you would do your collision checks with it), and all other layers be purely graphical (do nothing but draw tiles).
It's purely graphical. I don't see how I could go up/down if it's top-down? I think I'll just use a ladder sprite where you walk through xD.
And yes, it's background and stuff. But it doesn't matter anymore, I'm going to make only the second layer collisionable (is that a word?)
But how do I register events when I step on a tile, for example. Like when I collide with a door sprite, to make it load a new map?
1) Make an outline of any and all properties you want tiles to have.
2) Make a Tile class that encompasses all that info
3) Outline a tileset file format that lists all the tiles you want for a given map and their properties.
4) Load the tileset by loading individual tiles into some kind of container (perhaps a vector).
5) Your map should be an array of Tile*s, pointing to tiles in the tileset
6) When the player or another object moves, it examines the tiles on the relevent area(s) of the map.
7) If you want the player stepping on a specific tile to do something special, make that a tile property, and check for that property whenever the player moves.
I see, so I now have a std::map<int, void (*)(int)> to store my event functions. Next problem: For my loadMap function I need to pass my game.map variable too...
How do I do that?