Skip to content

DungeonGenerator

Fills its Tilemap with a dungeon made from a Seed, with no code: rooms of different sizes joined by corridors, walled in. The players start in the first room, the Exit waits in the room furthest from it, and the Spawns (monsters, potions, gold) are scattered through the other rooms. Reaching the exit makes the next floor. The same seed always makes the same dungeon; 0 makes a new one every game.

Part of the Dungeons module: Dungeons: floors of rooms and corridors made from a seed, floor after floor (DungeonGenerator), the Roguelike template, and Create Dungeon and Generate Dungeon in the Entity menu.

With GenerateOnPlay the map’s tiles are replaced by the first floor as the game starts; untick it to play the map as painted, with the floors after it generated. Corridors and rooms are FloorTile (or left empty) and the cells around them WallTile, so a grid player steps through the rooms and corridors and is stopped by the walls. Spawns go inside a “Spawns” entity in the dungeon’s, which the next floor clears out. The tiles and Floor are saved with the scene, so a rewind goes back to the floor it was on. In a network game the host makes the floors.

Requires: Tilemap (the dungeon it fills)

Works with: GridMovement (on the players, to step through it tile by tile); Counter (shows the floor (Output “Floor”))

Each is listed as its key in the scene file and the MCP tools, then its kind of value, its default and what it does.

  • seed: a whole number = 0. Picks the dungeon: the same number always makes the same one (each floor after the first its own). 0 makes a new one each game. (Field: a number.)
  • generateOnPlay: true or false = true. Make the first floor when the game starts. Untick it to play the map as painted; the floors after it are still made. (Field: on or off.)
  • width: a whole number = 48. Cells across. (Field: a number.)
  • height: a whole number = 32. Cells down. (Field: a number.)
  • rooms: a whole number = 9. How many rooms to make. Fewer fit in a small map: as many as there’s room for. (Field: a number.)
  • minRoomSize: a whole number = 4. The fewest cells across or down a room’s floor can be. (Field: a number.)
  • maxRoomSize: a whole number = 9. The most cells across or down a room’s floor can be. (Field: a number.)
  • corridorWidth: a whole number = 1. Cells across a corridor. (Field: a number.)
  • loops: a whole number = 2. Corridors added between rooms that are already joined, so there’s more than one way round. 0 makes every way the only one. (Field: a number.)
  • wallTile: a whole number = 0. The tile the walls are made of. (Tiles of the tilemap’s tilesets by number (the first tileset’s from 0, the next’s from 100, then 200…): a string of numbers and ranges like “10-15, 20”, or for a whole number one tile. The Inspector shows the tiles to click.) (Field: its own editor: Tile Numbers.)
  • floorTile: a whole number = -1. The tile for the floors of rooms and corridors; -1 leaves them empty. List it in the tilemap’s Background Tiles so nothing collides with it. (Tiles of the tilemap’s tilesets by number (the first tileset’s from 0, the next’s from 100, then 200…): a string of numbers and ranges like “10-15, 20”, or for a whole number one tile. The Inspector shows the tiles to click.) (Field: its own editor: Tile Numbers.)
  • fillWalls: true or false = false. Fill everything outside the rooms and corridors with wall. Untick it to wall them in with a single row and leave the rest empty. (Field: on or off.)
  • players: text = “Player”. Entities put in the middle of the first room as each floor is made, by name, separated by commas, e.g. “Player”. (Names entities: their names, separated by commas.) (Field: an entity’s name.)
  • exit: text = null. The entity put in the middle of the room furthest from the first, e.g. “Stairs”: a player stepping onto its cell goes down to the next floor (see DescendOnExit). (Names an entity.) (Field: an entity’s name.)
  • spawns: lines of text: an array of strings, or one string with line breaks = []. Prefabs scattered through the rooms (never the first) as each floor is made, one per line: its name and how many, e.g. “Enemy 4”, “Potion 1-2” (a number picked between them), “Gold” (one). (Prefabs and how many of each, one per line: the prefab’s name then a count, e.g. “Enemy 4”, “Potion 1-2” (a number picked between them) or “Gold” (one). The Inspector lists them a row each, picking the prefab from the project’s.) (Field: its own editor: Prefab Counts.)
  • floor: a whole number = 0. The floor the players are on, from 1 once the game has started; 0 before. Saved with the scene, so a rewind takes it back. (Field: a number.)
  • descendOnExit: true or false = true. A player stepping onto the Exit’s cell goes down to the next floor. Untick it to go down only when told to. (Field: on or off.)
  • nextFloorMessage: text = null. A message that makes the next floor when it’s sent, e.g. “Next Floor” from a Button or a script. Empty for none. (Names a message.) (Field: a name.)
  • floorMessage: text = “Floor”. A message sent with 1 as its data as each floor after the first is made, e.g. for a sound player. (A Counter counting its Output “Floor” shows the floor.) (Names a message.) (Field: a name.)
  • floorSound: text = null. A sound played as the players go down to the next floor, e.g. “Sounds/stairs.wav”. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)

What anything can make it do with no code: a Trigger’s do when its message arrives, a Contraptions Wire’s input as its signal comes on, a script’s Game.Do(entity, “Name”).

  • NextFloor. Goes down to the next floor, at the start of the next frame: a new dungeon, the players in its first room.

What anything can read with no code: a Counter’s, Bar’s or Text’s output, a Contraptions Wire’s output as its signal; Text shows names too, the rest read numbers, true as 1.

  • Floor (a whole number). The floor the players are on, from 1 once the game has started; 0 before. Saved with the scene, so a rewind takes it back.

Not saved with the scene; scripts read them, and entity_get shows them as live while the game plays.

  • usedSeed: a whole number. The seed the floor was last made from: the one picked when Seed is 0, then one of its own for each floor.
  • exitCell: [x, y], whole numbers or null. The cell the Exit was put in, or null before a floor is made.

Scripts use it as DungeonGenerator: its methods, events and values that aren’t saved with the scene.