Implemented inactive functions for all game count ins

Also made some changes to how SwitchGame(), OnGameSwitch, and the jukebox work.
This commit is contained in:
Slaith 2022-03-07 20:46:49 -08:00
parent 2d328229c9
commit fca105259c
11 changed files with 169 additions and 67 deletions

View file

@ -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,22 +315,28 @@ 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<SpriteRenderer>().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<Minigame>();
if (miniGame != null)
miniGame.OnGameSwitch(beat);
yield return new WaitForSeconds(0.1f);
this.GetComponent<SpriteRenderer>().enabled = false;
@ -372,9 +377,6 @@ namespace RhythmHeavenMania
GetGame(game).GetComponent<Minigame>().OnGameSwitch();
}*/
Minigame miniGame = currentGameO.GetComponent<Minigame>();
if (miniGame != null)
miniGame.OnGameSwitch();
SetCurrentGame(game);
ResetCamera();

View file

@ -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<Beatmap.Entity> cuedMoleSounds = new List<Beatmap.Entity>();
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);
}
}
}

View file

@ -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();
}

View file

@ -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);
}

View file

@ -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<Beatmap.Entity> prevEntities = GameManager.instance.Beatmap.entities.FindAll(c => c.beat <= beat && c.datamodel.Split(0) == [insert game name]);
foreach(Beatmap.Entity entity in prevEntities)
{

View file

@ -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);
}
}
}

View file

@ -45,8 +45,24 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
}
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)
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>();
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);
}
}

View file

@ -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);

View file

@ -110,7 +110,7 @@ namespace RhythmHeavenMania
{
new Minigame("gameManager", "Game Manager", "", false, true, new List<GameAction>()
{
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<GameAction>()
{
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<GameAction>()
{
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<Param>()
{

View file

@ -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);
}

View file

@ -10,6 +10,7 @@ namespace RhythmHeavenMania.Util
private float startBeat;
private int index;
private bool game;
private bool forcePlay;
public List<Sound> sounds = new List<Sound>();
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<Sound> 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);