While still in the design phase for a couple of games I’m working on, I have been learning and experimenting with procedurally generated content. One of the most well known and documented examples is the creation of roguelike dungeons, so this was a good place to start. I thought I’d go into a bit of detail about how I’m creating these if anyone is interested.
After looking through many examples and taking bits and pieces from different places, I came up with a couple of methods of generating different kind of tile-based 2D environments. Firstly there’s the standard roguelike setup with rectangular rooms and snaky corridors connecting them. Here’s an example of one being generated:
Firstly a number of rooms are added at random locations in a specified area. Many of them will overlap by chance. The overlapping ones show up in red. Separation is done by finding the centre of any intersecting rooms and moving them away from that point. Once all rooms are separated, the tiles are laid.
The edges of the rooms are filled in first, with wall tiles, and one doorway at the middle of each wall. Then the interior is filled in with floor tiles. Then the remaining tiles are filled in around the rooms. Corridors are added by using basic pathfinding techniques to move from the centre of each room to the centre of the room closest to the middle of the dungeon. Wall tiles cannot be passed through, so the corridors find one of the shortest paths available. There are multiple shortest paths so the direction taken is randomised at each tile to create a winding path.
Finally walls are added around the corridors and unreachable terrain is removed. There’s still much to be done to expand on this. Such as improving the ways that corridors are created so they aren’t all just reaching to the centre room, differently shaped rooms, and populating them with objects and enemies.
This may be used in conjunction with the method I’ve used to create cave systems, which I will cover in a later blog post.