fade in from maroon red color when dying/respawning

This commit is contained in:
yuni 2024-04-05 03:49:29 +02:00
parent 61c7cffcef
commit df9f47c427
2 changed files with 11 additions and 6 deletions

View file

@ -2,7 +2,7 @@ use bevy::prelude::*;
use bevy_xpbd_3d::prelude::*;
use bevy::scene::SceneInstance;
use bevy::math::DVec3;
use crate::{actor, audio, chat, commands, nature, settings, world};
use crate::{actor, audio, chat, commands, effects, nature, settings, world};
pub const ENGINE_SPEED_FACTOR: f32 = 30.0;
const MIN_INTERACT_DISTANCE: f32 = 30.0;
@ -379,6 +379,7 @@ fn handle_player_death(
ew_spawn: EventWriter<commands::SpawnEvent>,
mut scene_spawner: ResMut<SceneSpawner>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
mut ew_effect: EventWriter<effects::SpawnEffectEvent>,
) {
for _ in er_playerdies.read() {
for entity in &q_noscenes {
@ -390,6 +391,10 @@ fn handle_player_death(
}
//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,
});
commands::load_defs(ew_spawn);
return;
}

View file

@ -15,7 +15,7 @@ impl Plugin for EffectsPlugin {
#[derive(Clone)]
pub enum Effects {
FadeIn,
FadeIn(Color),
}
#[derive(Component)] pub struct FadeBlack;
@ -36,7 +36,7 @@ pub fn setup(
mut ew_effect: EventWriter<SpawnEffectEvent>,
) {
if !settings.dev_mode {
ew_effect.send(SpawnEffectEvent { class: Effects::FadeIn, duration: 4.0 });
ew_effect.send(SpawnEffectEvent { class: Effects::FadeIn(Color::BLACK), duration: 4.0 });
}
}
@ -48,7 +48,7 @@ pub fn spawn_effects(
let now = time.elapsed_seconds_f64();
for effect in er_effect.read() {
match effect.class {
Effects::FadeIn => {
Effects::FadeIn(color) => {
commands.spawn((
Effect {
class: effect.class.clone(),
@ -65,7 +65,7 @@ pub fn spawn_effects(
left: Val::Px(0.0),
..default()
},
background_color: Color::rgba(0.0, 0.0, 0.0, 1.0).into(),
background_color: color.into(),
..default()
},
));
@ -87,6 +87,6 @@ pub fn update_fadeblack(
continue;
}
let alpha = (1.3 - 1.3 * (now - effect.start_time) / effect.duration).clamp(0.0, 1.0);
bgcolor.0 = Color::rgba(0.0, 0.0, 0.0, alpha as f32);
bgcolor.0.set_a(alpha as f32);
}
}