🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Finis

Published June 11, 2006
Advertisement
The maze class presented in the previous post provides a method called getEdgePattern() which queries a maze cell, analyzes its open and closed edges, and returns an unsigned char code representing that pattern. The pattern is determined by 4 bits. 1 bit for the north wall, 1 for the south, 1 for the east, and 1 for the west, for a total of up to 16 possible patterns. We can use that generated code for building our level. It is also useful to note that of these 16 patterns, several are similar to each other in shape, and differ only in orientation. Consider the piece where only the north wall is open and the others are closed. (Imagine a U shape). This piece is basically identical to the other three pieces where the south, east, and west walls are the only ones open, the only difference being the orientation of the piece. We can use this to decrease the work we have to do in converting a maze to a level, as we only have to pre-generated room patterns for 1 orientation and can then simply rotate them for the other similar configurations. Due to the nature of the mazes generated by the two algorithms presented, we can also safely ignore cell patterns of 15 (fully closed edges) since those cells are never generated. However, if you start tweaking with the maze (erasing walls, etc..) for special purposes, you may need those patterns.

Here is a sample set of room patterns, with two varieties for each category. In a real application, of course, you might want more variety. In the past, I have used as many as 12 general-case selections for each category, though that many might not be necessary. Even 4 or 5 varieties provides a great deal of randomization in room selection.



Once you have the maze constructed, building the level is a simple matter. Each cell of the maze represents some arbitrary sized chunk of tiles in the tile map, in this case 15 as each piece in the above image is 15x15 tiles. Iterate the maze structure, obtain the edge pattern code for each cell, and lookup the correct patterns for the given edge code. Perform a rotation on the pattern as needed, and copy the pattern of tiles into the tile map. And voila, you have a maze that looks less like a standard maze and more like some sort of dungeon complex. (Of course, it needs more room randomization, as well as interesting things to put in the rooms).

Here is a sample maze:


And here is one possible variation using the above pieces:


Simplicity in and of itself, really. The technique uses no tricky math whatsoever, not complicated concepts. Just simple graph theory and some pattern copying, yet the results can be an extremely useful tool for your toolbox of random level generation stuff.

EDIT: I just realized I left out 2 pieces. Sorry, my bad. Got in a hurry with the copy/pasting. There are 2 additional pieces for patterns of 0 (no walls) representing 4-way intersections. Use your imagination to know what they look like.
Previous Entry Mazes
Next Entry Random photos
0 likes 1 comments

Comments

Rob Loach
Very cool... I should use this technique to make a maze game one day.
June 12, 2006 09:26 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement