Floor tile methods

master
Alex Bethel 2022-01-12 11:53:39 -06:00
parent 6b6a6720ce
commit a5f1cca981
2 changed files with 20 additions and 2 deletions

View File

@ -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)]) {

View File

@ -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())
}
}
}