Skip to contents

Procedurally generate a tile-based ASCII-character dungeon map. Creates a tile-based map of user-specified size; places randomly a user-specified number of rooms; connects them with a continuous corridor; and iteratively expands the interior space by sampling from adjacent tiles. Note: much of this function has been absorbed into the start_game function, but generate_dungeon will continue to be exported for now.

Usage

generate_dungeon(
  iterations = 5,
  n_row = 30,
  n_col = 50,
  n_rooms = 5,
  is_snake = FALSE,
  is_organic = TRUE,
  seed = NULL,
  colour = TRUE
)

Arguments

iterations

Numeric. How many times to 'grow' iteratively the dungeon rooms, where tiles adjacent to current floor tiles (.) have a random chance of becoming floor tiles themselves with each iteration.

n_row

Numeric. Number of row tiles in the dungeon, i.e. its height.

n_col

Numeric. Number of column tiles in the dungeon, i.e. its width.

n_rooms

Numeric. Number of rooms to place randomly on the map as starting points for iterative growth.

is_snake

Logical. Should the room start points be connected randomly (FALSE, the default) or from left to right across the room matrix (TRUE)? See details.

is_organic

Logical. Join the room start points with corridors before iterative growth steps (TRUE, the default), or after (FALSE)? See details.

seed

Numeric. Seed to reproduce a dungeon.

colour

Logical. Should the characters be coloured using crayon (TRUE, the default)?

Value

A matrix, invisibly. Output via cat to the console.

Details

  • You'll have to experiment to find the 'best' argument values for your needs. Typically, a larger dungeon should have a higher n_rooms value and can be grown through more iterations. Use is_snake and is_organic to play with dungeon appearance and connectedness.

  • For argument is_snake, TRUE will create a single continuous, winding cavern from left to right, while FALSE will create a more maze-like cavern.

  • For argument is_organic, TRUE will generally create what looks like a natural cavern, since the room start points and corridors are subject to iterative growth. When FALSE and is_snake is FALSE, the dungeon's caverns are more square, or more 'artificial' looking. When FALSE and is_snake is TRUE, the result is more likely to be a series of discrete roundish rooms connected by a narrow (one tile-width) corridor.

Examples

if (FALSE) {

# A 'natural' cavern with default arguments
generate_dungeon(seed = 23456)

# Rooms connected sequentially by narrow corridors
generate_dungeon(
  iterations = 8,      # iterate room growth 8 times
  n_rooms = 4,         # randomly place 4 room tiles to start
  is_snake = TRUE,     # connect rooms from left- to right-most
  is_organic = FALSE,  # add single tile-width corridors after growth
  seed = 2
)
}