Dungeon Generator

Filed under: development, games, dungeon, engine
/ (1 of 1)
Image by: tmib_seattle

A dungeon generator does exactly what it sounds like. It will, based on certain rules, generate a dungeon consisting of halls and rooms that are randomly connected. I am building this generator for use with the excellent AS3 game framework Flixel.

There are many ways to tackle a challenge like this. I have chosen one that apparently is often used in roguelike games. The procedure is built up of several iterations. The first one will split the entire into a few large chunks. These will be the basis for generating the rooms. Step 2 is to create rooms within the map chunks. Here we define variables for thickness of the wall, minimum length and width of a room, and whatnot. Step 3 is to create the halls. That is done by picking point on the edges of the rooms and drawing lines between them.

One can define all kinds of rules for each step to create variations in the dungeons. One can define rules that limits the numbers of rooms and their minimum and maximum sizes. There is also possible to define the shapes of the rooms. They don't necessarily have to be squared. In cases where two rooms are close to eachother, one can choose to merge the rooms into a bigger one. The creation of the halls can also have it's own rules. If two halls cross eachother, you might want to set up a tiny room with a shrine in the middle of the junction. The number of rules and their complexity is endless.

I want my dungeon generator to be completely abstract. That way I don't paint myself into a corner and can easily use/rewrite the code in other software. Rewriting it for Unity is one of the possibilities I'm thinking of.

To make the generator as flexible and understandable (from a coding point of view) as possible, I have decided to build it so that it is based on iterations. A coder can write his own iterations and plug them into the generator, and then tell the generator to execute them in a particular order.

The iterations can be simple or complex, and function quite different from eachother. First iteration could be to divide the map into larger chunks, while a later iteration would look for certain patterns and do whatever it is told to do.

After all of the iterations are done executing, the generator will be able to provide the dungeon data in a variety of ways. In Flash you could tell the generator to output a black and white map (that you can use with Flixel to draw tiles on), or you could return an array of the coordinates for all the rooms and halls. It wouldn't be too difficult to provide an array of walkable tiles either. As long as the generator only works with abstract variables it could return the data in a variety of ways.

So far I have made the routine that divides the room into larger chunks. The next step is to build the rooms. Looking forward to it :-)