Crates.io | tatami-dungeon |
lib.rs | tatami-dungeon |
version | 0.1.7 |
source | src |
created_at | 2024-07-01 01:36:29.595068 |
updated_at | 2024-11-15 01:17:33.948859 |
description | A roguelike dungeon generation algorithm |
homepage | |
repository | https://github.com/giraffekey/tatami |
max_upload_size | |
id | 1288290 |
size | 77,377 |
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.
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:
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!(),
}
}
}
}