diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 36236f35..c40d57e1 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -173,7 +173,6 @@ namespace RhythmHeavenMania // if game isn't loaded, preload game so whatever event that would be called will still run outside if needed if (entitiesAtSameBeat[i].datamodel.Split('/')[0] != currentGame && !preloadedGames.Contains(preloadedGames.Find(c => c.name == entitiesAtSameBeat[i].datamodel.Split('/')[0]))) { - //PreloadGame(entitesAtSameBeat[i].datamodel.Split('/')[0]); eventCaller.CallEvent(entitiesAtSameBeat[i], false); } else @@ -316,28 +315,34 @@ namespace RhythmHeavenMania #endregion - public void SwitchGame(string game) + public void SwitchGame(string game, float beat) { if (game != currentGame) { if (currentGameSwitchIE != null) StopCoroutine(currentGameSwitchIE); - currentGameSwitchIE = StartCoroutine(SwitchGameIE(game)); + currentGameSwitchIE = StartCoroutine(SwitchGameIE(game, beat)); } } - IEnumerator SwitchGameIE(string game) + IEnumerator SwitchGameIE(string game, float beat) { this.GetComponent().enabled = true; SetGame(game); + yield return new WaitForEndOfFrame(); //this is needed so that the minigame can have Start() called before OnGameSwitch() + + Minigame miniGame = currentGameO.GetComponent(); + if (miniGame != null) + miniGame.OnGameSwitch(beat); + yield return new WaitForSeconds(0.1f); this.GetComponent().enabled = false; } - private void SetGame(string game, bool onGameSwitch = true) + private void SetGame(string game, bool onGameSwitch = true) { Destroy(currentGameO); @@ -372,9 +377,6 @@ namespace RhythmHeavenMania GetGame(game).GetComponent().OnGameSwitch(); }*/ - Minigame miniGame = currentGameO.GetComponent(); - if (miniGame != null) - miniGame.OnGameSwitch(); SetCurrentGame(game); ResetCamera(); diff --git a/Assets/Scripts/Games/CropStomp/CropStomp.cs b/Assets/Scripts/Games/CropStomp/CropStomp.cs index bac0e4e9..47202336 100644 --- a/Assets/Scripts/Games/CropStomp/CropStomp.cs +++ b/Assets/Scripts/Games/CropStomp/CropStomp.cs @@ -1,11 +1,9 @@ -using System.Collections; +using DG.Tweening; +using NaughtyBezierCurves; +using RhythmHeavenMania.Util; +using System; using System.Collections.Generic; using UnityEngine; -using System; -using NaughtyBezierCurves; -using DG.Tweening; - -using RhythmHeavenMania.Util; namespace RhythmHeavenMania.Games.CropStomp { @@ -24,6 +22,7 @@ namespace RhythmHeavenMania.Games.CropStomp private int currentMarchBeat; private int stepCount; private bool isStepping; + private static float inactiveStart = -1f; public bool isMarching => marchStartBeat != -1f; @@ -118,6 +117,21 @@ namespace RhythmHeavenMania.Games.CropStomp } } + 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() { @@ -143,38 +157,17 @@ namespace RhythmHeavenMania.Games.CropStomp if (!isMarching) return; + Debug.Log(newBeat); if (cond.ReportBeat(ref newBeat, marchOffset, true)) { currentMarchBeat += 1; - // Step. - if (currentMarchBeat % 2 != 0) + PlayAnims(); + if (currentMarchBeat % 2 != 0) //step sound { - // Don't step if already stomped. - if (!isStepping) - { - stepCount += 1; - var stepAnim = (stepCount % 2 != 0 ? "StepFront" : "StepBack"); - - legsAnim.Play(stepAnim, 0, 0); - - isStepping = true; - } - Jukebox.PlayOneShotGame("cropStomp/hmm"); } - // Lift. - else - { - var liftAnim = (stepCount % 2 != 0 ? "LiftBack" : "LiftFront"); - legsAnim.Play(liftAnim, 0, 0); - - var farmerPos = farmerTrans.localPosition; - farmerTrans.localPosition = new Vector3(farmerPos.x - stepDistance, farmerPos.y, farmerPos.z); - - isStepping = false; - } } // Object scroll. @@ -214,6 +207,36 @@ namespace RhythmHeavenMania.Games.CropStomp isFlicking = false; } + private void PlayAnims() + { + // Step. + if (currentMarchBeat % 2 != 0) + { + // Don't step if already stomped. + if (!isStepping) + { + stepCount += 1; + var stepAnim = (stepCount % 2 != 0 ? "StepFront" : "StepBack"); + + legsAnim.Play(stepAnim, 0, 0); + + isStepping = true; + } + + } + // Lift. + else + { + var liftAnim = (stepCount % 2 != 0 ? "LiftBack" : "LiftFront"); + legsAnim.Play(liftAnim, 0, 0); + + var farmerPos = farmerTrans.localPosition; + farmerTrans.localPosition = new Vector3(farmerPos.x - stepDistance, farmerPos.y, farmerPos.z); + + isStepping = false; + } + } + public void StartMarching(float beat) { marchStartBeat = beat; @@ -257,5 +280,24 @@ namespace RhythmHeavenMania.Games.CropStomp newVeggie.gameObject.SetActive(true); } + + public static void MarchInactive(float beat) + { + if (GameManager.instance.currentGame == "cropStomp") //this function is only meant for making march sounds while the game is inactive + { + return; + } + inactiveStart = beat; + Beatmap.Entity gameSwitch = GameManager.instance.Beatmap.entities.Find(c => c.beat >= beat && c.datamodel == "gameManager/switchGame/cropStomp"); + if (gameSwitch == null) + return; + int length = Mathf.CeilToInt((gameSwitch.beat - beat)/2); + MultiSound.Sound[] sounds = new MultiSound.Sound[length]; + for(int i = 0; i < length; i++) + { + sounds[i] = new MultiSound.Sound("cropStomp/hmm", beat + i*2); + } + MultiSound.Play(sounds, forcePlay:true); + } } } diff --git a/Assets/Scripts/Games/ForkLifter/ForkLifter.cs b/Assets/Scripts/Games/ForkLifter/ForkLifter.cs index c128d806..310df41f 100644 --- a/Assets/Scripts/Games/ForkLifter/ForkLifter.cs +++ b/Assets/Scripts/Games/ForkLifter/ForkLifter.cs @@ -37,9 +37,9 @@ namespace RhythmHeavenMania.Games.ForkLifter instance = this; } - public override void OnGameSwitch() + public override void OnGameSwitch(float beat) { - base.OnGameSwitch(); + base.OnGameSwitch(beat); ForkLifterHand.CheckNextFlick(); } diff --git a/Assets/Scripts/Games/KarateMan/KarateMan.cs b/Assets/Scripts/Games/KarateMan/KarateMan.cs index 04f7f593..95a23f59 100644 --- a/Assets/Scripts/Games/KarateMan/KarateMan.cs +++ b/Assets/Scripts/Games/KarateMan/KarateMan.cs @@ -120,9 +120,9 @@ namespace RhythmHeavenMania.Games.KarateMan Shadow = 0; } - public override void OnGameSwitch() + public override void OnGameSwitch(float beat) { - base.OnGameSwitch(); + base.OnGameSwitch(beat); SetBackgroundColor((int)BGType, (int)Shadow, BGColor, ShadowColor); } diff --git a/Assets/Scripts/Games/Minigame.cs b/Assets/Scripts/Games/Minigame.cs index def63233..3d3e02b1 100644 --- a/Assets/Scripts/Games/Minigame.cs +++ b/Assets/Scripts/Games/Minigame.cs @@ -44,12 +44,11 @@ namespace RhythmHeavenMania.Games public int firstEnable = 0; - public virtual void OnGameSwitch() + public virtual void OnGameSwitch(float beat) { //Below is a template that can be used for handling previous entities. //section below is if you only want to look at entities that overlap the game switch /* - float beat = Conductor.instance.songPositionInBeats; List prevEntities = GameManager.instance.Beatmap.entities.FindAll(c => c.beat <= beat && c.datamodel.Split(0) == [insert game name]); foreach(Beatmap.Entity entity in prevEntities) { diff --git a/Assets/Scripts/Games/MrUpbeat/MrUpbeat.cs b/Assets/Scripts/Games/MrUpbeat/MrUpbeat.cs index ac60d8c6..39aca89a 100644 --- a/Assets/Scripts/Games/MrUpbeat/MrUpbeat.cs +++ b/Assets/Scripts/Games/MrUpbeat/MrUpbeat.cs @@ -14,6 +14,7 @@ namespace RhythmHeavenMania.Games.MrUpbeat public GameObject metronome; public UpbeatMan man; public GameObject bt; + private static MultiSound beeps; //only used when this game isn't active. public GameEvent beat = new GameEvent(); public bool canGo = false; @@ -70,6 +71,28 @@ namespace RhythmHeavenMania.Games.MrUpbeat } } + public override void OnGameSwitch(float beat) + { + foreach (Beatmap.Entity entity in GameManager.instance.Beatmap.entities) + { + if (entity.beat > beat) //the list is sorted based on the beat of the entity, so this should work fine. + { + break; + } + if (entity.datamodel != "mrUpbeat/prepare" || entity.beat + entity.length < beat) //check for prepares that happen before the switch + { + continue; + } + SetInterval(entity.beat); + break; + } + if(beeps != null) + { + beeps.Delete(); //the beeps are only for when the game isn't active + beeps = null; + } + } + public void SetInterval(float beat) { beatCount = 0; @@ -106,5 +129,23 @@ namespace RhythmHeavenMania.Games.MrUpbeat yield return new WaitForSeconds(Conductor.instance.secPerBeat * 0.5f - offset); man.Blip(); } + + public static void Beep(float beat, float length) + { + if(GameManager.instance.currentGame == "mrUpbeat") //this function is only meant for making beeps while the game is inactive + { + return; + } + if (beeps != null) + { + beeps.Delete(); + } + MultiSound.Sound[] beepSounds = new MultiSound.Sound[Mathf.CeilToInt(length)]; + for(int i = 0; i < beepSounds.Length; i++) + { + beepSounds[i] = new MultiSound.Sound("mrUpbeat/blip", beat + 0.5f + i); + } + beeps = MultiSound.Play(beepSounds, forcePlay:true); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Games/SpaceSoccer/SpaceSoccer.cs b/Assets/Scripts/Games/SpaceSoccer/SpaceSoccer.cs index c89fd971..457139d5 100644 --- a/Assets/Scripts/Games/SpaceSoccer/SpaceSoccer.cs +++ b/Assets/Scripts/Games/SpaceSoccer/SpaceSoccer.cs @@ -44,9 +44,25 @@ namespace RhythmHeavenMania.Games.SpaceSoccer { } - - public void Dispense(float beat) + public override void OnGameSwitch(float beat) + { + foreach(Beatmap.Entity entity in GameManager.instance.Beatmap.entities) + { + if(entity.beat > beat) //the list is sorted based on the beat of the entity, so this should work fine. + { + break; + } + if(entity.datamodel != "spaceSoccer/ball dispense" || entity.beat + entity.length <= beat) //check for dispenses that happen right before the switch + { + continue; + } + Dispense(entity.beat, false); + break; + } + } + + public void Dispense(float beat, bool playSound = true) { ballDispensed = true; for (int i = 0; i < kickers.Count; i++) @@ -60,7 +76,7 @@ namespace RhythmHeavenMania.Games.SpaceSoccer ball.SetActive(true); Ball ball_ = ball.GetComponent(); ball_.Init(kicker, beat); - if (kicker.player) + if (kicker.player && playSound) { DispenseSound(beat); } @@ -71,16 +87,16 @@ namespace RhythmHeavenMania.Games.SpaceSoccer { MultiSound.Play(new MultiSound.Sound[] { - new MultiSound.Sound("games/spaceSoccer/dispenseNoise", beat), - new MultiSound.Sound("games/spaceSoccer/dispenseTumble1", beat + 0.25f), - new MultiSound.Sound("games/spaceSoccer/dispenseTumble2", beat + 0.5f), - new MultiSound.Sound("games/spaceSoccer/dispenseTumble2B",beat + 0.5f), - new MultiSound.Sound("games/spaceSoccer/dispenseTumble3", beat + 0.75f), - new MultiSound.Sound("games/spaceSoccer/dispenseTumble4", beat + 1f), - new MultiSound.Sound("games/spaceSoccer/dispenseTumble5", beat + 1.25f), - new MultiSound.Sound("games/spaceSoccer/dispenseTumble6", beat + 1.5f), - new MultiSound.Sound("games/spaceSoccer/dispenseTumble6B",beat + 1.75f), - }, false); + new MultiSound.Sound("spaceSoccer/dispenseNoise", beat), + new MultiSound.Sound("spaceSoccer/dispenseTumble1", beat + 0.25f), + new MultiSound.Sound("spaceSoccer/dispenseTumble2", beat + 0.5f), + new MultiSound.Sound("spaceSoccer/dispenseTumble2B",beat + 0.5f), + new MultiSound.Sound("spaceSoccer/dispenseTumble3", beat + 0.75f), + new MultiSound.Sound("spaceSoccer/dispenseTumble4", beat + 1f), + new MultiSound.Sound("spaceSoccer/dispenseTumble5", beat + 1.25f), + new MultiSound.Sound("spaceSoccer/dispenseTumble6", beat + 1.5f), + new MultiSound.Sound("spaceSoccer/dispenseTumble6B",beat + 1.75f), + }, forcePlay:true); } } diff --git a/Assets/Scripts/Games/Spaceball/Spaceball.cs b/Assets/Scripts/Games/Spaceball/Spaceball.cs index 7f30ac3b..fd7d7a10 100644 --- a/Assets/Scripts/Games/Spaceball/Spaceball.cs +++ b/Assets/Scripts/Games/Spaceball/Spaceball.cs @@ -37,7 +37,7 @@ namespace RhythmHeavenMania.Games.Spaceball public static Spaceball instance { get; set; } - public override void OnGameSwitch() + public override void OnGameSwitch(float beat) { for (int i = 1; i < BallsHolder.transform.childCount; i++) Destroy(BallsHolder.transform.GetChild(i).gameObject); diff --git a/Assets/Scripts/Minigames.cs b/Assets/Scripts/Minigames.cs index 00d47a21..3a7cf2b8 100644 --- a/Assets/Scripts/Minigames.cs +++ b/Assets/Scripts/Minigames.cs @@ -110,7 +110,7 @@ namespace RhythmHeavenMania { new Minigame("gameManager", "Game Manager", "", false, true, new List() { - new GameAction("switchGame", delegate { GameManager.instance.SwitchGame(eventCaller.currentSwitchGame); }, 0.5f, inactiveFunction: delegate { GameManager.instance.SwitchGame(eventCaller.currentSwitchGame); }), + new GameAction("switchGame", delegate { GameManager.instance.SwitchGame(eventCaller.currentSwitchGame, eventCaller.currentEntity.beat); }, 0.5f, inactiveFunction: delegate { GameManager.instance.SwitchGame(eventCaller.currentSwitchGame, eventCaller.currentEntity.beat); }), new GameAction("end", delegate { Debug.Log("end"); }), new GameAction("skill star", delegate { }, 1f, true), new GameAction("flash", delegate @@ -383,7 +383,7 @@ namespace RhythmHeavenMania }), new Minigame("cropStomp", "Crop Stomp", "BFDEA6", false, false, new List() { - new GameAction("start marching", delegate { CropStomp.instance.StartMarching(eventCaller.currentEntity.beat); }, 2f, false), + new GameAction("start marching", delegate { CropStomp.instance.StartMarching(eventCaller.currentEntity.beat); }, 2f, false, inactiveFunction: delegate { CropStomp.MarchInactive(eventCaller.currentEntity.beat); }), new GameAction("veggies", delegate { }, 4f, true), new GameAction("mole", delegate { }, 2f, false), }), @@ -394,7 +394,7 @@ namespace RhythmHeavenMania }), new Minigame("mrUpbeat", "Mr. Upbeat", "FFFFFF", false, false, new List() { - new GameAction("prepare", delegate { MrUpbeat.instance.SetInterval(eventCaller.currentEntity.beat); }, 0.5f, true), + new GameAction("prepare", delegate { MrUpbeat.instance.SetInterval(eventCaller.currentEntity.beat); }, 0.5f, true, inactiveFunction: delegate { MrUpbeat.Beep(eventCaller.currentEntity.beat, eventCaller.currentEntity.length); }), new GameAction("go", delegate { MrUpbeat.instance.Go(eventCaller.currentEntity.beat); }, 4f, true), new GameAction("ding!", delegate { MrUpbeat.instance.Ding(eventCaller.currentEntity.toggle); }, 0.5f, parameters: new List() { diff --git a/Assets/Scripts/Util/Jukebox.cs b/Assets/Scripts/Util/Jukebox.cs index 079039fd..f2c339a3 100644 --- a/Assets/Scripts/Util/Jukebox.cs +++ b/Assets/Scripts/Util/Jukebox.cs @@ -81,9 +81,9 @@ namespace RhythmHeavenMania.Util return audioSource; } - public static AudioSource PlayOneShotGame(string name, float beat = -1) + public static AudioSource PlayOneShotGame(string name, float beat = -1, bool forcePlay = false) { - if (GameManager.instance.currentGame == name.Split('/')[0]) + if (GameManager.instance.currentGame == name.Split('/')[0] || forcePlay) { return PlayOneShot($"games/{name}", beat); } @@ -91,9 +91,9 @@ namespace RhythmHeavenMania.Util return null; } - public static AudioSource PlayOneShotScheduledGame(string name, double targetTime) + public static AudioSource PlayOneShotScheduledGame(string name, double targetTime, bool forcePlay = false) { - if (GameManager.instance.currentGame == name.Split('/')[0]) + if (GameManager.instance.currentGame == name.Split('/')[0] || forcePlay) { return PlayOneShotScheduled($"games/{name}", targetTime); } diff --git a/Assets/Scripts/Util/MultiSound.cs b/Assets/Scripts/Util/MultiSound.cs index 9e6b441b..0e238e94 100644 --- a/Assets/Scripts/Util/MultiSound.cs +++ b/Assets/Scripts/Util/MultiSound.cs @@ -10,6 +10,7 @@ namespace RhythmHeavenMania.Util private float startBeat; private int index; private bool game; + private bool forcePlay; public List sounds = new List(); public class Sound @@ -25,7 +26,7 @@ namespace RhythmHeavenMania.Util } - public static MultiSound Play(Sound[] snds, bool game = true) + public static MultiSound Play(Sound[] snds, bool game = true, bool forcePlay = false) { List sounds = snds.ToList(); GameObject gameObj = new GameObject(); @@ -33,6 +34,7 @@ namespace RhythmHeavenMania.Util ms.sounds = sounds; ms.startBeat = sounds[0].beat; ms.game = game; + ms.forcePlay = forcePlay; gameObj.name = "MultiSound"; GameManager.instance.SoundObjects.Add(gameObj); @@ -48,7 +50,7 @@ namespace RhythmHeavenMania.Util if (songPositionInBeats >= sounds[i].beat && index == i) { if (game) - Jukebox.PlayOneShotGame(sounds[i].name); + Jukebox.PlayOneShotGame(sounds[i].name, forcePlay:forcePlay); else Jukebox.PlayOneShot(sounds[i].name);