aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client.rs6
-rw-r--r--src/server.rs22
2 files changed, 22 insertions, 6 deletions
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::<Channel1, HealthChanged>(
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<HealthRegenTimer>, time: Res<Time>
health_regen_timer.0.tick(time.delta());
}
-fn health_regen(health_regen_timer: Res<HealthRegenTimer>, mut healths: Query<&mut Health>) {
+const HEALTH_REGEN: f32 = 5.;
+fn health_regen(
+ health_regen_timer: Res<HealthRegenTimer>,
+ mut connection_manager: ResMut<ServerConnectionManager>,
+ mut healths: Query<(&PlayerId, &mut Health)>,
+) {
if health_regen_timer.0.just_finished() {
- for mut health in healths.iter_mut() {
- health.0 = (health.0 + 1.).min(MAX_HEALTH);
+ for (target_player, mut health) in healths.iter_mut() {
+ health.0 = (health.0 + HEALTH_REGEN).min(MAX_HEALTH);
+ let _ = connection_manager.send_message_to_target::<Channel1, HealthChanged>(
+ HealthChanged(HealthEvent {
+ target_player: *target_player,
+ health_gained: HEALTH_REGEN,
+ }),
+ NetworkTarget::All,
+ );
}
}
}