From 82c4358ac73e4c29e1c194ae8e8ae1b631cbb6dc Mon Sep 17 00:00:00 2001 From: Alex Page Date: Tue, 1 Feb 2022 03:01:21 -0500 Subject: [PATCH] Allow monsters to break blocks --- src/resources/map.rs | 5 +++++ src/systems/monster_ai_system.rs | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/resources/map.rs b/src/resources/map.rs index 1d753f9..b9bb6a2 100644 --- a/src/resources/map.rs +++ b/src/resources/map.rs @@ -236,6 +236,11 @@ impl Map { self.tiles[self.point2d_to_index(point)] } + pub fn get_tile_at_mut(&mut self, point: Point) -> &mut TileType { + let index = self.point2d_to_index(point); + &mut self.tiles[index] + } + pub fn set_tile_at(&mut self, point: Point, tile: TileType) { let index = self.point2d_to_index(point); self.tiles[index] = tile; diff --git a/src/systems/monster_ai_system.rs b/src/systems/monster_ai_system.rs index d2147a6..231f8be 100644 --- a/src/systems/monster_ai_system.rs +++ b/src/systems/monster_ai_system.rs @@ -88,10 +88,12 @@ impl<'a> System<'a> for MonsterAiSystem { let _ = entities.delete(*entity); } } else { - match map.get_tile_at(destination) { + let tile = map.get_tile_at_mut(destination); + match tile { TileType::Wall => {} TileType::Block => { // TODO: Sound + *tile = TileType::Floor; let _ = entities.delete(*entity); } _ => {