tatami-dungeon

Crates.iotatami-dungeon
lib.rstatami-dungeon
version0.1.7
sourcesrc
created_at2024-07-01 01:36:29.595068
updated_at2024-11-15 01:17:33.948859
descriptionA roguelike dungeon generation algorithm
homepage
repositoryhttps://github.com/giraffekey/tatami
max_upload_size
id1288290
size77,377
(giraffekey)

documentation

README

Tatami   License Latest Version Docs

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:

dungeon floor

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!(),
            }
        }
    }
}
Commit count: 18

cargo fmt