mod backpack_ui; use crate::{GameState, heads_ui::HEAD_COUNT}; 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 } } #[derive(Resource, Default)] pub struct Backpack { pub heads: Vec, } #[derive(Event)] pub struct BackbackSwapEvent(pub usize); pub fn plugin(app: &mut App) { app.add_plugins(backpack_ui::plugin); app.add_systems(OnEnter(GameState::Playing), setup); } fn setup(mut commands: Commands) { commands.insert_resource(Backpack { heads: (0usize..HEAD_COUNT) .map(|i| BackpackHead { head: i, health: 1., ammo: 1., }) .collect(), }); }