Class structure for storing simple dungeon maps...

Started by
12 comments, last by GameDev.net 19 years, 1 month ago
Hello, What are some recommendations that you guys would have as a class structure for storing a simple dungeon map? Let's say I'm doing a rogue-like random 2D map. If my surface is 50x50 units, what do you recommend for demarking open cells versus closed? How about indicating doors between two cells? My initial guess would be something along the lines of a multidimensional array of 'cell' objects. Would you then indicate doors in a separate object, or would you try and indicate a 'door' inside of a cell object (maybe with a pointer to another cell instance?). How would the system handle if the door pointer pointed to a disconnected cell? Just getting my brain thinking about it... thanks for the ideas! -Ben
--Ben Finkel
Advertisement
why, not a multidimension grid, with coded tile numbers, e.g 0 is nothing, 1 is floor, 2 is wall .etc
For 50x50, it's small enough that I'd just make it a multidimensional array of pointers-to-cell-object. Make the pointer NULL where you can't pass, and point it at an appropriate terrain (floor type) cell where you can pass. The Cells can then contain a collection of items "in" that cell (for loot, monsters, etc).

If it's C# or Java, the "pointer to" is implicit, of course.
enum Bool { True, False, FileNotFound };
50x50 was a purely hypothetical number. I think that I'm more concerned about door placement, now that I've thought about it some more.


I'd like to avoid having a cell dedicated to a wall. i.e. maybe a corridor runs alongside an open room but only has a door into that room at one square. I don't want a whole row of 'empty' spaces and then have a 1-cell thick door. I'd like to indicate that the wall is impassible except at that one cell.

--Ben
--Ben Finkel
Another option is to have each cell linked to eachother through the exits. This way there is no wasted space but it can get kind of confusing to work with. For example I have cell A. Cell A is a room in a house. There are 2 exits in cell A, 1 north and one east. North links to cell B as a doorway with no door. East links to cell C with a closed locked door. The other exits do no exist so there is no wasted cell. This works best if you are "crawling" through a dungeon one cell at a time where only the current or directly adjacent visble cells are visble. It alleviates the wasted space but also causes some confusion while creating these maps and can very easily become difficult to manage in how you store/load them from a file. Depending on what your needs are this may or may not be a viable option.

Evillive2
Yup,

That was the exact conclusion I came to when thinking about it that way.

It seems like a multi-dimension array of 'Cell' objects would be the way to go. Each cell object would then have four walls and a floor. Each wall could either be marked with a door or not.


The problem I see there is the danger of discrepancy. If cell 5,5 has a door on it's left wall, and cell 4,5 does not have a door marked on it's right wall, how does the system resolve that?

--Ben

--Ben Finkel
each cell only needs two walls (top or bottom, and left or right). the other sides will be accounted for by the neighboring cells.

the only problem with this is that some edge cells won't have walls, but you could always make your map one row and column wider than you need to build those walls.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Krez,

Interesting, I like where you're going with this. Help me flesh it out some, if you don't mind.


How do I decide which cell is responsible for which wall? Every cell would be defined, and the walls would keep the player out of 'impassible' areas (areas that were not accessible)?

-Ben
--Ben Finkel
AhHa!

Checkerboard! Alternating cells are responsible for alternating wall pairs (North South vs. East West).

Any map configuration can be done, as long as you maintain that pattern.

Now, the formula to decide if a given cell is responsible for NS or EW? Hmmm

Got it, another painfully obvious answer. Cell.X+Cell.Y; odd results are one wall pair, even results are the other wall pair.



-Ben
--Ben Finkel
For a simple dungeon, a simple array will do. There is no need to make things overly complex.

This topic is closed to new replies.

Advertisement