Layers of tiles or 1 layer with multiple sprites per tile?

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.
Last edited on
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.


See this post for more details:
http://cplusplus.com/forum/general/42924/#msg232049
1) How should I make the outline for events? Is it like a function? And what if the tile doesn't need to register any events? Empty function?

2) Check.

3) Check.

4) Check.

5) Check.

6) Will do!

7) Will do!

If you want the event triggered by the player stepping on a specific tile, make it a property of the tile:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
struct Tile  // or class, whatever
{
//...
  unsigned event;  // 0 = no event
};

//...

// when player moves

const Tile* t = mymap( player.x, player.y );

if(t->event && !DidEventAlreadyTrigger(t->event) )
{
  // dispatch event here, based on above event ID
}


How you want to dispatch it is up to you. If you want to hardcode events or script them somehow.
Last edited on
Hmm I think I'm going to do it likes this:

1
2
3
4
5
6
7
8
9
10
11
Class Tile
{    

public:
        Tile(sf::Sprite sprite_, bool walkable_, unsigned event_);
        sf::Sprite sprite;
        unsigned event;
        bool walkable;
        void draw(sf::RenderWindow& Window);

};


But how do I, for example, store the name of the file to be loaded when the event is triggered, without adding a string variable to all my tiles?
Last edited on
You could have an index->string lookup file of sorts. Something that looks like this:
1
2
3
event name 1.evt
foobar.evt
person explodes.evt


(top event being event ID 1 assuming ID 0 = no event)

Then load all lines into a vector.

Or you could hardcode that.

Or you could just use a string in your tile instead of an unsigned.



PS: draw should take a sf::RenderTarget&, not an sf::RenderWindow&.
Really? Because it does work right now...?
And I'll guess I'll make several files, one for each event that has varying variables?

EDIT: I'm a little stuck on how to implement the function to load a new map...
How do I know at which "entrance" I enter the map with my player?
Last edited on
Really? Because it does work right now...?


sf::RenderTarget is a more abstract class.

It be like outputting to a ofstream when you should be outputting to an ostream.


EDIT: I'm a little stuck on how to implement the function to load a new map...
How do I know at which "entrance" I enter the map with my player?

specify an x,y position in addition to a map ID.
Last edited on
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?
Topic archived. No new replies allowed.