diff --git a/assets/level.ron b/assets/level.ron index 1282be62..9cdf3793 100644 --- a/assets/level.ron +++ b/assets/level.ron @@ -39,7 +39,7 @@ Level( ), telegraph: ( precede_time: 1.0, - duration: 2.0, + speed: 2.0, ), )), ), diff --git a/src/model/level.rs b/src/model/level.rs index b1f831f2..8cad99c4 100644 --- a/src/model/level.rs +++ b/src/model/level.rs @@ -43,8 +43,8 @@ pub struct LightEvent { pub struct Telegraph { /// How long before the event should the telegraph occur (in beats). pub precede_time: Time, - /// How long will the telegraph be visible (in beats). - pub duration: Time, + /// How fast the telegraph is. + pub speed: Coord, } impl Level { @@ -79,7 +79,7 @@ impl Default for Telegraph { fn default() -> Self { Self { precede_time: Time::new(1.0), - duration: Time::new(2.0), + speed: Coord::new(1.0), } } } diff --git a/src/model/light.rs b/src/model/light.rs index 736002ff..f3901964 100644 --- a/src/model/light.rs +++ b/src/model/light.rs @@ -15,8 +15,10 @@ pub struct Light { pub struct LightTelegraph { /// The light to telegraph. pub light: Light, - /// Lifetime of the telegraph. - pub lifetime: Lifetime, + /// How fast the telegraph is. + pub speed: Coord, + /// Time since creation. + pub lifetime: Time, /// The time until the actual light is spawned. pub spawn_timer: Time, } @@ -25,7 +27,8 @@ impl Light { pub fn into_telegraph(self, telegraph: Telegraph, beat_time: Time) -> LightTelegraph { LightTelegraph { light: self, - lifetime: Lifetime::new_max(telegraph.duration * beat_time), + speed: telegraph.speed, + lifetime: Time::ZERO, spawn_timer: telegraph.precede_time * beat_time, } } diff --git a/src/model/logic/mod.rs b/src/model/logic/mod.rs index 6003e9ac..4dc676c9 100644 --- a/src/model/logic/mod.rs +++ b/src/model/logic/mod.rs @@ -28,22 +28,30 @@ impl Model { // Update telegraphs for tele in &mut self.telegraphs { - tele.lifetime.change(-delta_time); + tele.lifetime += delta_time; if tele.spawn_timer > Time::ZERO { tele.spawn_timer -= delta_time; if tele.spawn_timer <= Time::ZERO { self.lights.push(tele.light.clone()); + continue; } } - let t = 1.0 - tele.lifetime.get_ratio().as_f32(); // 0 to 1 - let t = crate::util::smoothstep(t); - tele.light.collider = tele.light.base_collider.transformed(Transform { - scale: r32(t), - ..default() - }); + let t = tele.lifetime * tele.speed; + let transform = if t > tele.light.movement.duration() { + Transform { + scale: Coord::ZERO, + ..default() + } + } else { + tele.light.movement.get(t) + }; + tele.light.collider = tele.light.base_collider.transformed(transform); } - self.telegraphs.retain(|tele| tele.lifetime.is_above_min()); + self.telegraphs.retain(|tele| { + tele.spawn_timer > Time::ZERO + || tele.lifetime * tele.speed < tele.light.movement.duration() + }); // Update lights for light in &mut self.lights { @@ -99,7 +107,7 @@ impl Model { self.random_light().into_telegraph( Telegraph { precede_time: r32(1.0), - duration: r32(2.0), + speed: r32(1.0), }, self.level.beat_time(), )