8 releases
0.1.7 | Nov 15, 2024 |
---|---|
0.1.6 | Nov 15, 2024 |
0.1.5 | Aug 12, 2024 |
0.1.2 | Jul 4, 2024 |
#235 in Game dev
265 downloads per month
77KB
1.5K
SLoC
Tatami
Tatami is a roguelike dungeon generation algorithm that creates a multi-floor dungeon layout from a series of randomly oriented, interconnected rectangles.
The library attempts to provide many of the common features found in roguelikes, such as stairs, teleporters, items, enemies and traps. It is intended to be used as a base upon which a fully featured game can be built on.
You can find a tutorial on how to use it here.
Examples
Output an image of a generated dungeon
let dungeon = Dungeon::generate();
dungeon.output_as_image("dungeon.png", "images/spritesheet.png", 8);
dungeon.output_floor_as_image(0, "floor-1.png", "images/spritesheet.png", 8);
Example output:
Generate a dungeon for your game
let dungeon = Dungeon::generate();
for floor in &dungeon.floors {
for (x, col) in floor.tiles.iter().enumerate() {
for (y, tile) in col.iter().enumerate() {
match tile {
Tile::Floor => // Draw floor tile at (x, y)
Tile::Wall => // Draw wall tile at (x, y)
}
}
}
for room in &floor.rooms {
for item in &room.items {
match item.rarity {
1..=20 => // Spawn common item
21..=40 => // Spawn uncommon item
41..=60 => // Spawn rare item
61..=80 => // Spawn epic item
81..=100 => // Spawn legendary item
_ => unreachable!(),
}
}
for enemy in &room.enemies {
match enemy.difficulty {
1..=20 => // Spawn common enemy
21..=40 => // Spawn uncommon enemy
41..=60 => // Spawn rare enemy
61..=80 => // Spawn epic enemy
81..=100 => // Spawn legendary enemy
_ => unreachable!(),
}
}
for trap in &room.traps {
match trap.difficulty {
1..=20 => // Spawn common trap
21..=40 => // Spawn uncommon trap
41..=60 => // Spawn rare trap
61..=80 => // Spawn epic trap
81..=100 => // Spawn legendary trap
_ => unreachable!(),
}
}
}
}
Dependencies
~6MB
~110K SLoC