   2d tile based gaming
  So I'm doing a tile based game and my room looks something like this1 1 1 1 1 11 0 0 0 0 11 0 0 0 0 11 1 1 1 1 1I'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   
  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).   ;  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.   ;  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.   ;  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!;  A very easy way to do it would be to use a 4dimensional array. Sort of like this:int Map[MAX_LEVEL][MAX_STAGE][MAX_X][MAX_Y];;  i agree with caseyd, if Hd space is a problem; which it shouldn't, youcould always use a better compression later. Like zlib or something.   ;  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