From a5f1cca981d517f1a1a33989e6d0c341d73d5166 Mon Sep 17 00:00:00 2001 From: Alex Bethel Date: Wed, 12 Jan 2022 11:53:39 -0600 Subject: [PATCH] Floor tile methods --- src/level.rs | 20 +++++++++++++++++++- src/player.rs | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/level.rs b/src/level.rs index 57faedc..5c25999 100644 --- a/src/level.rs +++ b/src/level.rs @@ -30,6 +30,24 @@ pub enum DungeonTile { Downstair, } +impl DungeonTile { + /// Whether this tile is considered a floor tile, for the purposes + /// of rendering walls. + pub fn is_floor(&self) -> bool { + match self { + DungeonTile::Wall => false, + DungeonTile::Hallway => false, + _ => true, + } + } + + /// Whether this tile can be traveled through by normal + /// creatures. + pub fn is_navigable(&self) -> bool { + self.is_floor() || self == &DungeonTile::Hallway + } +} + impl DungeonLevel { /// Creates a new level in a branch that has the given /// configuration. @@ -88,7 +106,7 @@ impl DungeonLevel { (0..LEVEL_SIZE.0 as i32).contains(x) && (0..LEVEL_SIZE.1 as i32).contains(y) }) - .any(|(x, y)| self.tile(x, y) == &DungeonTile::Floor) + .any(|(x, y)| self.tile(x, y).is_floor()) }; if has_floor(&[(0, -1), (0, 1)]) { diff --git a/src/player.rs b/src/player.rs index c3dad9a..eb688a5 100644 --- a/src/player.rs +++ b/src/player.rs @@ -78,7 +78,7 @@ fn possible(ecs: &World, action: &MobAction) -> bool { (&players, &positions) .join() - .all(|(_plr, pos)| map.tile(pos.x + dx, pos.y + dy) != &DungeonTile::Wall) + .all(|(_plr, pos)| map.tile(pos.x + dx, pos.y + dy).is_navigable()) } } }