private IEnumerator Sequence() { // Infinite. Vector2 start = Position; while (true) { if (!HasPlayerRider()) { yield return(null); continue; } Vector2 from = start; Vector2 to; float at2; // Player is riding. bool shouldCancel = false; int i; for (i = 0; i < targets.Length; i++) { to = targets[i]; // Start shaking. sfx.Play($"event:/CommunalHelperEvents/game/zipMover/{themePath}/start"); Input.Rumble(RumbleStrength.Medium, RumbleLength.Short); StartShaking(0.1f); yield return(0.1f); // Start moving towards the target. streetlight.SetAnimationFrame(3); StopPlayerRunIntoAnimation = false; at2 = 0f; while (at2 < 1f) { yield return(null); at2 = Calc.Approach(at2, 1f, 2f * Engine.DeltaTime); percent = Ease.SineIn(at2); Vector2 vector = Vector2.Lerp(from, to, percent); if (Scene.OnInterval(0.1f)) { pathRenderer.CreateSparks(); } MoveTo(vector); if (Scene.OnInterval(0.03f)) { SpawnScrapeParticles(); } } bool last = (i == targets.Length - 1); // Arrived, will wait for 0.5 secs. StartShaking(0.2f); Audio.Play($"event:/CommunalHelperEvents/game/zipMover/{themePath}/impact", Center); streetlight.SetAnimationFrame(((waits && !last) || (ticking && !last) || (permanent && last)) ? 1 : 2); Input.Rumble(RumbleStrength.Strong, RumbleLength.Medium); SceneAs <Level>().Shake(); StopPlayerRunIntoAnimation = true; yield return(0.5f); from = targets[i]; if (ticking && !last) { float tickTime = 0.0f; int tickNum = 0; while (!HasPlayerRider() && tickNum < 5) { yield return(null); streetlight.SetAnimationFrame(1 - (int)Math.Round(tickTime)); tickTime = Calc.Approach(tickTime, 1f, Engine.DeltaTime); if (tickTime >= 1.0f) { tickTime = 0.0f; tickNum++; Audio.Play($"event:/CommunalHelperEvents/game/zipMover/{themePath}/tick", Center); StartShaking(0.1f); } } if (tickNum == 5 && !HasPlayerRider()) { shouldCancel = true; break; } } else if (waits && !last) { streetlight.SetAnimationFrame(1); while (!HasPlayerRider()) { yield return(null); } } } if (!permanent) { for (i -= 2 - (shouldCancel ? 1 : 0); i > -2; i--) { to = (i == -1) ? start : targets[i]; // Goes back to start with a speed that is four times slower. StopPlayerRunIntoAnimation = false; streetlight.SetAnimationFrame(2); sfx.Play($"event:/CommunalHelperEvents/game/zipMover/{themePath}/return"); at2 = 0f; while (at2 < 1f) { yield return(null); at2 = Calc.Approach(at2, 1f, 0.5f * Engine.DeltaTime); percent = 1f - Ease.SineIn(at2); Vector2 position = Vector2.Lerp(from, to, Ease.SineIn(at2)); MoveTo(position); } if (i != -1) { from = targets[i]; } StartShaking(0.2f); Audio.Play($"event:/CommunalHelperEvents/game/zipMover/{themePath}/finish", Center); } StopPlayerRunIntoAnimation = true; // Done, will not actiavte for 0.5 secs. streetlight.SetAnimationFrame(1); yield return(0.5f); } else { // Done, will never be activated again. StartShaking(0.3f); Audio.Play($"event:/CommunalHelperEvents/game/zipMover/{themePath}/finish", Center); Audio.Play($"event:/CommunalHelperEvents/game/zipMover/{themePath}/tick", Center); SceneAs <Level>().Shake(0.15f); streetlight.SetAnimationFrame(0); while (true) { yield return(null); } } } }
private IEnumerator Sequence() { // Infinite. while (true) { if (!HasPlayerRider()) { yield return(null); continue; } Vector2 from = start; Vector2 to; float at2; // Player is riding. bool shouldCancel = false; int i; // Zeroth node is the origin for (i = 1; i < nodes.Length; i++) { to = nodes[i]; // Start shaking. sfx.Play(CustomSFX.game_zipMover_normal_start); Input.Rumble(RumbleStrength.Medium, RumbleLength.Short); StartShaking(0.1f); yield return(0.1f); // Start moving towards the target. //streetlight.SetAnimationFrame(3); StopPlayerRunIntoAnimation = false; at2 = 0f; while (at2 < 1f) { yield return(null); at2 = Calc.Approach(at2, 1f, 2f * Engine.DeltaTime); percent = Ease.SineIn(at2); Vector2 vector = Vector2.Lerp(from, to, percent); vector = FixCassetteY(vector); ScrapeParticlesCheck(to); if (Scene.OnInterval(0.1f)) { pathRenderer.CreateSparks(); } MoveTo(vector); } bool last = (i == nodes.Length - 1); // Arrived, will wait for 0.5 secs. StartShaking(0.2f); Audio.Play(CustomSFX.game_zipMover_normal_impact, Center); //streetlight.SetAnimationFrame(((waits && !last) || (ticking && !last) || (permanent && last)) ? 1 : 2); Input.Rumble(RumbleStrength.Strong, RumbleLength.Medium); SceneAs <Level>().Shake(); StopPlayerRunIntoAnimation = true; yield return(0.5f); from = nodes[i]; if (ticking && !last) { float tickTime = 0.0f; int tickNum = 0; while (!HasPlayerRider() && tickNum < 5) { yield return(null); //streetlight.SetAnimationFrame(1 - (int) Math.Round(tickTime)); tickTime = Calc.Approach(tickTime, 1f, Engine.DeltaTime); if (tickTime >= 1.0f) { tickTime = 0.0f; tickNum++; sfx.Play(CustomSFX.game_zipMover_normal_tick); StartShaking(0.1f); } } if (tickNum == 5 && !HasPlayerRider()) { shouldCancel = true; break; } } else if (waits && !last) { //streetlight.SetAnimationFrame(1); while (!HasPlayerRider()) { yield return(null); } } } if (!permanent) { if (noReturn) { ReverseNodes(out Vector2 newStart); start = newStart; } else { for (i -= 2 - (shouldCancel ? 1 : 0); i > -1; i--) { to = (i == 0) ? start : nodes[i]; // Goes back to start with a speed that is four times slower. StopPlayerRunIntoAnimation = false; //streetlight.SetAnimationFrame(2); sfx.Play(CustomSFX.game_zipMover_normal_return); at2 = 0f; while (at2 < 1f) { yield return(null); at2 = Calc.Approach(at2, 1f, 0.5f * Engine.DeltaTime); percent = 1f - Ease.SineIn(at2); Vector2 position = Vector2.Lerp(from, to, Ease.SineIn(at2)); position = FixCassetteY(position); MoveTo(position); } if (i != 0) { from = nodes[i]; } StartShaking(0.2f); Audio.Play(CustomSFX.game_zipMover_normal_finish, Center); } } StopPlayerRunIntoAnimation = true; // Done, will not actiavte for 0.5 secs. //streetlight.SetAnimationFrame(1); yield return(0.5f); } else { // Done, will never be activated again. StartShaking(0.3f); Audio.Play(CustomSFX.game_zipMover_normal_finish, Center); Audio.Play(CustomSFX.game_zipMover_normal_tick, Center); SceneAs <Level>().Shake(0.15f); //streetlight.SetAnimationFrame(0); while (true) { yield return(null); } } } }