use bevy::math::vec2; use bevy::prelude::*; use bevy_simple_stat_bars::prelude::*; #[derive(Component)] #[component(storage = "SparseSet")] struct PlayerCharacter; #[derive(Component)] struct Speed(f32); #[derive(Component)] struct Hp { current: i32, max: i32 } #[derive(Component)] struct Mp { current: i32, max: i32 } #[derive(Component)] struct StatBars { pub hp: Entity, pub mp: Entity, } fn spawn_player( mut commands: Commands ) { let player = commands .spawn_bundle( SpriteBundle { sprite: Sprite { custom_size: Some(vec2(32.0, 64.0)), ..Default::default() }, ..Default::default() }, ) .insert(Speed(250.0)) .insert(PlayerCharacter) .insert(Hp { current: 30, max: 30 }) .insert(Mp { current: 12, max: 15 }) .id(); let hp_bar = commands .spawn_bundle(( StatBarColor(Color::GREEN), StatBarEmptyColor(Color::BLACK), StatBarBorder { color: Color::DARK_GRAY, thickness: 3.0 }, StatBarValue(1.0), StatBarSize { full_length: 50.0, thickness: 6.0 }, StatBarSubject(player), StatBarPosition(40.0 * Vec2::Y) )).id(); let mp_bar = commands .spawn_bundle(( StatBarColor(Color::PURPLE), StatBarEmptyColor(Color::BLACK), StatBarBorder { color: Color::DARK_GRAY, thickness: 3.0 }, StatBarValue(12.0 / 15.0), StatBarSize { full_length: 50.0, thickness: 6.0 }, StatBarSubject(player), StatBarPosition(50.0 * Vec2::Y) )).id(); commands.entity(player) .insert(StatBars { hp: hp_bar, mp: mp_bar, }); } fn move_player( time: Res