From 4f71f833fbf270663c6c80ce191ac624f567aaff Mon Sep 17 00:00:00 2001 From: yuni Date: Mon, 16 Sep 2024 00:45:20 +0200 Subject: [PATCH] particles: grow now over time --- src/camera.rs | 11 +++++++++++ src/game.rs | 7 ------- src/visual.rs | 55 ++++++++++++++++++++++++++++++++++++++++++++------- src/world.rs | 16 +++++++++++++++ 4 files changed, 75 insertions(+), 14 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index c29a154..6cc0bb2 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -447,6 +447,7 @@ pub fn apply_input_to_player( ), (With, Without), >, + mut ew_effect: EventWriter, ) { if settings.map_active || !settings.in_control() { return; @@ -564,6 +565,16 @@ pub fn apply_input_to_player( engine.current_warmup = (engine.current_warmup + dt / engine.warmup_seconds).clamp(0.0, 1.0); play_thruster_sound = true; + + // Visual effect + if acceleration_total.length_squared() > 1e-4 { + let thruster_direction = acceleration_total.normalize(); + let thruster_v = v.0 - 10.0 * thruster_direction; + ew_effect.send(visual::SpawnEffectEvent { + duration: 1.0, + class: visual::Effects::ThrusterParticle(pos.clone(), LinearVelocity::from(thruster_v)), + }); + } } else { engine.current_warmup = (engine.current_warmup - dt / engine.warmup_seconds).clamp(0.0, 1.0); diff --git a/src/game.rs b/src/game.rs index 824fc58..f75089d 100644 --- a/src/game.rs +++ b/src/game.rs @@ -476,16 +476,9 @@ fn debug( // >, mut achievement_tracker: ResMut, vars: Res, - q_playercam: Query<(&Position, &LinearVelocity), With>, - mut ew_effect: EventWriter, // materials: Query<(Entity, Option<&Name>, &Handle)>, ) { if settings.dev_mode && keyboard_input.just_pressed(KeyCode::KeyP) { - let (pos, v) = q_playercam.get_single().unwrap(); - ew_effect.send(visual::SpawnEffectEvent { - duration: 0.0, - class: visual::Effects::ThrusterParticle(pos.clone(), v.clone()), - }); // for (entity, _name, mesh) in &materials { // dbg!(mesh); diff --git a/src/visual.rs b/src/visual.rs index 4841d63..2eec69f 100644 --- a/src/visual.rs +++ b/src/visual.rs @@ -27,6 +27,7 @@ impl Plugin for VisualPlugin { app.add_systems(Update, spawn_effects); app.add_systems(Update, update_fadein); app.add_systems(Update, update_fadeout); + app.add_systems(Update, update_grow); app.add_systems(Update, play_animations); // Blackout disabled for now //app.add_systems(Update, update_blackout); @@ -45,9 +46,18 @@ pub enum Effects { //#[derive(Component)] pub struct BlackOutOverlay; #[derive(Component)] -pub struct FadeIn; +pub struct FadeInSprite; #[derive(Component)] -pub struct FadeOut; +pub struct FadeOutSprite; +#[derive(Component)] +pub struct FadeOut3DObject; +#[derive(Component)] +pub struct Grow3DObject { + pub start_time: f64, + pub duration: f64, + pub scale_start: f32, + pub scale_end: f32, +} #[derive(Component)] pub struct Effect { pub class: Effects, @@ -126,7 +136,7 @@ pub fn spawn_effects( duration: effect.duration, start_time: now, }, - FadeIn, + FadeInSprite, NodeBundle { style: style_fullscreen(), background_color: color.into(), @@ -141,7 +151,7 @@ pub fn spawn_effects( duration: effect.duration, start_time: now, }, - FadeOut, + FadeOutSprite, NodeBundle { style: style_fullscreen(), background_color: color.with_alpha(0.0).into(), @@ -156,10 +166,17 @@ pub fn spawn_effects( bevy::pbr::NotShadowCaster, pos, v, + Grow3DObject { + start_time: now, + duration: effect.duration, + scale_start: 1.0, + scale_end: 10.0, + }, + world::DespawnAt(now + effect.duration * 3.0), world::DespawnOnPlayerDeath, actor::WantsToLookAt(cmd::ID_SPECIAL_PLAYERCAM.into()), PbrBundle { - mesh: meshes.add(Mesh::from(Rectangle::new(1.0, 1.0))), + mesh: meshes.add(Mesh::from(Rectangle::new(0.2, 0.2))), material: materials.add(StandardMaterial { base_color_texture: Some(texture), perceptual_roughness: 1.0, @@ -176,7 +193,7 @@ pub fn spawn_effects( pub fn update_fadein( mut commands: Commands, - mut q_effect: Query<(Entity, &Effect, &mut BackgroundColor), With>, + mut q_effect: Query<(Entity, &Effect, &mut BackgroundColor), With>, time: Res