From df9f47c427cdef3c45eff51090d9734e37528a7d Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 5 Apr 2024 03:49:29 +0200 Subject: [PATCH] fade in from maroon red color when dying/respawning --- src/actor.rs | 7 ++++++- src/effects.rs | 10 +++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index d372f88..8b515ec 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -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, mut scene_spawner: ResMut, mut ew_sfx: EventWriter, + mut ew_effect: EventWriter, ) { 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; } diff --git a/src/effects.rs b/src/effects.rs index c322ee9..fa3e94e 100644 --- a/src/effects.rs +++ b/src/effects.rs @@ -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, ) { 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); } }