Add exit point to GridBuilder and change parameters to usize.

This commit is contained in:
Nolan Darilek 2021-08-26 16:00:56 -05:00
parent d33f26d31c
commit 68e5143386

View File

@ -125,18 +125,18 @@ pub struct MapBundle {
}
pub struct GridBuilder {
width_in_rooms: u32,
height_in_rooms: u32,
room_width: u32,
room_height: u32,
width_in_rooms: usize,
height_in_rooms: usize,
room_width: usize,
room_height: usize,
}
impl GridBuilder {
pub fn new(
width_in_rooms: u32,
height_in_rooms: u32,
room_width: u32,
room_height: u32,
width_in_rooms: usize,
height_in_rooms: usize,
room_width: usize,
room_height: usize,
) -> Box<GridBuilder> {
Box::new(GridBuilder {
width_in_rooms,
@ -153,6 +153,8 @@ impl MapFilter for GridBuilder {
let mut generator = RbGenerator::new(None);
let maze = generator.generate(self.width_in_rooms as i32, self.height_in_rooms as i32);
let total_height = (self.room_height + 1) * self.height_in_rooms + 1;
let half_width = self.room_width / 2;
let half_height = self.room_height / 2;
for y in 0..self.height_in_rooms {
for x in 0..self.width_in_rooms {
let x_offset = x * (self.room_width + 1);
@ -166,8 +168,6 @@ impl MapFilter for GridBuilder {
map.add_room(room);
let coords = maze_generator::prelude::Coordinates::new(x as i32, y as i32);
if let Some(field) = maze.get_field(&coords) {
let half_width = self.room_width / 2;
let half_height = self.room_height / 2;
use maze_generator::prelude::Direction::*;
if field.has_passage(&North) {
let x = x_offset + half_width;
@ -192,6 +192,14 @@ impl MapFilter for GridBuilder {
}
}
}
map.starting_point = Some(mapgen::geometry::Point::new(
maze.start.x as usize + 1,
maze.start.y as usize + 1,
));
map.exit_point = Some(mapgen::geometry::Point::new(
(maze.goal.x as usize) * self.room_width + half_width,
(maze.goal.y as usize) * self.room_height + half_height,
));
map
}
}