The Origami Map crate is a library that provides map generation and manipulation functionalities for Dojo-based games. It offers efficient implementations of various map-related algorithms and data structures commonly used in game development.
The Map crate focuses on providing tools for creating, manipulating, and navigating 2D grid-based maps. Its primary scope includes:
- Map generation algorithms (maze, cave, random walk)
- Pathfinding
- Object distribution on maps
- Hexagonal grid support
The crate is designed to work seamlessly with the Dojo engine and other Origami crates.
- Maze generation using Prim's algorithm
- Cave generation using a cellular automata-like approach
- Random walk map generation
- A* algorithm for finding the shortest path between two points
- Adding corridors to existing maps
- Integrating mazes into existing maps
- Spreading objects uniformly across walkable areas of the map
- Basic operations for hexagonal grids
To add the Origami Map crate as a dependency in your project, you need to modify your Scarb.toml file. Add the following to your [dependencies] section:
[dependencies]
origami_map = { git = "https://github.com/dojoengine/origami" }
Make sure you have dojo installed and configured in your project.
Here are some examples of how to use the Map crate:
use origami_map::map::MapTrait;
let width = 18;
let height = 14;
let order = 0;
let seed = 'SEED';
let maze_map = MapTrait::new_maze(width, height, order, seed);
use origami_map::map::MapTrait;
let width = 18;
let height = 14;
let order = 3;
let seed = 'SEED';
let cave_map = MapTrait::new_cave(width, height, order, seed);
use origami_map::map::MapTrait;
let width = 18;
let height = 14;
let steps = 500;
let seed = 'SEED';
let random_walk_map = MapTrait::new_random_walk(width, height, steps, seed);
use origami_map::map::MapTrait;
let mut map = MapTrait::new_maze(width, height, order, seed);
let position = 1;
let order = 0;
map.open_with_corridor(position, order);
use origami_map::map::MapTrait;
let mut map = MapTrait::new_maze(width, height, order, seed);
let position = 1;
let order = 0;
map.open_with_maze(position, order);
use origami_map::map::MapTrait;
let map = MapTrait::new_maze(width, height, order, seed);
let path = map.search_path(start_position, end_position);
use origami_map::map::MapTrait;
let map = MapTrait::new_maze(width, height, order, seed);
let distribution = map.compute_distribution(10, seed);
Remember to import the necessary traits and types when using the Map crate in your project.