pub struct GridMap { /* private fields */ }
Expand description
A map with grid coordinates
Examples
// Make a map that's 25x25 cells in size.
let map = GridMap::new(25, 25);
Implementations§
source§impl GridMap
impl GridMap
sourcepub fn new(xmax: usize, ymax: usize) -> GridMap
pub fn new(xmax: usize, ymax: usize) -> GridMap
Make a new GridMap
Examples
// Make a map that's 25x25 cells in size.
let map = GridMap::new(25, 25);
sourcepub fn get_limits(&self) -> (usize, usize)
pub fn get_limits(&self) -> (usize, usize)
Returns size of map in (x, y) format
Examples
let limits = map.get_limits();
assert_eq!(limits, (25, 25));
sourcepub fn get_cell_ref(&self, x: usize, y: usize) -> &GridCell
pub fn get_cell_ref(&self, x: usize, y: usize) -> &GridCell
Get a reference to a GridCell at coordinate.
sourcepub fn place_entrance(&mut self, (x, y): (usize, usize))
pub fn place_entrance(&mut self, (x, y): (usize, usize))
Set the entrance at a particular location. The cell at this location will be marked as having the entrance area type. Typically this will be coloured differently on a map.
sourcepub fn place_entrance_near(
&mut self,
(x, y): (usize, usize)
) -> Result<(), &'static str>
pub fn place_entrance_near(
&mut self,
(x, y): (usize, usize)
) -> Result<(), &'static str>
Similar to place entrance, however it starts with the coordinates and finds the nearest spot that is already a “room”. This allows entrances to be placed in non-deterministic generators, such as caves.
sourcepub fn place_room_dimensions(
&mut self,
(x, y): (usize, usize),
(w, h): (isize, isize)
)
pub fn place_room_dimensions(
&mut self,
(x, y): (usize, usize),
(w, h): (isize, isize)
)
Place a room by setting the origin and width/height
Arguments:
- (x, y) -> The origin of the room. This will be a corner.
- (w, h) -> Width/Height of the room. Note, they’re isize because you can specify the w/h to be left OR right of the origin and up OR down, respectively.
sourcepub fn place_hallway(
&mut self,
(x0, y0): (usize, usize),
(x1, y1): (usize, usize),
route: RouteMethod
)
pub fn place_hallway(
&mut self,
(x0, y0): (usize, usize),
(x1, y1): (usize, usize),
route: RouteMethod
)
Place a hallway between two points
sourcepub fn generate_random_cells(&mut self, limit: i64)
pub fn generate_random_cells(&mut self, limit: i64)
Generate random cells with a biasing towards more/less rooms. Limit is a value between 1 and 100. This limit sets the chance that the cells are a room. Higher limit means fewer rooms.
pub fn generate_annealed_random_cells(&mut self)
sourcepub fn place_random_room(&mut self, scale: usize, connect: bool)
pub fn place_random_room(&mut self, scale: usize, connect: bool)
Place a randomly sized room of up to scale length or width.