ammo system

* heads have abilities
* health and ammo shows in ui
This commit is contained in:
2025-04-02 01:35:02 +08:00
parent 8187eb58a9
commit 01e6e944d3
13 changed files with 360 additions and 234 deletions

View File

@@ -1,38 +1,18 @@
mod backpack_ui;
mod ui_head_state;
use crate::{GameState, heads_ui::HEAD_COUNT};
use crate::{
GameState,
active_heads::{HEAD_COUNT, HeadState},
};
use bevy::prelude::*;
pub use backpack_ui::BackpackAction;
#[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
}
}
pub use ui_head_state::UiHeadState;
#[derive(Resource, Default)]
pub struct Backpack {
pub heads: Vec<BackpackHead>,
pub heads: Vec<HeadState>,
}
#[derive(Event)]
@@ -47,11 +27,7 @@ pub fn plugin(app: &mut App) {
fn setup(mut commands: Commands) {
commands.insert_resource(Backpack {
heads: (0usize..HEAD_COUNT)
.map(|i| BackpackHead {
head: i,
health: 1.,
ammo: 1.,
})
.map(|i| HeadState::new(i, 10))
.collect(),
});
}