Loading Maps..
Posted: Mon Nov 24, 2008 9:08 pm
Okay, so I'm working on my tile engine (a.k.a. my "game"), and I'm trying to figure out how best to handle loading and storing maps in the most dynamic way possible.
First off @ MarauderIIC:
Is this at all similar to what you tried to explain?:
level.txt
tiles.txt
Back on topic...
This is what my map file looks like at the moment:
test.map (line 1 is tilex, tiley, levelx, levely, -1 to terminate):
Level.h (Level class):
The question is how can I change ( int mapData[20][15]; ) so that I can create an array ( int mapData[tilesWide][tilesHigh]; ) depending on the values placed at the top of the map files? Is there some way to declare the size of a private class variable from within the Load function after I read it from the map? I was thinking about using a 2d vector, but that just seemed way too complicated. There must be something I'm just thinking way too hard about.
Thanks in advance for any help
-Dan
First off @ MarauderIIC:
Is this at all similar to what you tried to explain?:
level.txt
Code: Select all
//tilex, tiley, levelx, levely
32 32 160 160
tiles.txt
tile 2 0 0
tile 4 1 0
tile 1 2 0
tile 1 3 0
tile 0 4 0
tile 3 0 1
tile 3 1 1
tile 2 2 1
tile 2 3 1
tile 0 4 1
tile 2 0 2
tile 0 1 2
tile 1 2 2
tile 1 3 2
tile 1 4 2
tile 0 0 3
tile 2 1 3
tile 4 2 3
tile 1 3 3
tile 1 4 3
tile 4 0 4
tile 3 1 4
tile 0 2 4
tile 3 3 4
tile 3 4 4
Code: Select all
a.png 0 //tile 0
b.png 0 //tile 1
c.png 0 //tile 2
a.png 1 //tile 3 (same as tile 0 but with collision)
b.png 1 //tile 4 (same as tile 1 but with collision)
This is what my map file looks like at the moment:
test.map (line 1 is tilex, tiley, levelx, levely, -1 to terminate):
Code: Select all
32 32 640 480 -1
21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21
21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21
21 21 21 21 21 21 21 21 21 27 32 32 32 39 21 21 21 21 21 21
21 21 21 36 21 21 21 21 21 38 21 21 21 28 31 21 21 21 21 21
21 21 21 29 32 32 32 32 32 41 21 21 21 38 21 21 21 21 21 21
21 21 21 21 21 21 21 21 21 21 21 21 21 38 21 21 21 21 21 21
21 21 21 21 21 21 21 21 21 21 21 21 21 28 32 31 21 21 21 21
21 21 21 27 32 32 32 32 32 32 32 32 32 41 21 21 21 21 21 21
21 21 21 38 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21
21 21 21 38 21 27 32 32 32 32 39 21 21 21 21 21 21 21 21 21
21 21 21 38 21 38 21 21 21 21 38 21 21 21 21 21 21 21 21 21
21 21 21 38 21 38 21 21 21 21 38 21 21 21 21 21 21 21 21 21
21 21 21 38 21 29 32 33 33 32 41 21 21 27 32 32 39 21 21 21
21 21 21 38 21 21 21 38 38 21 21 21 21 38 21 21 29 31 21 21
21 21 21 29 32 32 32 35 35 32 32 32 32 41 21 21 21 21 21 21
Code: Select all
class Level
{
private:
int mapData[20][15];
public:
Level();
int Load( std::string filename );
int Draw();
};
Thanks in advance for any help
-Dan