Sign in to follow this  

2d tile based gaming

This topic is 4359 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I'm doing a tile based game and my room looks something like this 1 1 1 1 1 1 1 0 0 0 0 1 1 0 0 0 0 1 1 1 1 1 1 1 I'm at the point where I need to create a bunch of rooms and can't come up with some really clever way of storing them all yet. Keep in mind there will probably be over 100 rooms when I'm done. And I want it to be something like Level 1 - 1, Level 1 - 2, etc. So each Level must be able to store a bunch of rooms. What do you recommend is the best way to store this data? doubled indexed array? vectors? I'm opened to all suggestions. Thanks

Share this post


Link to post
Share on other sites
My approach would be to store, on disk, maps as a bidimensional array of blocks of size NxN (where N can be a global constant, or be different in each file), with RLE to reduce size. Then, I would use a Map class to access tiles at [x][y] coordinates (using a proxy object for the second coordinate). Internally, the class will have access to a vector of vectors of blocks. The unused blocks would be stored as RLE (which takes less memory) and be converted on-the-fly to and from N²-sized vectors with [i+j*N] indexing. All this is, of course, hidden from the user. The N² vector would then allow much faster access to the tiles. This method combines small memory footprint (for all unused sectors of the map) with quick memory access (for the sectors that are accessed, except on the first access).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Use structs or classes to organize the data. Each room can have a two dimensional array or vector or something, and maybe some other data that is stored with the room, and each level can have a vector or array or something of rooms.

Share this post


Link to post
Share on other sites
I'd also like to add that keeping it simple would be a good idea. RLE compression would be nice to add later, but isn't really required.
Suppose your map data is 8 bit per tile - a room of 64 x 64 tiles would only be 4KiB in size. 100 rooms of 256 x 256 tiles would only be 6.25 MiB in size if stored uncompressed. That's not much considering todays computers.

Cheers,
Pat.

Share this post


Link to post
Share on other sites
Check this guide out.

This program, Dragon, converts standard-issue bitmaps into Ultima Online world maps. It's pretty much right up your alley, from a theoretical perspective.

If you create a program which converts 8-bit palettized bitmaps to a format which you want for your game (or, perhaps your game could read from bitmaps directly), then perhaps it would be prudent to do so. This would allow you to use a paint program to edit your maps, and even Windows comes with a paint program which would be decent for this application.

We've done this for the map system for our online game, and it works quite nicely. I highly recommend it!

Share this post


Link to post
Share on other sites
a. Create an object that represents a map sublevel:
class SUBMAP
{ int tile[MAXX][MAXY];
//Add some constructors and accesors. Maybe some processing functions
};

b. Probably you can live with a simple array:
class MAP
{ SUBMAP* submap[MAXSUBMAPS];
//Add some methos for map serilization like
void LoadMap(char* filename);
void SaveMap(char* filename);
}

c. Save your map with some header and the submap array. A simple file format would be
<map>
<submap id='0'>
<tile x='0' y='0' value='1' />
<tile x='0' y='1' value='1' />
<tile x='1' y='1' value='0' />
... etc
</submap>
</map>

Now, each level load the appropiate map file to our map object and your are ready to go.

Luck!
Guimo


Share this post


Link to post
Share on other sites

This topic is 4359 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this