From 61c7cffcef15a4d4d80562c0f4f8abbfab919373 Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 5 Apr 2024 03:31:52 +0200 Subject: [PATCH] implement damage on low oxygen and collisions --- src/actor.rs | 53 +++++++++++++++++++++++++++++++++++++++---------- src/audio.rs | 7 ++++++- src/commands.rs | 1 + src/hud.rs | 30 +++++++++++++++++++++++----- src/world.rs | 4 ++++ 5 files changed, 78 insertions(+), 17 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index 53b1ccd..d372f88 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -22,6 +22,7 @@ impl Plugin for ActorPlugin { app.add_systems(Update, ( handle_input, handle_collisions, + handle_damage, )); app.add_systems(PostUpdate, ( handle_vehicle_enter_exit, @@ -43,17 +44,14 @@ pub struct VehicleEnterExitEvent { #[derive(Component)] pub struct Actor { pub id: String, - pub hp: f32, pub m: f32, // mass pub inside_entity: u32, pub camdistance: f32, } - impl Default for Actor { fn default() -> Self { Self { id: "".to_string(), - hp: 100.0, m: 100.0, inside_entity: NO_RIDE, camdistance: 15.0, @@ -61,6 +59,22 @@ impl Default for Actor { } } +#[derive(Component)] +pub struct HitPoints { + pub current: f32, + pub max: f32, + pub damage: f32, +} +impl Default for HitPoints { + fn default() -> Self { + Self { + current: 100.0, + max: 100.0, + damage: 0.0, + } + } +} + #[derive(Component)] pub struct Player; // Attached to the suit of the player #[derive(Component)] pub struct PlayerDrivesThis; // Attached to the entered vehicle #[derive(Component)] pub struct PlayerCamera; // Attached to the actor to use as point of view @@ -144,10 +158,10 @@ const SUIT_SIMPLE: Suit = Suit { pub fn update_physics_lifeforms( time: Res