The dungeon
For creatorsAdd-on 2.2.2+
In this tutorial you build a dungeon crawler. Every level is generated, you move one step per turn, the monsters act in between, and death is permanent. The rules decide what is where; a tile set made in Blender decides what it looks like. This builds on tutorial 4, Falling blocks.
▶ Play the finished game: arrows, W A S D or H J K L move you; walk into a monster to fight it. . or Space waits, Enter descends again. On a phone, use the pad.
How it fits together
Section titled “How it fits together”| Part | Where it comes from |
|---|---|
| What is where: the map, the monsters, the treasure | Grids in the rules’ variables, generated from a seed by graph nodes |
| What it looks like | A tile set: a separate Blender cartridge whose objects are tagged tile.value |
| Drawing | The Grid View component: each cell holding a value shows a copy of that value’s tile |
Swap a model in the tile set, keep its tag, and every level redraws with it. No rule changes.
1. Make the tile set
Section titled “1. Make the tile set”-
Save a new file as
dungeon-tiles.blend. -
Model one object per tile, made for a 1-metre cell, with its origin at the cell’s floor centre. Simple stand-ins are fine; you can replace them later.
-
Tag each tile with
tile.value(the cell value it draws) andtile.name(a readable name). The quickest way is to drag Tile from the Simulacrum asset library and edit its two tags, or add them to your own model with Add Tag (Object ▸ Simulacrum ▸ Tags). -
Press Build Cartridge. The tile set’s address is its web path followed by
/scene.osmx.
| Layer | Tiles |
|---|---|
| Map | 1 floor, 2 wall, 3 corridor, 5 stairs down, and 13 to 16: the same four remembered (seen before, out of sight now), dimmed |
| Actors | 6 gold, 7 potion, 8 the player, 9 rat, 10 snake, 11 goblin, 12 orc |
2. Meet the new nodes
Section titled “2. Meet the new nodes”| Node | What it does |
|---|---|
| Grid Dungeon | Rooms carved into rock from a seed, joined by L-shaped corridors, with walls round every carved cell. Outputs the grid and the rooms [[x, y, w, h], …]. The same seed always gives the same dungeon, and every walkable cell can be reached |
| Grid Field of View | The cells seen from (x, y) within a radius, along straight lines of sight blocked by the values you list as opaque (0,2: rock and wall) |
| Grid Path Step | The first step of a shortest path over the values you call passable, avoiding a blockers grid (other monsters). The goal itself may be occupied |
| Grid Find | Every cell matching a value (=, ≠, more, less), as a list of [x, y] |
| Grid Combine | Two grids cell by cell: B over A (layers), A masked by B (what is seen), max, min, add |
| Grid Remap | Each value looked up in a list: a remembered floor becomes the dim floor tile |
| Grid Move Cell | A value moved from one cell to another: a monster steps |
| Text | A string from a template: You slay the {a}. |
3. Set up the game file
Section titled “3. Set up the game file”-
Save a new file as
dungeon.blend. Add two data tables:data/monsters.json(rows ofname,hpanddmg: rat 2 and 1, snake 3 and 2, goblin 5 and 2, orc 8 and 4, after an empty row 0) anddata/items.json(what a room’s treasure roll gives, as tile values: gold, gold, a potion, nothing). -
Add two Empties,
MapLayerandActorLayer, each with Add Component ▸ Arcade ▸ Grid View. Give both the tags in the table below; setgrid.vartomapViewon the first andactorViewon the second. -
In World ▸ Simulacrum ▸ Input, add
left,right,upanddown(for examplekeys:ArrowLeft/KeyA/KeyH ; repeat:220,140),wait=keys:Period/Spaceandagain=keys:Enter/KeyR. -
Add a HUD Choice Menu pad (
left=◀|up=▲|down=▼|right=▶|wait=Wait, shown whileplaying), a status lineDepth {depth} · HP {hp}/{maxHp} · Gold {gold}, a message line{msg}, and aDescend againmenu (again) shown whileover. -
Look down at three quarters with an orthographic camera:
camera.mode=fixed,camera.projection=ortho,camera.at=0,14,9,camera.target=0,0,0.4,camera.orthoHeight=6.2,camera.orthoMinWidth=11(wider on a phone).
| Tag | Value | What it does |
|---|---|---|
grid.plane |
xz |
The grid lies on the floor, row 0 farthest away |
grid.cell |
1 |
One metre per cell, the size the tiles are made for |
grid.tiles |
your tile set’s address | Each cell shows its value’s tile instead of a coloured block |
grid.window |
19,15 |
Draw only this many cells round the player |
grid.follow |
px,py |
The two variables naming the cell the window centres on |
The player stays at the centre and the map scrolls under a still camera. Two grid views over one map make layers: the map first, then the actors.
4. Write the rules
Section titled “4. Write the rules”Make a Scene-scope graph named dungeon.rules and set it as the scene’s Rules. Its grids (map, seen, visible, mons, hpg, items, mapView, actorView) are json variables; best, the deepest level reached, is Persistent for the Player.
-
A level. The seed is
run× 1000 +depth, into Grid Dungeon. The first run’s number is itself a roll, so every play starts in a new dungeon. You start at room 0’s centre and the stairs go at the last room’s centre. Every other room rolls for a monster (80%, its kind limited by depth) and for treasure fromdata/items.json. -
Your turn. On On Input
left,right,up,downorwait: a monster in that cell is attacked (1 to 3 damage; at 0 HP it dies). A floor, corridor or stairs cell is walked onto, and gold, a potion or the stairs take effect. A wall costs nothing and says so: “A wall blocks the way.” -
Their turn. For Each over Grid Find (every monster): a monster next to you attacks, with its damage from
data/monsters.json. One that sees you steps toward you with Grid Path Step; move its HP grid first, because the path is read from the monsters grid before that grid changes. The rest wait. -
Sight. After every turn, Grid Field of View (radius 7), and
seenbecomes the max ofseenandvisible. -
Drawing. The map layer is the remembered cells remapped to their dim tiles, with what you can see laid over them. The actor layer is the treasure and the monsters in sight (each monster’s kind remapped to its tile), with you set at your cell.
-
Permadeath. At 0 HP the run ends and the last blow stays as the message. The deepest level is kept.
againstarts a new run with the next seed: a different dungeon.
5. Build and play
Section titled “5. Build and play”-
Press Build Cartridge. The game lists the tile set as a file it depends on.
-
Publish the tile set and the game (Publish and share), open the game and walk: the corridor ahead lights up as you see it, and the rooms behind you stay dimly remembered.
What you learned
Section titled “What you learned”- Grid Dungeon, Grid Field of View and Grid Path Step give generation, sight and pursuit with no game code.
- A tile set is a cartridge of models tagged
tile.value; a grid view withgrid.tilesdraws each cell with its model. grid.windowandgrid.followscroll a large map round the player.
Next: Functions makes a large graph like this one smaller with nested graphs and formulas.