From a869a7704e7e26a51e72983f3ad5b5d4156cfcb5 Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 6 Apr 2024 01:11:11 +0200 Subject: [PATCH] implement g-forces and passing out --- src/actor.rs | 50 +++++++++++++++++++++++++++++++++++++++++++------ src/commands.rs | 1 + src/defs.txt | 2 +- src/effects.rs | 32 ++++++++++++++++++++++++++++++- src/hud.rs | 7 ++++--- 5 files changed, 81 insertions(+), 11 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index be5e7eb..ead5c1d 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -18,6 +18,7 @@ impl Plugin for ActorPlugin { update_physics_lifeforms, handle_wants_maxrotation, handle_wants_maxvelocity, + handle_gforce, )); app.add_systems(Update, ( handle_input, @@ -73,6 +74,22 @@ impl Default for HitPoints { } } +#[derive(Component)] +pub struct ExperiencesGForce { + pub gforce: f32, + pub damage_threshold: f32, + pub blackout_threshold: f32, + pub blackout: f32, + pub last_linear_velocity: DVec3, +} +impl Default for ExperiencesGForce { fn default() -> Self { Self { + gforce: 0.0, + damage_threshold: 50.0, + blackout_threshold: 20.0, + blackout: 0.0, + last_linear_velocity: DVec3::splat(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 @@ -312,9 +329,9 @@ fn handle_collisions( mut collision_event_reader: EventReader, mut ew_sfx: EventWriter, q_player: Query<(Entity, Option<&Player>), With>, - mut q_player_lifeform: Query<(&mut LifeForm, &mut Suit, &mut HitPoints), With>, + mut q_player_lifeform: Query<(&mut LifeForm, &mut Suit), With>, ) { - if let (Ok((player, player_maybe)), Ok((mut lifeform, mut suit, mut hp))) = (q_player.get_single(), q_player_lifeform.get_single_mut()) { + if let (Ok((player, player_maybe)), Ok((mut lifeform, mut suit))) = (q_player.get_single(), q_player_lifeform.get_single_mut()) { for CollisionStarted(entity1, entity2) in collision_event_reader.read() { if *entity1 == player || *entity2 == player { ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Crash)); @@ -322,10 +339,6 @@ fn handle_collisions( if player_maybe.is_some() { suit.integrity -= 0.03; - hp.damage += 10.0; - } - else { - hp.damage += 3.0; } } } @@ -423,3 +436,28 @@ fn handle_damage( } } } + +fn handle_gforce( + time: Res