implement DamageTypes, different visuals/sounds on death
This commit is contained in:
parent
2b74b50563
commit
eb481edc8e
54
src/actor.rs
54
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)]
|
#[derive(Event)]
|
||||||
pub struct VehicleEnterExitEvent {
|
pub struct VehicleEnterExitEvent {
|
||||||
vehicle: Entity,
|
vehicle: Entity,
|
||||||
|
@ -63,6 +76,7 @@ pub struct HitPoints {
|
||||||
pub current: f32,
|
pub current: f32,
|
||||||
pub max: f32,
|
pub max: f32,
|
||||||
pub damage: f32,
|
pub damage: f32,
|
||||||
|
pub damagetype: DamageType,
|
||||||
}
|
}
|
||||||
impl Default for HitPoints {
|
impl Default for HitPoints {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
|
@ -70,6 +84,7 @@ impl Default for HitPoints {
|
||||||
current: 100.0,
|
current: 100.0,
|
||||||
max: 100.0,
|
max: 100.0,
|
||||||
damage: 0.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);
|
suit.oxygen = (suit.oxygen - oxygen_drain*d).clamp(0.0, suit.oxygen_max);
|
||||||
if suit.oxygen <= 0.0 {
|
if suit.oxygen <= 0.0 {
|
||||||
hp.damage += 1.0 * d;
|
hp.damage += 1.0 * d;
|
||||||
|
hp.damagetype = DamageType::Asphyxiation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -405,7 +421,7 @@ fn handle_player_death(
|
||||||
mut log: ResMut<hud::Log>,
|
mut log: ResMut<hud::Log>,
|
||||||
settings: Res<settings::Settings>,
|
settings: Res<settings::Settings>,
|
||||||
) {
|
) {
|
||||||
for _ in er_playerdies.read() {
|
for death in er_playerdies.read() {
|
||||||
if settings.god_mode {
|
if settings.god_mode {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -418,11 +434,32 @@ fn handle_player_death(
|
||||||
}
|
}
|
||||||
log.clear();
|
log.clear();
|
||||||
//cmd.run_system(commands::load_defs); // why is it so complicated to get SystemId?
|
//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 {
|
match death.0 {
|
||||||
class: effects::Effects::FadeIn(Color::MAROON),
|
DamageType::Mental => {
|
||||||
duration: 1.0,
|
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);
|
commands::load_defs(ew_spawn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -439,7 +476,7 @@ fn handle_damage(
|
||||||
hp.current -= hp.damage;
|
hp.current -= hp.damage;
|
||||||
}
|
}
|
||||||
if hp.current <= 0.0 {
|
if hp.current <= 0.0 {
|
||||||
ew_playerdies.send(PlayerDiesEvent);
|
ew_playerdies.send(PlayerDiesEvent(hp.damagetype));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -464,6 +501,7 @@ fn handle_gforce(
|
||||||
}
|
}
|
||||||
if gforce.gforce > gforce.damage_threshold {
|
if gforce.gforce > gforce.damage_threshold {
|
||||||
hp.damage += (gforce.gforce - gforce.damage_threshold).powf(2.0) / 3000.0;
|
hp.damage += (gforce.gforce - gforce.damage_threshold).powf(2.0) / 3000.0;
|
||||||
|
hp.damagetype = DamageType::Trauma;
|
||||||
}
|
}
|
||||||
|
|
||||||
if gforce.visual_effect > 0.0001 {
|
if gforce.visual_effect > 0.0001 {
|
||||||
|
|
|
@ -446,7 +446,7 @@ fn handle_cheats(
|
||||||
lifeform.adrenaline = 1.0;
|
lifeform.adrenaline = 1.0;
|
||||||
}
|
}
|
||||||
if key_input.just_pressed(settings.key_cheat_die) {
|
if key_input.just_pressed(settings.key_cheat_die) {
|
||||||
ew_playerdies.send(actor::PlayerDiesEvent);
|
ew_playerdies.send(actor::PlayerDiesEvent(actor::DamageType::Trauma));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue