WIP: 2.10

This commit is contained in:
2022-01-27 19:42:51 +01:00
parent ecbecc1a58
commit f2f4c40c28
7 changed files with 96 additions and 82 deletions

View File

@@ -65,6 +65,27 @@ impl Map {
}
}
fn is_exit_valid(&self, x: i32, y: i32) -> bool {
if x < 1 || x > self.width - 1 || y < 1 || y > self.height - 1 {
return false;
}
let idx = self.xy_idx(x, y);
!self.blocked[idx]
}
pub fn populate_blocked(&mut self) {
for (i, tile) in self.tiles.iter_mut().enumerate() {
self.blocked[i] = *tile == TileType::Wall;
}
}
pub fn clear_content_index(&mut self) {
for content in self.tile_content.iter_mut() {
content.clear();
}
}
pub fn new_map_rooms_and_corridors() -> Map {
let mut map = Map {
tiles: vec![TileType::Wall; MAP_COUNT],
@@ -116,37 +137,11 @@ impl Map {
map
}
fn is_exit_valid(&self, x: i32, y: i32) -> bool {
if x < 1 || x > self.width - 1 || y < 1 || y > self.height - 1 {
return false;
}
let idx = self.xy_idx(x, y);
!self.blocked[idx]
}
pub fn populate_blocked(&mut self) {
for (i, tile) in self.tiles.iter_mut().enumerate() {
self.blocked[i] = *tile == TileType::Wall;
}
}
pub fn clear_content_index(&mut self) {
for content in self.tile_content.iter_mut() {
content.clear();
}
}
}
impl Algorithm2D for Map {
fn dimensions(&self) -> rltk::Point {
Point::new(self.width, self.height)
}
}
impl BaseMap for Map {
fn is_opaque(&self, idx: usize) -> bool {
self.tiles[idx as usize] == TileType::Wall
self.tiles[idx] == TileType::Wall
}
fn get_pathing_distance(&self, idx1: usize, idx2: usize) -> f32 {
@@ -192,6 +187,12 @@ impl BaseMap for Map {
}
}
impl Algorithm2D for Map {
fn dimensions(&self) -> rltk::Point {
Point::new(self.width, self.height)
}
}
pub fn draw_map(ecs: &World, ctx: &mut Rltk) {
let map = ecs.fetch::<Map>();
@@ -203,12 +204,12 @@ pub fn draw_map(ecs: &World, ctx: &mut Rltk) {
let mut fg;
match tile {
TileType::Floor => {
fg = RGB::from_f32(0.5, 0.5, 0.5);
fg = RGB::from_f32(0.0, 0.5, 0.5);
glyph = rltk::to_cp437('.');
}
TileType::Wall => {
fg = RGB::from_f32(0.0, 1.0, 0.0);
fg = RGB::from_f32(0., 1.0, 0.);
glyph = rltk::to_cp437('#');
}
}
@@ -219,7 +220,7 @@ pub fn draw_map(ecs: &World, ctx: &mut Rltk) {
}
x += 1;
if x > 79 {
if x > MAP_WIDTH as i32 - 1 {
x = 0;
y += 1;
}