Crate bevy_knossos

Source
Expand description

§Overview

A simple library for generating mazes with some basic routines for rendering and saving mazes to files.

§Installation

Run the following Cargo command in your project directory:

cargo add bevy_knossos

Or add the following line to your Cargo.toml:

[dependencies]
bevy_knossos = "0.7.0"

§Usage

This crate is designed to be super easy to use. Here are some usage examples of how to generate, display and save mazes:

§Generate with Default Parameters

use bevy_knossos::maze::*;

let maze = OrthogonalMazeBuilder::new().build();

§Generate with Custom Parameters

use bevy_knossos::maze::*;

let maze = OrthogonalMazeBuilder::new()
 .height(10)
 .width(10)
 .algorithm(Box::new(GrowingTree::new(Method::Random)))
 .build();

Read more about maze builder API

§Display Maze

use bevy_knossos::maze::*;

let maze = OrthogonalMazeBuilder::new().build().unwrap();
println!("{}", &maze);

§Save to File

use bevy_knossos::maze::*;

let maze = OrthogonalMazeBuilder::new().build().unwrap();

// Save as ASCII text
maze.save("output/maze.txt", AsciiNarrow).unwrap();
// Save as a game map
maze.save("output/maze_game_map.txt", GameMap::new().span(3)).unwrap();
// Save as a PNG image
maze.save("output/maze.png", Image::new().wall(10).passage(30)).unwrap();

Read more about maze formatters

§Seeding for Deterministic Mazes

By default, each generated maze is randomized, producing a different layout every time. However, you can use a seed value to ensure that the same maze is generated consistently across runs. This is useful for debugging, testing, or sharing the exact same maze with others.

use bevy_knossos::maze::*;

// Generate a maze with a fixed seed
let maze = OrthogonalMazeBuilder::new().seed(Some(40)).build();

Passing None as the seed (or omitting the .seed() method) will result in a random maze each time.

§Algorithms

You can find 10 different algorithms supported by this crate. Each of them has its own pros and cons: some of them are impressively efficient, some of them are slower but generate splendid mazes that look hard to puzzle out, and others are extremely flexible and customizable. Do give each of them a shot and find the best one that suits you:

Modules§

maze
Maze representations, builders, formatters, and supported algorithms for generating mazes
pathfind
Module containing all necessary tooling to pathfind between Start and Goal

Structs§

CellSize
Maze cell size
CoordsComponent
Auxiliary Bevy component to hold Coords
Goal
Auxiliary Bevy component that holds the Goal Coords of Pathfinding
KnossosPlugin
Plugin registering Knossos Reflect Components and Resources
Start
Auxiliary Bevy component that holds the Start Coords of Pathfinding

Enums§

Color
An enumeration over supported color types for filling a maze image with colors

Type Aliases§

Coords
Basic coords type