From fdee6aa8cf2c51d5004d914458ff661da366e883 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Fri, 15 Mar 2024 14:04:17 +0100 Subject: feat: add health/ damage --- src/client.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/client.rs') diff --git a/src/client.rs b/src/client.rs index a5a7845..174d615 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,5 +1,6 @@ use crate::client::network::*; use crate::protocol::*; +use crate::shared::health::*; use crate::shared::imperative::*; use crate::shared::projectile::*; use crate::shared::*; @@ -45,8 +46,15 @@ impl Plugin for ClientPlugin { transport: self.transport.clone(), }) .add_systems(Startup, setup) - .add_systems(Update, (render_players, render_projectiles)) .add_systems(Update, (move_players, move_projectiles)) + .add_systems( + Update, + ( + render_players.after(move_players), + render_projectiles.after(move_projectiles), + render_health, + ), + ) .add_systems( FixedPreUpdate, buffer_input.in_set(InputSystemSet::BufferInputs), @@ -214,3 +222,13 @@ fn player_position( } None } + +const HEALTH_OFFSET: f32 = 4.; + +fn render_health(players: Query<(&Health, &PlayerPosition)>, mut gizmos: Gizmos) { + for (health, position) in players.iter() { + let start = position.0 + Vec2::new(-PLAYER_RADIUS, PLAYER_RADIUS + HEALTH_OFFSET); + let end = position.0 + Vec2::new(PLAYER_RADIUS, PLAYER_RADIUS + HEALTH_OFFSET); + gizmos.line_2d(start, start.lerp(end, health.0 / MAX_HEALTH), Color::RED); + } +} -- cgit v1.2.3