diff options
Diffstat (limited to 'src/shared/health.rs')
-rw-r--r-- | src/shared/health.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/shared/health.rs b/src/shared/health.rs index b88f19c..f9cc300 100644 --- a/src/shared/health.rs +++ b/src/shared/health.rs @@ -1,4 +1,20 @@ use crate::shared::*; #[derive(Component, Message, Serialize, Deserialize, Clone, Copy, Debug, PartialEq)] -pub struct Health(pub f32); +pub struct Health { + pub health: f32, + pub shield: f32, +} + +impl Health { + pub fn apply_damage(&mut self, damage: f32) { + let shield_damage = damage.min(self.shield); + let health_damage = damage - shield_damage; + self.shield = self.shield - shield_damage; + self.health = (self.health - health_damage).max(0.); + } + + pub fn heal(&mut self, health: f32, max_health: f32) { + self.health = (self.health + health).min(max_health); + } +} |