From eb481edc8e9d14daa494cb4c91da3492116edcbd Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 11 Apr 2024 20:46:52 +0200 Subject: [PATCH] implement DamageTypes, different visuals/sounds on death --- src/actor.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++-------- src/world.rs | 2 +- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index bbf4962..78073d3 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -33,7 +33,20 @@ impl Plugin for ActorPlugin { } } -#[derive(Event)] pub struct PlayerDiesEvent; +#[derive(Copy, Clone)] +pub enum DamageType { + Unknown, + Mental, + Trauma, + Asphyxiation, + //Poison, + //Radiation, + //Freeze, + //Burn, +} + +#[derive(Event)] pub struct PlayerDiesEvent(pub DamageType); + #[derive(Event)] pub struct VehicleEnterExitEvent { vehicle: Entity, @@ -63,6 +76,7 @@ pub struct HitPoints { pub current: f32, pub max: f32, pub damage: f32, + pub damagetype: DamageType, } impl Default for HitPoints { fn default() -> Self { @@ -70,6 +84,7 @@ impl Default for HitPoints { current: 100.0, max: 100.0, damage: 0.0, + damagetype: DamageType::Unknown, } } } @@ -211,6 +226,7 @@ pub fn update_physics_lifeforms( suit.oxygen = (suit.oxygen - oxygen_drain*d).clamp(0.0, suit.oxygen_max); if suit.oxygen <= 0.0 { hp.damage += 1.0 * d; + hp.damagetype = DamageType::Asphyxiation; } } } @@ -405,7 +421,7 @@ fn handle_player_death( mut log: ResMut, settings: Res, ) { - for _ in er_playerdies.read() { + for death in er_playerdies.read() { if settings.god_mode { return; } @@ -418,11 +434,32 @@ fn handle_player_death( } log.clear(); //cmd.run_system(commands::load_defs); // why is it so complicated to get SystemId? - ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::WakeUp)); - ew_effect.send(effects::SpawnEffectEvent { - class: effects::Effects::FadeIn(Color::MAROON), - duration: 1.0, - }); + + match death.0 { + DamageType::Mental => { + ew_effect.send(effects::SpawnEffectEvent { + class: effects::Effects::FadeIn(Color::BLACK), + duration: 4.0, + }); + } + DamageType::Trauma => { + ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::WakeUp)); + ew_effect.send(effects::SpawnEffectEvent { + class: effects::Effects::FadeIn(Color::MAROON), + duration: 1.0, + }); + } + DamageType::Asphyxiation => { + ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::WakeUp)); + ew_effect.send(effects::SpawnEffectEvent { + class: effects::Effects::FadeIn(Color::BLACK), + duration: 1.0, + }); + } + _ => { + } + } + commands::load_defs(ew_spawn); return; } @@ -439,7 +476,7 @@ fn handle_damage( hp.current -= hp.damage; } if hp.current <= 0.0 { - ew_playerdies.send(PlayerDiesEvent); + ew_playerdies.send(PlayerDiesEvent(hp.damagetype)); } } else { @@ -464,6 +501,7 @@ fn handle_gforce( } if gforce.gforce > gforce.damage_threshold { hp.damage += (gforce.gforce - gforce.damage_threshold).powf(2.0) / 3000.0; + hp.damagetype = DamageType::Trauma; } if gforce.visual_effect > 0.0001 { diff --git a/src/world.rs b/src/world.rs index 9fa50b8..86ecfdc 100644 --- a/src/world.rs +++ b/src/world.rs @@ -446,7 +446,7 @@ fn handle_cheats( lifeform.adrenaline = 1.0; } if key_input.just_pressed(settings.key_cheat_die) { - ew_playerdies.send(actor::PlayerDiesEvent); + ew_playerdies.send(actor::PlayerDiesEvent(actor::DamageType::Trauma)); } }