From 193cb6670addf16bb18b76a1badc00f648150d0b Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Mon, 18 Mar 2024 07:06:13 +0100 Subject: fix: show health regen in ui --- src/client.rs | 6 +++++- src/server.rs | 22 +++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/client.rs b/src/client.rs index 3679b85..277fc2c 100644 --- a/src/client.rs +++ b/src/client.rs @@ -585,7 +585,11 @@ fn health_indicator_spawn( format!("{health_gained_or_lost}"), TextStyle { font_size: 6., - color: Color::RED, + color: if *health_gained < 0. { + Color::RED + } else { + Color::GREEN + }, ..Default::default() }, ) diff --git a/src/server.rs b/src/server.rs index 0b15c5f..55e7ebc 100644 --- a/src/server.rs +++ b/src/server.rs @@ -34,7 +34,7 @@ struct ServerPlugin { pub transport: TransportConfig, } -const HEALTH_REGEN_RATE: f32 = 1.; +const HEALTH_REGEN_RATE: f32 = 5.; #[derive(Resource)] struct HealthRegenTimer(pub Timer); @@ -472,6 +472,7 @@ fn projectile_despawn( if let Some(target_player) = maybe_target_player { if let Some(target_entity) = entity_map.0.get(&target_player.0) { if let Ok(mut health) = healths.get_mut(*target_entity) { + health.0 = (health.0 - projectile.damage).max(0.); let _ = connection_manager .send_message_to_target::( HealthChanged(HealthEvent { @@ -480,7 +481,6 @@ fn projectile_despawn( }), NetworkTarget::All, ); - health.0 = (health.0 - projectile.damage).max(0.); } } } @@ -502,10 +502,22 @@ fn timers_tick(mut health_regen_timer: ResMut, time: Res