Jump to content
  • Advertisement
Sign in to follow this  
benfinkel

Class structure for storing simple dungeon maps...

This topic is 4912 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

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

Share this post


Link to post
Share on other sites
Advertisement
why, not a multidimension grid, with coded tile numbers, e.g 0 is nothing, 1 is floor, 2 is wall .etc

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
For a simple dungeon, a simple array will do. There is no need to make things overly complex.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!