Package dngn is a simple random map generation library primarily made to be used for 2D games. It features a simple API, and a couple of different means to generate maps. The easiest way to kick things off when using dngn is to simply create a Room to represent your overall game map, which can then be manipulated or have a Generate function run on it to actually generate the content on the map.
Room represents a dungeon map. Width and Height are the width and height of the Room in the layout. This determines the size of the overall Data structure backing the Room layout. Data is the core underlying data structure representing the dungeon. It's a 2D array of runes. Seed is the seed of the Room to use when doing random generation using the Generate* functions below. CustomSeed indicates whether the Seed was customized - if not, then it will default to using the time of the system to have random generation each time you use Generate* functions.
NewRoom returns a new Room with the specified width and height.
NewRoomFromRuneArrays creates a new Room with the data contained in the provided rune arrays.
NewRoomFromStringArray creates a new Room with the data contained in the provided string array.
Area returns the overall size of the Room by multiplying the width by the height.
Center returns the center position of the Room.
ClearSeed clears a custom seed set for random generation. When using a clear seed, random generation functions will use the system's Unix time.
CopyFrom copies the data from the other Room into this Room's data. x and y are the position of the other Room's data in the destination (calling) Room.
DataToString returns the underlying data of the overall Room layout in an easily understood visual format. 0's turn into blank spaces when using DataToString, and the column is shown at the left of the map.
DrawLine is used to draw a line from x, y, to x2, y2, placing the rune specified by fillRune in the cells between those points (including) in those points themselves, as well. thickness controls how thick the line is. If stagger is on, then the line will stagger it's vertical movement, allowing a 1-thickness line to actually be pass-able if an object was only able to move in cardinal directions and the line had a diagonal slope.
GenerateBSP generates a map using BSP (binary space partitioning) generation, drawing lines of wallValue runes horizontally and vertically across, partitioning the room into pieces. It also will place single cells of doorValue on the walls, creating doorways. Link: http://www.roguebasin.com/index.php?title=Basic_BSP_Dungeon_generation BUG: GenerateBSP doesn't handle pre-existing doorValues well (i.e. if 0's already exist on the map and you try to use a doorValue of 0 to indicate not to place doors, it bugs out; either it might place a wall where a doorway exists, or it won't place anything at all because everywhere could be a door). A workaround is to use another value that you turn into 0's later.
GenerateDrunkWalk generates a map in the bounds of the Room specified using drunk walking. It will pick a random point in the Room and begin walking around at random, placing fillRune in the Room, until at least percentageFilled (0.0 - 1.0) of the Room is filled. Note that it only counts values placed in the cell, not instances where it moves over a cell that already has the value being placed. Link: http://www.roguebasin.com/index.php?title=Random_Walk_Cave_Generation
GenerateRandomRooms generates a map using random room creation. fillRune is the rune to fill the rooms generated with. roomCount is how many rooms to place, roomMinWidth and Height are how small they can be, minimum, while roomMaxWidth and Height are how large they can be. connectRooms determines if the algorithm should also attempt to connect the rooms using pathways between each room. The function returns the positions of each room created.
Get returns the rune in the specified position in the Room's Data array. A convenience function stand-in for "value := room.Data[y][x]".
MinimumSize returns the minimum distance (width or height) for the Room.
Resize resizes the room to be of the width and height provided. Note that resizing to a smaller Room is destructive (and so, data will be lost if resizing to a smaller Room).
Rotate rotates the entire room 90 degrees clockwise.
Select generates a Selection containing all of the cells of the Room.
SelectContiguous generates a Selection containing all contiguous (connected) cells featuring the same value as the cell in the position provided.
Set sets the rune provided in the Room's Data. A convenience function stand-in for "room.Data[y][x] = value".
SetSeed sets a custom seed for random generation.
A Selection represents a selection of cell positions in the Room's data array, and can be filtered down and manipulated using the functions on the Selection struct.
AddSelection adds the cells in the other Selection to the current one if they're not already in it.
By simply takes a function that takes the X and Y values of each cell position contained in the Selection, and returns a boolean to indicate whether to include that cell in the Selection or not. This allows you to easily make custom filtering functions to filter down the cells in a Selection.
ByArea filters down a selection by only selecting the cells that have X and Y values between X, Y, and X+W and Y+H. It crops the selection, basically.
ByNeighbor selects the cells that are surrounded at least by minNeighborCount neighbors with a value of neighborValue. If diagonals is true, then diagonals are also checked.
ByPercentage selects the provided percentage of the cells curently in the Selection.
ByRune filters the Selection down to the cells that have the character (rune) provided.
Contains returns a boolean indicating if the specified cell is in the list of cells contained in the selection.
Degrade applies a formula that randomly sets the cells in the selection to the provided char rune if their neighbors have that same rune value. The more neighbors that have the rune value, the more likely the selected cell will be set to it as well.
Expand expands the selection outwards by the distance value provided. Diagonal indicates if the expansion should happen diagonally as well, or just on the cardinal 4 directions.
Fill fills the cells in the Selection with the rune provided.
Invert inverts the selection (selects all non-selected cells from the Selection's source Room).
RemoveSelection removes the cells in the other Selection from the current one if they are already in it.
Shrink shrinks the selection by one.