Once Within a Dungeon Dreary …

New App on the way!

Random Dungeon Creator!

A Random Dungeon

I learnt a lot from reading this article:
https://gamedevelopment.tutsplus.com/tutorials/create-a-procedurally-generated-dungeon-cave-system–gamedev-10099
So if you are interested in the nitty-gritty, go take a look!

So far, it draws a map (as above), with a random number of rooms (4-13) and joins them with corridors. Add a few Doors, and Voila! A Dungeon!

I’ll be writing a Contents generator for it, to add Monsters, Loot, and other features, but that may take a while.

While you’re waiting, I’ll explain a little about how the generator works:

The display is split into a Grid pattern, 60×35 (approx). This grid is held in a two-dimensional array, representing the co-ordinates. Each entry represents a “tile” in the Dungeon. These “tiles” are populated with the different features you may find:

First, Rooms. Without Rooms, a Dungeon is just a Maze, or Labyrinth. We need somewhere for the Monsters to gather, and hoard their Loot.

A simple function picks a random point on the map as the top left corner, and then picks another point to be the bottom right corner. This defines our rectangular room. This is checked against the List of Rooms, to see if it overlaps. We recreate a new room until it does not, and then this is added to the list.

Some rooms

Once we have enough rooms, they are joined together with corridors. Starting with the first room, we extend a short horizontal corridor in the direction of the next rooms, and then vertically until level with the center of the room. Another horizontal corridor takes us to the room.

The spaces to the sides of the corridors, and around the rooms are defined as Solid Rock.

This procedure is repeated until all rooms have been joined.

As we define the Rooms and Corridors, the Array is filled, each Point being set to “C” (Corridor) or “R” (Room) or “V” (Void. Undefined) or “S” (Solid Rock).

Now, we iterate over the Array, using it’s co-ordinates to draw the features. A simple “Switch/Case” statement determines which Tile is placed on the map.

A tip I picked up from Donjon was to always work on Odd numbered grids, leaving the Even numbered columns and rows as Solid Rock or Void. This ensures space between the rooms, and produces (in my opinion) a better map.

Map, with Array values overlaid

The only other tweak so far is to add doors. Each time we place a corridor, the first point is defined as a door

You will note that not all entrances seem to have doors! This is because some corridors run through rooms! In this following example, the corridor from Room 2 to Room 4 does not have a door, as it is actually a corridor from Room 3! “1 to 2” has a door as it leaves 1. “2 to 3” (the lower of the short corridors joining 2 and 3). “3 to 4” has a door as it leaves 3, and then passes through Room 2, turns, and continues to 4.

No door from 2 to 4!

In this way, we build up complex corridors and junctions from some very simple rules. The maps with more rooms have a lot more corridors, that cris-cross each other, and travel through rooms. See if you can trace each corridor in this map (not that it matters, once created. Brave Adventurers may take any route!):

Which corridor is which?

So, there we have it. The result of many long hours sweating over the keyboard, swearing and throwing things!

I will let you know when it is updated with Contents!