From 960861af7994f063e423533d6f126f0ea1c4ef11 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Thu, 14 Aug 2025 21:57:47 -0500 Subject: [PATCH] Add a sparkler component to flash entities I'll be using this to make a sparkling effect on the debris field left behind from a destroyed ship. It can also be used to do the temporary invincibility effect when (re)spawning the player. --- src/lib.rs | 1 + src/machinery.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index a8b4224..c22ee57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,6 +58,7 @@ impl Plugin for AsteroidPlugin { input_ship_shoot, physics::wrap_entities, machinery::tick_asteroid_manager, + machinery::operate_sparklers, objects::spawn_asteroid.after(machinery::tick_asteroid_manager), objects::split_asteroids, objects::bullet_impact_listener, diff --git a/src/machinery.rs b/src/machinery.rs index eef9110..e55ff91 100644 --- a/src/machinery.rs +++ b/src/machinery.rs @@ -103,3 +103,35 @@ pub fn tick_lifetimes( } } } + +/// Entities marked with this will flash. Used to make the debris field sparkle. +#[derive(Component, Deref, DerefMut)] +pub struct Sparkler(Timer); + +impl Sparkler { + pub fn at_interval(period: f32) -> Self { + Self(Timer::from_seconds(period, TimerMode::Repeating)) + } +} + +/// Advances the timer in a sparkler, swapping between visible and invisible +/// each time the timer expires. +pub fn operate_sparklers(mut sparklers: Query<(&mut Visibility, &mut Sparkler)>, time: Res