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 } 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(); 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), component_observer(|hp: &Hp| hp.current as f32 / hp.max as f32) )); 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), component_observer(|mp: &Mp| mp.current as f32 / mp.max as f32) )); } fn move_player( time: Res