Procedural Random Dungeon Generator – Tutorial Part 1

Step 5: Map Settings

Go into the settings of our “Space” map. Into its Note Tag box, enter something like this. Text after the // symbol are comments, please don’t copy-paste them.

<load:[
{"name":"snippets", "map":2},  // "snippets" is hard-coded, 2 is the id of its map
{"name":"snippets2", "map":4}, // to use multiple snippets, append any number < 99 behind
{"name":"entrance_exit", "map":8},
{"name":"decoration", "map":5}, // "decoration" is not hard-coded, so you can use any name you want to
{"name":"decoration2", "map":6},
{"name":"decoration_pillars", "map":7},
{"name":"decoration_large", "map":9}
]>

Then, we need to connect all the chosen region IDs to their respective maps. Finally, here we set the dimensions of all the decoration objects. Paste this text block just directly below the text from the prior step (still in hint box).

<regions:{
"entrance_exit":{"w":1, "h":3}, // "entrance_exit" is hard-coded, here you define the w and h of the snippets from your entrance / exit map
"1":{"name":"decoration", "w":1, "h":1}, // "1" is the region you chose to put decoration on your snippets, the value for "name" is the same as defined above, "w" and "h" same as in entrance / exit
"2":{"name":"decoration2", "w":1, "h":2},
"3":{"name":"decoration_pillars", "w":1, "h":2},
"4":{"name":"decoration_large", "w":3, "h":2} } >

The finished block for our tutorial looks like this.

<load:[
{"name":"snippets", "map":1},
{"name":"entrance_exit", "map":3},
{"name":"decoration", "map":4}
]>
<regions:{
"entrance_exit":{"w":1, "h":3},
"1":{"name":"decoration", "w":3, "h":2}, } >

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 something 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:
    • Transfer Player to any Position on the “Space” Map (as the plugin will automatically adjust the player’s starting position)
    • Call our Common Event
  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. Well, you should consider a counter here to let the player actually 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

Your email address will not be published. Required fields are marked *