Complete section 4.1 by removing rooms from Maps
This commit is contained in:
parent
feb7988f5f
commit
713c3f6fb8
@ -1,4 +1,3 @@
|
||||
use crate::Rect;
|
||||
use rltk::{Algorithm2D, BaseMap, Point, Rltk, SmallVec, RGB};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use specs::prelude::*;
|
||||
@ -18,7 +17,6 @@ pub enum TileType {
|
||||
#[derive(Default, Serialize, Deserialize, Clone)]
|
||||
pub struct Map {
|
||||
pub tiles: Vec<TileType>,
|
||||
pub rooms: Vec<Rect>,
|
||||
pub width: i32,
|
||||
pub height: i32,
|
||||
pub revealed_tiles: Vec<bool>,
|
||||
@ -63,7 +61,6 @@ impl Map {
|
||||
pub fn new(new_depth: i32) -> Map {
|
||||
Map {
|
||||
tiles: vec![TileType::Wall; MAP_COUNT],
|
||||
rooms: Vec::new(),
|
||||
width: MAP_WIDTH as i32,
|
||||
height: MAP_HEIGHT as i32,
|
||||
revealed_tiles: vec![false; MAP_COUNT],
|
||||
|
@ -7,7 +7,8 @@ use specs::prelude::*;
|
||||
pub struct SimpleMapBuilder {
|
||||
map: Map,
|
||||
starting_position: Position,
|
||||
depth: i32
|
||||
depth: i32,
|
||||
rooms: Vec<Rect>
|
||||
}
|
||||
|
||||
impl MapBuilder for SimpleMapBuilder {
|
||||
@ -16,7 +17,7 @@ impl MapBuilder for SimpleMapBuilder {
|
||||
}
|
||||
|
||||
fn spawn_entities(&mut self, ecs: &mut World) {
|
||||
for room in self.map.rooms.iter().skip(1) {
|
||||
for room in self.rooms.iter().skip(1) {
|
||||
spawner::spawn_room(ecs, room, self.depth);
|
||||
}
|
||||
}
|
||||
@ -35,7 +36,8 @@ impl SimpleMapBuilder {
|
||||
SimpleMapBuilder{
|
||||
map: Map::new(new_depth),
|
||||
starting_position: Position { x: 0, y: 0 },
|
||||
depth: new_depth
|
||||
depth: new_depth,
|
||||
rooms: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,7 +57,7 @@ impl SimpleMapBuilder {
|
||||
let new_room = Rect::new(x, y, w, h);
|
||||
let mut ok = true;
|
||||
|
||||
for other_room in self.map.rooms.iter() {
|
||||
for other_room in self.rooms.iter() {
|
||||
if new_room.intersect(other_room) {
|
||||
ok = false;
|
||||
}
|
||||
@ -64,9 +66,9 @@ impl SimpleMapBuilder {
|
||||
if ok {
|
||||
apply_room_to_map(&mut self.map, &new_room);
|
||||
|
||||
if !self.map.rooms.is_empty() {
|
||||
if !self.rooms.is_empty() {
|
||||
let (new_x, new_y) = new_room.center();
|
||||
let (prev_x, prev_y) = self.map.rooms[self.map.rooms.len() - 1].center();
|
||||
let (prev_x, prev_y) = self.rooms[self.rooms.len() - 1].center();
|
||||
|
||||
if rng.range(0, 2) == 1 {
|
||||
apply_horizontal_tunnel(&mut self.map, prev_x, new_x, prev_y);
|
||||
@ -77,15 +79,15 @@ impl SimpleMapBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
self.map.rooms.push(new_room);
|
||||
self.rooms.push(new_room);
|
||||
}
|
||||
}
|
||||
|
||||
let stairs_position = self.map.rooms[self.map.rooms.len() - 1].center();
|
||||
let stairs_position = self.rooms[self.rooms.len() - 1].center();
|
||||
let stairs_idx = self.map.xy_idx(stairs_position.0, stairs_position.1);
|
||||
self.map.tiles[stairs_idx] = TileType::DownStairs;
|
||||
|
||||
let start_pos = self.map.rooms[0].center();
|
||||
let start_pos = self.rooms[0].center();
|
||||
self.starting_position = Position {
|
||||
x: start_pos.0,
|
||||
y: start_pos.1,
|
||||
|
Loading…
Reference in New Issue
Block a user