Procedural Random Dungeon Generator – Tutorial Part 1

Step 5: Map Arrangement

Now when we have all the required Maps, we need to arrange them. All we have to do is to make the Space Map become the parent map of the maps we created in this tutorial. As soon as the player enters the Space Map, the plugin will scan its child maps and load them.

Each Space Map owns only the Snippet Maps which really belong to the individual dungeon. When you want to add a whole new generated dungeon, create a new Space Map and move all its required maps below it.

Step 6: Start Command

Finally, we can write the event command to start the generator.

  1. To keep our project and events more tidied up, we decide to use Common Events here. Let’s create a new Common Event (in the Database) and call it “generate Dungeon”.
  2. Now, make a “insert script” command and enter like this:

    $dungeonGenerator
    .prims()
    .mergeDeadEnds(0.3)
    .cutOffDeadEnds(2)
    .generate()
    .placeEntranceOn("bottom")
    .placeExitOn("top")
    .drawDecorations()
    .finalize();

    The merge dead ends function helps to lower the number of dead ends in the maze while it creates new tunnels between dead ends and other parts of the maze. This also leads to circulations in the maze and the fact, that there will exist more than one way to the escape. Experts call this an imperfect maze. The number 0.3 sets the probability that a tunnel will be made, while 1.0 means everytime and 0.0 means never.
    The cut off dead ends function will (as the name says) cut off dead ends, while the number 2 defines the number of iterations. A gangway with the length of 3 will later have the length of 1. This leads to blank spaces on the map, which I really appreciate.
    While calling the place entrance / exit function, we set where they should spawn. Possible alternatives are “left”, “right”, and “any”.

    Close the Database.
  3. We now let the player enter the dungeon. On any map (eg. World Map if your game has one) create an event with this commands:
    • Screen Fade-Out
    • Transfer Player to any Position on the “Space” Map, use instant Transition Fade
    • Call our Common Event
    • Screen Fade-In
  4. Last but not least: the exit, while we keep it easy. We don’t need a transfer command here (as we are already on the Space Map), just call our Common Event again. I recommend to fade-out and fade-in the screen. Eventually, you should think about a counter to let the player escape the dungeon after he found the exit x times.

Conclusion

Using this plugin to generate dungeons is a tricky exercise. However, it provides great power to design good-looking maps. When steps are unclear, feel free to look into my demo project.

Leave a comment