From 68e5143386f4dcae035e04f38a83a1fb17a75de0 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Thu, 26 Aug 2021 16:00:56 -0500 Subject: [PATCH] Add exit point to `GridBuilder` and change parameters to `usize`. --- src/map.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/map.rs b/src/map.rs index 6d7afe4..018c2e2 100644 --- a/src/map.rs +++ b/src/map.rs @@ -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 { 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 } }