Jump to content
  • Advertisement
  • entries
  • comments
  • views


Sign in to follow this  


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.
Sign in to follow this  

1 Comment

Recommended Comments

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
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!