diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-03-15 14:04:17 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-03-15 14:25:01 +0100 |
commit | fdee6aa8cf2c51d5004d914458ff661da366e883 (patch) | |
tree | 0c022856e64e72a00305e28a684e139696c297ab /src/client.rs | |
parent | 1e162629da53373f0e2502014d42c7636412e67e (diff) |
feat: add health/ damage
Diffstat (limited to 'src/client.rs')
-rw-r--r-- | src/client.rs | 20 |
1 files changed, 19 insertions, 1 deletions
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,9 +46,16 @@ 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); + } +} |