Add exit point to GridBuilder
and change parameters to usize
.
This commit is contained in:
parent
d33f26d31c
commit
68e5143386
28
src/map.rs
28
src/map.rs
|
@ -125,18 +125,18 @@ pub struct MapBundle {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GridBuilder {
|
pub struct GridBuilder {
|
||||||
width_in_rooms: u32,
|
width_in_rooms: usize,
|
||||||
height_in_rooms: u32,
|
height_in_rooms: usize,
|
||||||
room_width: u32,
|
room_width: usize,
|
||||||
room_height: u32,
|
room_height: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GridBuilder {
|
impl GridBuilder {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
width_in_rooms: u32,
|
width_in_rooms: usize,
|
||||||
height_in_rooms: u32,
|
height_in_rooms: usize,
|
||||||
room_width: u32,
|
room_width: usize,
|
||||||
room_height: u32,
|
room_height: usize,
|
||||||
) -> Box<GridBuilder> {
|
) -> Box<GridBuilder> {
|
||||||
Box::new(GridBuilder {
|
Box::new(GridBuilder {
|
||||||
width_in_rooms,
|
width_in_rooms,
|
||||||
|
@ -153,6 +153,8 @@ impl MapFilter for GridBuilder {
|
||||||
let mut generator = RbGenerator::new(None);
|
let mut generator = RbGenerator::new(None);
|
||||||
let maze = generator.generate(self.width_in_rooms as i32, self.height_in_rooms as i32);
|
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 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 y in 0..self.height_in_rooms {
|
||||||
for x in 0..self.width_in_rooms {
|
for x in 0..self.width_in_rooms {
|
||||||
let x_offset = x * (self.room_width + 1);
|
let x_offset = x * (self.room_width + 1);
|
||||||
|
@ -166,8 +168,6 @@ impl MapFilter for GridBuilder {
|
||||||
map.add_room(room);
|
map.add_room(room);
|
||||||
let coords = maze_generator::prelude::Coordinates::new(x as i32, y as i32);
|
let coords = maze_generator::prelude::Coordinates::new(x as i32, y as i32);
|
||||||
if let Some(field) = maze.get_field(&coords) {
|
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::*;
|
use maze_generator::prelude::Direction::*;
|
||||||
if field.has_passage(&North) {
|
if field.has_passage(&North) {
|
||||||
let x = x_offset + half_width;
|
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
|
map
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user