Making Forests and Caves Part 2 – Structures and Decoration


After completing the last tutorial, you may wonder what had happened with the walls. We will do them now!

Let’s create a new Map, call it „Structures“ (or any other name) with the same Tileset that you selected in the Space Map, and put it below the Space Map.

Now, let’s look at this screenshot:

This map defines, on its left, combinations of tiles, that the generator will scan for. Any area from the generated map, that fits with one matcher, is replaced by any combination from its right. We’ll go into more detail now. Each row consists of

  • one Region Id block (blue), that assigns this row with a width&height and a number. The number does not matter, so just start from 1 and count up.
  • at least one Matcher (orange), each matcher must have the same width&height than your region Id block. Use blank tiles as joker.
  • one blank area with the same size than your region Id block, to separate matchers from replacements. If your matchers have a width of e.g. 2 each, then the blank area must be 2 tiles wide, too.
  • at least one Replacement (green); draw what should be drawn by the generator. For instance, walls, assets, dirts… You can set a Region Id Stopper 61 to make blank objects.


For a dungeon with 2 tile-high walls, I found out this layout works quite good.

Let’s make a new Map, call it „Details“, and draw something like this:

As you can see, when there’s grass on the floor, there’s a much higher chance to draw plants than when the floor is dirt. On grass tiles there’s a chance to draw small plants.

Tips and Ideas

  • The generator works from top to bottom. That means, you can use the upper rows to define basic structures, walls, etc. and then you can set a wall as matcher itself to define more details.
  • For the replacements, you can draw the same element multiple times, to get a ratio.
  • To not draw small flowers on every single floor tile, you can use the Region Id Stopper 61. For example, draw 4 different flowers, leave 20 tiles empty, and then draw a Region 61 Stopper. Then you get a 1:5 ratio that a flower is drawn.
  • Having a wall and a water tile below will create a waterfall! (Everytime or by chance, as you define it)
  • Wall tiles that are right next to water tiles will have a higher change of having greens.

Having a 61 Stopper Tile, the generator will now include all assets being on its left, regardless if they are blank or not. As a blank tile won’t modify the result, you can use this technique to draw assets by probability. Looking at this screenshot above, there’s a roughly 1:3 change of an asset being placed.

JavaScript Calls

We extend our Script Call to something like this:


The line „drawStructures“ must contain the name of the Map in which you defined the structures. If it is exactly „Structures“, it can be left out.

Decoration and Assets

The term assets would fit better, but for historical reasons, this article keeps with the term decoration.

A Decoration Map works basically the same as the Structures Map, but it has some special rules. While tiles, that are defined in the Structures Map, are drawn anywhere consistently, decorations are not drawn automatically. Instead, they are placed with more control. For instance, decorations can be drawn x-times, and therefore it’s usually used for loot chests or monsters that should be spawn n but m times at most.

To create a Decoration Map, create a new Map, call it „Decoration“ (exactly this name), again use the same tileset, and put it below the Space Map. Place Assets as we did before in the Structure’s Map. I use this Map only to add some Loot chests.

Region Ids are important now. Don’t use reserved Region Ids, that are 5, 6, 13, 61 by default.

Example having Lootchests and Monsters

JavaScript Calls

We extend our Script Call to something like this:

.drawDecorationXTimes(11, 2, 4)
.drawDecorationXTimes(14, 2, 3)

As you can see, you can call those methods multiple times and in any order. Sometimes it’s easier to draw Loot chests before the Details.

The drawDecorationXTimes function works as follows:


will draw any asset from region Id 11 exactly once – if possible.

.drawDecorationXTimes(11, 3)

will draw any asset from region Id 11 exactly 3 times – if possible.

.drawDecorationXTimes(11, 2, 4)

will draw any asset from region Id 11 at least 2 times and 4 times at most – if possible.

„If possible“ refers to to the fact that an asset won’t be placed if there are not places left on the generated Map that matches with the decoration’s matchers. In such cases, nothing will happen.

Continue with Part 3.