From 9d733b6f2f0c36b3664cdf3a72a07e33be6d4963 Mon Sep 17 00:00:00 2001 From: Jenny Crowe Date: Sun, 13 Mar 2022 03:25:41 -0700 Subject: [PATCH] Stomp: Fixed issues associated with specific cue setups. --- Assets/Scripts/Games/CropStomp/CropStomp.cs | 68 +++++++++++++-------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/Assets/Scripts/Games/CropStomp/CropStomp.cs b/Assets/Scripts/Games/CropStomp/CropStomp.cs index 65af90ad..8f04f8c9 100644 --- a/Assets/Scripts/Games/CropStomp/CropStomp.cs +++ b/Assets/Scripts/Games/CropStomp/CropStomp.cs @@ -24,6 +24,7 @@ namespace RhythmHeavenMania.Games private int currentMarchBeat; private int stepCount; private bool isStepping; + private static float inactiveStart = -1f; public bool isMarching => marchStartBeat != -1f; @@ -66,20 +67,48 @@ namespace RhythmHeavenMania.Games var cond = Conductor.instance; var entities = GameManager.instance.Beatmap.entities; - // Find the beat of the closest "start marching" event. - // If not found, default to current beat. float startBeat = cond.songPositionInBeats; - var marchStarts = entities.FindAll(m => m.datamodel == "cropStomp/start marching"); - for (int i = 0; i < marchStarts.Count; i++) + if (inactiveStart == -1f) { - var sampleBeat = marchStarts[i].beat; - if (cond.songPositionInBeats <= sampleBeat + 0.25f) // 0.25-beat buffer in case the start marching event is directly next to the game switch event. + // Find the beat of the closest "start marching" event. + var marchStarts = entities.FindAll(m => m.datamodel == "cropStomp/start marching"); + for (int i = 0; i < marchStarts.Count; i++) { - startBeat = sampleBeat; - break; + var sampleBeat = marchStarts[i].beat; + if (cond.songPositionInBeats <= sampleBeat + 0.25f) // 0.25-beat buffer in case the start marching event is directly next to the game switch event. + { + startBeat = sampleBeat; + break; + } } } + else + { + // Find the beat of the next step, assuming marching started at inactiveStart. + int stepsPassed = 0; + + while (inactiveStart + (stepsPassed * 2f) < cond.songPositionInBeats) + { + stepsPassed++; + + if (stepsPassed > 1000) + { + Debug.Log("Loop broke!"); + return; + } + } + + startBeat = inactiveStart + (stepsPassed * 2f); + + // Cue the marching proper to begin when applicable. + BeatAction.New(gameObject, new List() + { + new BeatAction.Action(startBeat, delegate { StartMarching(startBeat); }) + }); + + inactiveStart = -1f; + } // Veggie and mole events. var vegEvents = entities.FindAll(v => v.datamodel == "cropStomp/veggies"); @@ -92,14 +121,14 @@ namespace RhythmHeavenMania.Games var vegLength = vegEvents[i].length; // Only consider veggie events that aren't past the start point. - if (startBeat < vegBeat + vegLength) + if (startBeat <= vegBeat + vegLength) { int veggiesInEvent = Mathf.CeilToInt(vegLength + 1) / 2; for (int b = 0; b < veggiesInEvent; b++) { var targetVeggieBeat = vegBeat + 2f * b; - if (startBeat < targetVeggieBeat) + if (startBeat <= targetVeggieBeat) { SpawnVeggie(targetVeggieBeat, startBeat, false); } @@ -112,28 +141,13 @@ namespace RhythmHeavenMania.Games { var moleBeat = moleEvents[i].beat; - if (startBeat < moleBeat) + if (startBeat <= moleBeat) { SpawnVeggie(moleBeat, startBeat, true); } } } - public override void OnGameSwitch(float beat) - { - if(inactiveStart != -1f) - { - StartMarching(inactiveStart); - float diff = beat - marchStartBeat; - newBeat = (Mathf.Ceil(diff) + marchStartBeat-1)*Conductor.instance.secPerBeat; - currentMarchBeat = Mathf.CeilToInt(diff); - stepCount = currentMarchBeat / 2; - farmer.nextStompBeat = newBeat/Conductor.instance.secPerBeat; - inactiveStart = -1f; - PlayAnims(); - } - } - List cuedMoleSounds = new List(); private void Update() { @@ -148,7 +162,7 @@ namespace RhythmHeavenMania.Games { var moleEvent = moleEvents[i]; var timeToEvent = moleEvent.beat - cond.songPositionInBeats; - if (timeToEvent <= 3f && timeToEvent > 0f && !cuedMoleSounds.Contains(moleEvent)) + if (timeToEvent <= 4f && timeToEvent > 2f && !cuedMoleSounds.Contains(moleEvent)) { cuedMoleSounds.Add(moleEvent); MultiSound.Play(new MultiSound.Sound[] { new MultiSound.Sound("cropStomp/moleNyeh", (moleEvent.beat - 2f) - moleSoundOffsets[0] * Conductor.instance.songBpm / 60f),