Skip to content

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.

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. Save a new file as dungeon-tiles.blend.

  2. 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.

  3. Tag each tile with tile.value (the cell value it draws) and tile.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).

  4. 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
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}.
  1. Save a new file as dungeon.blend. Add two data tables: data/monsters.json (rows of name, hp and dmg: rat 2 and 1, snake 3 and 2, goblin 5 and 2, orc 8 and 4, after an empty row 0) and data/items.json (what a room’s treasure roll gives, as tile values: gold, gold, a potion, nothing).

  2. Add two Empties, MapLayer and ActorLayer, each with Add Component ▸ Arcade ▸ Grid View. Give both the tags in the table below; set grid.var to mapView on the first and actorView on the second.

  3. In World ▸ Simulacrum ▸ Input, add left, right, up and down (for example keys:ArrowLeft/KeyA/KeyH ; repeat:220,140), wait = keys:Period/Space and again = keys:Enter/KeyR.

  4. Add a HUD Choice Menu pad (left=◀|up=▲|down=▼|right=▶|wait=Wait, shown while playing), a status line Depth {depth} · HP {hp}/{maxHp} · Gold {gold}, a message line {msg}, and a Descend again menu (again) shown while over.

  5. 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.

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.

  1. 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 from data/items.json.

  2. Your turn. On On Input left, right, up, down or wait: 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.”

  3. 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.

  4. Sight. After every turn, Grid Field of View (radius 7), and seen becomes the max of seen and visible.

  5. 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.

  6. Permadeath. At 0 HP the run ends and the last blow stays as the message. The deepest level is kept. again starts a new run with the next seed: a different dungeon.

  1. Press Build Cartridge. The game lists the tile set as a file it depends on.

  2. 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.

  • 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 with grid.tiles draws each cell with its model.
  • grid.window and grid.follow scroll a large map round the player.

Next: Functions makes a large graph like this one smaller with nested graphs and formulas.