Floor tile methods
This commit is contained in:
parent
6b6a6720ce
commit
a5f1cca981
20
src/level.rs
20
src/level.rs
|
@ -30,6 +30,24 @@ pub enum DungeonTile {
|
||||||
Downstair,
|
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 {
|
impl DungeonLevel {
|
||||||
/// Creates a new level in a branch that has the given
|
/// Creates a new level in a branch that has the given
|
||||||
/// configuration.
|
/// configuration.
|
||||||
|
@ -88,7 +106,7 @@ impl DungeonLevel {
|
||||||
(0..LEVEL_SIZE.0 as i32).contains(x)
|
(0..LEVEL_SIZE.0 as i32).contains(x)
|
||||||
&& (0..LEVEL_SIZE.1 as i32).contains(y)
|
&& (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)]) {
|
if has_floor(&[(0, -1), (0, 1)]) {
|
||||||
|
|
|
@ -78,7 +78,7 @@ fn possible(ecs: &World, action: &MobAction) -> bool {
|
||||||
|
|
||||||
(&players, &positions)
|
(&players, &positions)
|
||||||
.join()
|
.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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue