From f0e715fd3fad342c785a5b4a8637cedfaccb8731 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Wed, 19 Nov 2025 22:20:56 -0500 Subject: dungeon: implement items --- dungeon/src/map.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'dungeon/src/map.rs') 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 -- cgit v1.2.3-freya