From c1893aec742a08371dc9e6dec276ce48433d9e2b Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sat, 29 Jan 2022 22:38:38 +0100 Subject: [PATCH] Bsp: format --- src/main.rs | 1 - src/map.rs | 2 -- src/map_builders/bsp_dungeon.rs | 62 +++++++++++++++++++++++++-------- src/map_builders/mod.rs | 4 +-- 4 files changed, 49 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index 938701f..60aa191 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,6 @@ use crate::particle_system::ParticleSpawnSystem; use crate::state::{RunState, State}; use crate::trigger_system::TriggerSystem; - mod components; mod damage_system; mod gamelog; diff --git a/src/map.rs b/src/map.rs index 907e0a8..86e4274 100644 --- a/src/map.rs +++ b/src/map.rs @@ -4,8 +4,6 @@ use rltk::{Algorithm2D, BaseMap, FontCharType, Point, Rltk, RGB}; use serde::{Deserialize, Serialize}; use specs::prelude::*; - - #[derive(PartialEq, Copy, Clone, Serialize, Deserialize)] pub enum TileType { Wall, diff --git a/src/map_builders/bsp_dungeon.rs b/src/map_builders/bsp_dungeon.rs index 5a998ee..bcbbe84 100644 --- a/src/map_builders/bsp_dungeon.rs +++ b/src/map_builders/bsp_dungeon.rs @@ -1,9 +1,9 @@ use rltk::{Point, RandomNumberGenerator}; -use crate::{Map, Position, SHOW_MAPGEN_VISUALIZER, spawner, TileType, World}; use crate::map_builders::common::apply_room_to_map; use crate::map_builders::MapBuilder; use crate::rect::Rect; +use crate::{spawner, Map, Position, TileType, World, SHOW_MAPGEN_VISUALIZER}; pub struct BspDungeonBuilder { map: Map, @@ -37,7 +37,8 @@ impl BspDungeonBuilder { } fn place_rooms(&mut self, rng: &mut RandomNumberGenerator) { - self.rects.push(Rect::new(2, 2, self.map.width - 5, self.map.height - 5)); + self.rects + .push(Rect::new(2, 2, self.map.width - 5, self.map.height - 5)); let first_room = self.rects[0]; self.add_subrects(first_room); @@ -65,8 +66,10 @@ impl BspDungeonBuilder { let next_room = self.rooms[i + 1]; let start_x = room.x1 + (rng.roll_dice(1, i32::abs(room.x1 - room.x2)) - 1); let start_y = room.y1 + (rng.roll_dice(1, i32::abs(room.y1 - room.y2)) - 1); - let end_x = next_room.x1 + (rng.roll_dice(1, i32::abs(next_room.x1 - next_room.x2)) - 1); - let end_y = next_room.y1 + (rng.roll_dice(1, i32::abs(next_room.y1 - next_room.y2)) - 1); + let end_x = + next_room.x1 + (rng.roll_dice(1, i32::abs(next_room.x1 - next_room.x2)) - 1); + let end_y = + next_room.y1 + (rng.roll_dice(1, i32::abs(next_room.y1 - next_room.y2)) - 1); self.draw_corridor(start_x, start_y, end_x, end_y); self.take_snapshot(); } @@ -74,7 +77,10 @@ impl BspDungeonBuilder { fn place_start(&mut self) { let start = self.rooms[0].center(); - self.starting_position = Position { x: start.0, y: start.1 }; + self.starting_position = Position { + x: start.0, + y: start.1, + }; } fn place_stairs(&mut self) { @@ -89,13 +95,31 @@ impl BspDungeonBuilder { let half_width = i32::max(width / 2, 1); let half_height = i32::max(height / 2, 1); - self.rects.push(Rect::new(rect.x1, rect.y1, half_width, half_height)); - self.rects.push(Rect::new(rect.x1, rect.y1 + half_height, half_width, half_height)); - self.rects.push(Rect::new(rect.x1 + half_width, rect.y1, half_width, half_height)); - self.rects.push(Rect::new(rect.x1 + half_width, rect.y1 + half_height, half_width, half_height)); + self.rects + .push(Rect::new(rect.x1, rect.y1, half_width, half_height)); + self.rects.push(Rect::new( + rect.x1, + rect.y1 + half_height, + half_width, + half_height, + )); + self.rects.push(Rect::new( + rect.x1 + half_width, + rect.y1, + half_width, + half_height, + )); + self.rects.push(Rect::new( + rect.x1 + half_width, + rect.y1 + half_height, + half_width, + half_height, + )); } fn get_random_rect(&mut self, rng: &mut RandomNumberGenerator) -> Rect { - if self.rects.len() == 1 { return self.rects[0]; } + if self.rects.len() == 1 { + return self.rects[0]; + } let idx = (rng.roll_dice(1, self.rects.len() as i32) - 1) as usize; self.rects[idx] } @@ -127,10 +151,18 @@ impl BspDungeonBuilder { for y in expanded.y1..=expanded.y2 { for x in expanded.x1..=expanded.x2 { - if x > self.map.width - 2 { can_build = false; } - if y > self.map.height - 2 { can_build = false; } - if x < 1 { can_build = false; } - if y < 1 { can_build = false; } + if x > self.map.width - 2 { + can_build = false; + } + if y > self.map.height - 2 { + can_build = false; + } + if x < 1 { + can_build = false; + } + if y < 1 { + can_build = false; + } if can_build { let idx = self.map.xy_idx(x, y); if self.map.tiles[idx] != TileType::Wall { @@ -195,4 +227,4 @@ impl MapBuilder for BspDungeonBuilder { self.history.push(snapshot); } } -} \ No newline at end of file +} diff --git a/src/map_builders/mod.rs b/src/map_builders/mod.rs index c351304..3af15f1 100644 --- a/src/map_builders/mod.rs +++ b/src/map_builders/mod.rs @@ -1,12 +1,12 @@ use specs::World; +use crate::map_builders::bsp_dungeon::BspDungeonBuilder; use crate::map_builders::simple_map::SimpleMapBuilder; use crate::{Map, Position}; -use crate::map_builders::bsp_dungeon::BspDungeonBuilder; +mod bsp_dungeon; mod common; mod simple_map; -mod bsp_dungeon; pub trait MapBuilder { fn build_map(&mut self);