implement DamageTypes, different visuals/sounds on death

This commit is contained in:
yuni 2024-04-11 20:46:52 +02:00
parent 2b74b50563
commit eb481edc8e
2 changed files with 47 additions and 9 deletions

View file

@ -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<hud::Log>,
settings: Res<settings::Settings>,
) {
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?
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 {

View file

@ -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));
}
}