blob: 03c0822c7e13258ca453eaeca53a4444b2a48e6d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
use bevy::prelude::*;
use lightyear::prelude::*;
use serde::*;
#[derive(Component, Message, Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
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);
}
}
|