diff options
| author | Freya Murphy <freya@freyacat.org> | 2025-11-20 10:07:41 -0500 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2025-11-20 10:07:41 -0500 |
| commit | 65b69d06200d7757bb7f9f9ae3645a7366d08826 (patch) | |
| tree | eb5897af68d7a3a103a5b318b01c2c1d56da44c4 /dungeon/src/entity.rs | |
| parent | dungeon: inventory usage (diff) | |
| download | DungeonCrawl-65b69d06200d7757bb7f9f9ae3645a7366d08826.tar.gz DungeonCrawl-65b69d06200d7757bb7f9f9ae3645a7366d08826.tar.bz2 DungeonCrawl-65b69d06200d7757bb7f9f9ae3645a7366d08826.zip | |
dungeon: entity death
Diffstat (limited to 'dungeon/src/entity.rs')
| -rw-r--r-- | dungeon/src/entity.rs | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/dungeon/src/entity.rs b/dungeon/src/entity.rs index 9af27bd..da807c2 100644 --- a/dungeon/src/entity.rs +++ b/dungeon/src/entity.rs @@ -67,6 +67,18 @@ impl Item { } } } + + /// Returns if this item is a bomb + #[must_use] + pub const fn is_bomb(self) -> bool { + matches!(self, Self::Bomb | Self::LargeBomb) + } + + /// Returns if this item is a potion + #[must_use] + pub const fn is_potion(self) -> bool { + matches!(self, Self::HealthPotion | Self::SpeedPotion) + } } /// Different speed entities can move @@ -308,6 +320,16 @@ impl Entity { _ => None, } } + + /// Returns if this entity is dead + pub const fn is_dead(&self) -> bool { + self.health == 0 && self.kind.initial_health() > 0 + } + + /// Returns if the entity is alive (or does not have/use health) + pub const fn is_alive(&self) -> bool { + !self.is_dead() + } } /// The current "weapon" level we have @@ -520,8 +542,13 @@ impl Dungeon { }; updater.update_entity(&mut self.player.entity); - for enemy in &mut self.entities { - updater.update_entity(enemy); + + for entity in &mut self.entities { + updater.update_entity(entity); + if entity.is_dead() { + // TODO: on entity death + } } + self.entities.retain(Entity::is_alive); } } |