Class DungeonBoneGen
java.lang.Object
squidpony.squidgrid.mapping.styled.DungeonBoneGen
public class DungeonBoneGen extends Object
Generate a dungeon using Sean T. Barrett's Herringbone Wang Tiles method. http://nothings.org/gamedev/herringbone/
Created by Tommy Ettinger on 3/10/2015.
- Author:
- Tommy Ettinger - https://github.com/tommyettinger
-
Field Summary
Fields Modifier and Type Field Description GreasedRegion
region
A GreasedRegion that, aftergenerate(TilesetType, int, int)
has been called, will hold the floor cells in its data as "on" cells and walls as "off" cells.IRNG
rng
GreasedRegion
workingRegion
Not recommended for general usage; a GreasedRegion that is frequently modified by this generator and is kept in a field so this and potentially other classes can avoid allocating new GreasedRegions withGreasedRegion.remake(GreasedRegion)
or the various refill methods in GreasedRegion. -
Constructor Summary
Constructors Constructor Description DungeonBoneGen()
Constructs a DungeonBoneGen that uses a default RNG, randomly seeded.DungeonBoneGen(Random random)
Constructs a DungeonBoneGen that uses the given java.util.Random .DungeonBoneGen(IRNG random)
Constructs a DungeonBoneGen that uses the given IRNG. -
Method Summary
Modifier and Type Method Description char[][]
generate(Tileset ts, int w, int h)
Generate a dungeon given a Tileset.char[][]
generate(TilesetType tt, int w, int h)
Generate a dungeon given a TilesetType enum.char
get(int x, int y)
Gets the char at a given x,y position.char[][]
getDungeon()
Get the char[][] dungeon that was last returned by generate(), or null if generate() or setDungeon have not been called.int
getHeight()
Returns the height, used as the second coordinate in any char[][] in this class.IRNG
getRng()
Gets the current RNG.int
getWidth()
Returns the width, used as the first coordinate in any char[][] in this class.void
put(char elem, int x, int y)
Sets the char at the given x,y position, storing it in this object.void
setDungeon(char[][] dungeon)
Change the stored char[][] dungeon, using x,y indexing.void
setRng(IRNG rng)
Sets the current RNG.String
toString()
Provides a string representation of the latest generated dungeon.char[][]
wallWrap()
Changes the outer edge of this dungeon to the wall char, '#'.static char[][]
wallWrap(char[][] map)
Changes the outer edge of a char[][] to the wall char, '#'.
-
Field Details
-
rng
-
region
A GreasedRegion that, aftergenerate(TilesetType, int, int)
has been called, will hold the floor cells in its data as "on" cells and walls as "off" cells. This can be useful for inter-operating with code that expects a GreasedRegion, which can be for various reasons. -
workingRegion
Not recommended for general usage; a GreasedRegion that is frequently modified by this generator and is kept in a field so this and potentially other classes can avoid allocating new GreasedRegions withGreasedRegion.remake(GreasedRegion)
or the various refill methods in GreasedRegion.
-
-
Constructor Details
-
DungeonBoneGen
Constructs a DungeonBoneGen that uses the given java.util.Random .- Parameters:
random
- A Random number generator to be used during the dungeon generation; it will be used to generate a seed for the internal RNG this class uses.
-
DungeonBoneGen
Constructs a DungeonBoneGen that uses the given IRNG. -
DungeonBoneGen
public DungeonBoneGen()Constructs a DungeonBoneGen that uses a default RNG, randomly seeded.
-
-
Method Details
-
getRng
Gets the current RNG.- Returns:
-
setRng
Sets the current RNG.- Parameters:
rng
-
-
getWidth
Returns the width, used as the first coordinate in any char[][] in this class.- Returns:
-
getHeight
Returns the height, used as the second coordinate in any char[][] in this class.- Returns:
-
getDungeon
Get the char[][] dungeon that was last returned by generate(), or null if generate() or setDungeon have not been called. Uses x,y indexing.- Returns:
-
setDungeon
Change the stored char[][] dungeon, using x,y indexing.- Parameters:
dungeon
-
-
get
Gets the char at a given x,y position.- Parameters:
x
-y
-- Returns:
-
put
Sets the char at the given x,y position, storing it in this object. The dungeon this modifies is accessible with getDungeon() and can be set all at once with setDungeon().- Parameters:
elem
-x
-y
-
-
generate
Generate a dungeon given a TilesetType enum. The main way of generating dungeons with DungeonBoneGen. Consider using DungeonBoneGen.wallWrap to surround the edges with walls. Assigns the returned result to a member of this class, 'dungeon'.- Parameters:
tt
- A TilesetType enum; try lots of these out to see how they look.w
- Width of the dungeon to generate in chars.h
- Height of the dungeon to generate in chars.- Returns:
- A row-major char[][] with h rows and w columns; it will be filled with '#' for walls and '.' for floors.
-
wallWrap
Changes the outer edge of a char[][] to the wall char, '#'.- Parameters:
map
- A char[][] that stores map data.- Returns:
-
wallWrap
Changes the outer edge of this dungeon to the wall char, '#'.- Returns:
- The modified dungeon, a char[][].
-
generate
Generate a dungeon given a Tileset. If you have your own Tileset gained by parsing your own JSON, use this to generate a dungeon using it. Consider using DungeonBoneGen.wallWrap to surround the edges with walls. Assigns the returned result to a member of this class, 'dungeon'.- Parameters:
ts
- A Tileset; if you don't have one of these available, use a TilesetType enum instead to select a predefined one.h
- Height of the dungeon to generate in chars.w
- Width of the dungeon to generate in chars.- Returns:
- A row-major char[][] with h rows and w columns; it will be filled with '#' for walls and '.' for floors.
-
toString
Provides a string representation of the latest generated dungeon.
-