wrire up ammo and health in head_ui

This commit is contained in:
2025-04-01 23:47:51 +08:00
parent d9fad37e07
commit 8187eb58a9
3 changed files with 74 additions and 25 deletions

View File

@@ -5,16 +5,29 @@ use bevy::prelude::*;
pub use backpack_ui::BackpackAction;
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, Reflect)]
pub struct BackpackHead {
pub head: usize,
pub health: f32,
pub ammo: f32,
}
impl BackpackHead {
pub fn new(head: usize) -> Self {
Self {
head,
health: 1.0,
ammo: 1.0,
}
}
pub fn damage(&self) -> f32 {
1. - self.health
}
pub fn ammo_used(&self) -> f32 {
1. - self.ammo
}
}
#[derive(Resource, Default)]
@@ -37,6 +50,7 @@ fn setup(mut commands: Commands) {
.map(|i| BackpackHead {
head: i,
health: 1.,
ammo: 1.,
})
.collect(),
});