/Lua-Dungeon-Generator

A procedural dungeon generator written in Lua.

Primary LanguageLua

Dungeon Generator

This is a procedural dungeon generator written in Lua 5.3.5 for roguelike games.

Example Output (default settings)

drawing

Example Output (customized settings)

drawing

How to use

In the root folder there is a file ExampleMain.lua which includes two examples of how the generator can be used.

  • main(): Using the Dungeon class (which holds many levels) and default generation settings for levels.
  • mainCustomizedLevel(): Generating one level with customized settings.

Default algorithm for levels

  • Creates matrix of given height/width
  • Places non-overlapping rooms of random sizes across matrix.
  • Creates minimal spanning tree of rooms using Prim's algorithm (to ensure whole dungeon is reachable).
  • Builds tile corridors between rooms by doing DFS through room tree.
  • Adds staircases and doors randomly but with certain constraints.

Available functionalities

Settings that can be modified:

  • Height/width
  • Maximum room size
  • Maximum number of rooms
  • ScatteringFactor: an attribute that changes randomness when building corridors between rooms.
  • Spawn rate of mineral veins "*" / soil "%".

Some useful functions to customize level:

  • Level:buildCorridor(from, to): builds a corridor from one room to another.
  • Level:addCycles(): Builds cycles randomly between rooms.
  • Level:buildRandomTiles(r,c): Builds random floor tiles around given tile.
  • Level:getRandRoom(): returns random room.
  • Level:getRoot(): returns root room.
  • Level:getEnd(): returns last leaf added to tree.
  • Level:addDoors()
  • Level:addStaircases()/Level:getStaircases()