summaryrefslogtreecommitdiff
path: root/dungeon/src/map.rs
diff options
context:
space:
mode:
Diffstat (limited to 'dungeon/src/map.rs')
-rw-r--r--dungeon/src/map.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/dungeon/src/map.rs b/dungeon/src/map.rs
index 0d05b73..7403e31 100644
--- a/dungeon/src/map.rs
+++ b/dungeon/src/map.rs
@@ -53,7 +53,11 @@ impl Tile {
matches!(self, Self::Room | Self::Hallway | Self::Stairs)
}
- // Index by u16
+ /// Returns if the tile is blast resistant
+ #[must_use]
+ pub const fn blast_resistant(self) -> bool {
+ matches!(self, Self::Stairs)
+ }
}
impl Display for Tile {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -164,6 +168,26 @@ impl Floor {
break pos;
}
}
+
+ /// Blows up a set number of tiles with a given radius
+ pub fn explode(&mut self, center_pos: Pos, radius: i16) {
+ let tiles_mut = self.tiles_mut();
+ for x_off in -radius..=radius {
+ for y_off in -radius..=radius {
+ let Some(x) = center_pos.x().checked_add_signed(x_off) else {
+ continue;
+ };
+ let Some(y) = center_pos.y().checked_add_signed(y_off) else {
+ continue;
+ };
+ let Some(pos) = Pos::new(x, y) else { continue };
+ if pos.is_border() || tiles_mut[pos.idx()].blast_resistant() {
+ continue;
+ }
+ tiles_mut[pos.idx()] = Tile::Room;
+ }
+ }
+ }
}
impl Display for Floor {
/// Display the floor as a string for debugging