Skip to content

giraffekey/tatami

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!(),
            }
        }
    }
}

About

A roguelike dungeon generation algorithm

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages