Class DungeonBoneGen
java.lang.Object
com.github.yellowstonegames.place.tileset.DungeonBoneGen
Generates a dungeon as a 2D char array using
Sean T. Barrett's Herringbone Wang Tiles method.
-
Field Summary
FieldsModifier and TypeFieldDescriptioncom.github.yellowstonegames.grid.RegionA Region that, aftergenerate(TilesetType, int, int)has been called, will hold the floor cells in its data as "on" cells and walls as "off" cells.com.github.tommyettinger.random.EnhancedRandomThe current random number generator; this can be seeded initially, and can be anyEnhancedRandomcom.github.yellowstonegames.grid.RegionNot recommended for general usage; a Region that is frequently modified by this generator and is kept in a field so this and potentially other classes can avoid allocating new Regions withRegion.remake(Region)or the various refill methods in Region.com.github.yellowstonegames.grid.RegionNot recommended for general usage; a Region that is frequently modified by this generator and is kept in a field so this and potentially other classes can avoid allocating new Regions withRegion.remake(Region)or the various refill methods in Region. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a DungeonBoneGen that uses a default WhiskerRandom, randomly seeded.DungeonBoneGen(com.github.tommyettinger.random.EnhancedRandom random) Constructs a DungeonBoneGen that uses the given EnhancedRandom. -
Method Summary
Modifier and TypeMethodDescriptionchar[][]Generate a dungeon given a Tileset.char[][]generate(TilesetType tt, int w, int h) Generate a dungeon given a TilesetType enum.charget(int x, int y) Gets the char at a given x,y position.char[][]Get the char[][] dungeon that was last returned by generate(), or null if generate() or setDungeon have not been called.intReturns the height, used as the second coordinate in any char[][] in this class.com.github.tommyettinger.random.EnhancedRandomgetRng()Gets the current EnhancedRandom used as a random number generator (RNG).intgetWidth()Returns the width, used as the first coordinate in any char[][] in this class.voidput(char elem, int x, int y) Sets the char at the given x,y position, storing it in this object.voidsetDungeon(char[][] dungeon) Change the stored char[][] dungeon, using x,y indexing.voidsetRng(com.github.tommyettinger.random.EnhancedRandom rng) Sets the current EnhancedRandom used as a random number generator (RNG).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
public com.github.tommyettinger.random.EnhancedRandom rngThe current random number generator; this can be seeded initially, and can be anyEnhancedRandom -
region
public com.github.yellowstonegames.grid.Region regionA Region 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 Region, which can be for various reasons. -
workingRegion
public transient com.github.yellowstonegames.grid.Region workingRegionNot recommended for general usage; a Region that is frequently modified by this generator and is kept in a field so this and potentially other classes can avoid allocating new Regions withRegion.remake(Region)or the various refill methods in Region. -
workingRegionB
public transient com.github.yellowstonegames.grid.Region workingRegionBNot recommended for general usage; a Region that is frequently modified by this generator and is kept in a field so this and potentially other classes can avoid allocating new Regions withRegion.remake(Region)or the various refill methods in Region.
-
-
Constructor Details
-
DungeonBoneGen
public DungeonBoneGen(com.github.tommyettinger.random.EnhancedRandom random) Constructs a DungeonBoneGen that uses the given EnhancedRandom.- Parameters:
random- An EnhancedRandom, such as a WhiskerRandom, to be used during the dungeon generation
-
DungeonBoneGen
public DungeonBoneGen()Constructs a DungeonBoneGen that uses a default WhiskerRandom, randomly seeded.
-
-
Method Details
-
getRng
public com.github.tommyettinger.random.EnhancedRandom getRng()Gets the current EnhancedRandom used as a random number generator (RNG).- Returns:
- the current EnhancedRandom
-
setRng
public void setRng(com.github.tommyettinger.random.EnhancedRandom rng) Sets the current EnhancedRandom used as a random number generator (RNG).- Parameters:
rng- the non-null EnhancedRandom to use
-
getWidth
public int getWidth()Returns the width, used as the first coordinate in any char[][] in this class.- Returns:
- the width of 2D arrays this returns (the first length)
-
getHeight
public int getHeight()Returns the height, used as the second coordinate in any char[][] in this class.- Returns:
- the height of 2D arrays this returns (the second length)
-
getDungeon
public char[][] 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:
- the last 2D char array map this generated, or null if
generate(TilesetType, int, int)orsetDungeon(char[][])have not been called
-
setDungeon
public void setDungeon(char[][] dungeon) Change the stored char[][] dungeon, using x,y indexing.- Parameters:
dungeon- the 2D char array to use; if null, width and height will be invalid
-
get
public char get(int x, int y) Gets the char at a given x,y position.- Parameters:
x- first coordinate; should be at least 0 and less thangetWidth()y- second coordinate; should be at least 0 and less thangetHeight()- Returns:
- the char in the last generated map at the given coordinates
-
put
public void put(char elem, int x, int y) 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- the char to placex- first coordinate; should be at least 0 and less thangetWidth()y- second coordinate; should be at least 0 and less thangetHeight()
-
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
public static char[][] wallWrap(char[][] map) Changes the outer edge of a char[][] to the wall char, '#'.- Parameters:
map- A char[][] that stores map data.- Returns:
-
wallWrap
public char[][] 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.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.
-
toString
-
appendToString
-