Create Random Dungeons with Snippets

In this tutorial, we build our first random dungeon by using the „Snippets“-technique.

Snippets

The idea is to pre-define Snippets which this plugin will randomly connect to create appealing dungeons to explore. A snippet is a fundamental base element of the resulting maze, in detail: straights, turns, dead-ends, T-forks, and one crossing.

  1. We decide the size of all the snippets, let’s use 7 for both width and height.
  2. Create a map called „snippets“ (exactly this name). This map has a width of
    (4 * snippet's width) + 5
    and height respectively, in our case that’s 33 for both, width and height.
  3. Draw snippets as shown in the picture below.



    The plugin’s technique is pretty straightforward: It expects each primitive element (straights, turns, crossings, etc.) to be in a specific spot, which means you must follow this arrangement to get a logical map.



    However, you are free to draw whatever you wish. For example, it is not required for the blank tile to be completely black. When designing a forest, it could be nice to use grass here, which is passable for the player.
    Tips:
    • The yellow sand helps you to frame your snippets. You can use any tile here; just pick one with a high contrast.
    • This plugin uses functions to fix autotiles, so you don’t have to worry about them.
    • The same goes for shadows, they will be automatically erased when the map is generated.
  4. You maybe wondered if the map will later look clipped or repetitive. To get some more variety, you can repeat step 3 and make another map with Snippets.
    Important: Name them „Snippets2“, „Snippets3“, and so on. This plugin will then randomly pick from your maps.

Space Map

Create a new map with these settings:

  1. You can give it any name, e.g. „Space“
  2. Decide on the size of the generated dungeon, i.e., how many snippets are there for each column and line, let’s use 6 for both.
    By default, the plugin draws a margin around the map; hence, the formula for the map dimension is

    snippet's width * columns + 2

    and for the height, respectively. In our example, that’s 44 for both.
  3. Use the same Tileset as in the Snippet Map.
  4. Feel free to choose BGM, display name, encounters, …

Confirm and close this dialog.

Fill this map with the black Tile that you used in your Snippet on the top left.

Right-click here, and…
…fill out the Space Map

Entrance, Exits, Events, and Other Objects

Assets as Space Map’s child

Right-click your Space Map and create a new Map.

  • Call it Assets (exactly this name)
  • Choose the same Tileset as before

In this map, we define an entrance and an exit, gameplay-related objects like mobs, chests, switches, keys, and decorative objects.

Let’s have a look at this example:

Let’s break it down, row by row. Each one consists of:

  • Region Tiles on the left. Please ignore the 6 on the top, we come back to this later. The Region Tiles have these purposes:
    • They assign each row a unique number so we can easily refer back to them later.
    • They define the width and height of their corresponding object.
  • At least one object. That could be anything like regular Tiles or Events. When you put more than one object, the plugin picks randomly every time.

Entrance and Exits

The entrances and exits have a special role. First, the plugin sees no difference in whether you enter or leave the generated map. From now on, the entrance and the exit(s) are treated the same.

You can have up to 4 exits; one in each direction (north, west, east, south). Each exit has its reserved Region ID that you can look up:

  • 5: Southern Exit
  • 13: Northern Exit
  • 8: Western Exit
  • 15: Eastern Exit

For which directions do I need an exit?

You can choose whether the player can enter and leave the generated map from all 4 directions or, for example, just from south and north.

You need at least 2 of them.

For our first dungeon, we pick 2: The southern one where the player will spawn and the northern one where the player continues their expedition. Draw something like this:

Feel free to choose a different width or height, e.g., having a larger door. When you don’t want to visually emphasize where the player spawns, you can safely keep this tile blank.

Spawn Locations

All exits must have a Spawn Location defined. This is required so the plugin knows where exactly the player should spawn. A Spawn Location is a single Region Tile with a specific ID.

  • 6: Southern Spawn Location
  • 14: Northern Spawn Location
  • 9: Western Spawn Location
  • 16: Eastern Spawn Location

Tip: Slightly move the Spawn Location

It usually looks more appealing when the player spawns one tile below the gate.

Decorative Assets

Now, you can define more decorative objects.

By default, you can use Region IDs from 1, 2, 3, and 4. All of them are optional.

How can I add new rows?

You can use any other Region ID. To add or change Region IDs go into Templates/Plugin Manager.

Monsters, Chests, and other Gameplay-related Objects

As you can see in the screenshot above, you can add gameplay-related objects. By default, this plugin offers you 3 reserved IDs:

  • 20: loot chests
  • 21: mobs
  • 22: a single switch (e.g. for puzzles)

How can I change the number of spawns or add new assets?

You may use any other Region ID. To add or change Region IDs, or to change the number of how often an object spawns, go into Templates/Plugin Manager.

Region IDs

Below is a table of the default Region IDs and their function.

Some Region IDs are reserved for special functions. You may change them in the Plugin Manager („RNGMaps“, and in the Templates inside of „RNGMaps_withSnippets“).

Region IdDescription
5Southern Exit
6Southern Spawn Location
13Northern Exit
14Northern Spawn Location
8Western Exit
9Western Spawn Location
15Eastern Exit
16Eastern Spawn Location
1 – 4Decorative Objects
20Chests
21Enemies
22Switch (e.g. for Puzzles)

Multiple Assets in one Row

As you can see, you can always put more than one object in one row. You can also duplicate objects to easily make ratios. In this example, it’s more likely that a grey chest appears rather than the blue one.

Can I put empty objects on purpose?

By default, the plugin scans for the last asset of a row. You may use the Stopper Region Id (61 by default, which can be changed in the Plugin Manager) to tell the plugin where it should stop scanning. That is useful when you want to allow an asset to not spawn at all.

Put Region Tiles on the Snippets

By putting Region Tiles on your Snippets, you define where objects spawn. In detail, you place one Region Tile for one asset (regardless of its size).

By putting the 13 on the Snippet, the generator will put the exit on the generated map

Let’s go through all the different asset types. I recommend you to start with the exits first.

Exits

Exits have special rules. It is essential for the plugin that it is able to spawn all mandatory exits; otherwise, your player cannot spawn correctly or find an exit to escape from your dungeon.

Ensure that the generator is always able to spawn all the exits! For that, put one spawn point for the southern exit on every Snippet having a wall on its bottom, and for the northern one, respectively, on all Snippets having a wall on their top.

Common Objects

You can put all the other objects anywhere you want; just don’t block the player.

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.

Eventing

Finally, we can write the event command to start the generator. You can use Common Events to re-use your commands.

The player must be on the Space Map before you call the generator. The plugin relocates the player for you, so your transfer event can point anywhere on your Space Map.

Your (Common) Event, therefore, consists of:

  • a Transfer Event (any position on the Space Map)
  • a Script Call (MV)
    OR
  • Plugin Command (MZ)

It’s helpful to add some fade-in and fade-out effects to wrap everything.

This is an example of how your eventing could look like:

MZ: Plugin Command

Here, you define the directions into which your dungeon has exits. Note that the entrance is also treated as an exit. You also define from which direction the player spawns.

MV & MZ: Javascript Call

Non-Programmers, don’t be afraid. You don’t need any programming knowledge.

Make a Script command and copy-paste this:

$dungeonGenerator.template("Imperfect Maze")
.withExit("top")
.withExit("bottom")
.spawnPlayerAt("bottom")
.finalize()

with Exit:

You can have the line .withExit(x) up to 4 times; one for each direction (top, left, right, bottom).

Spawn Player at:

You can pass a direction (top, left, right, or bottom) or an x, y-pair. Example:

.spawnPlayerAt($gameVariables.value(1), $gameVariables.value(2))

Replace 1 and 2 with your Variable Ids.