using System.Collections; using System.Collections.Generic; using UnityEngine; using RhythmHeavenMania.Util; namespace RhythmHeavenMania.Games.ClappyTrio { public class ClappyTrio : Minigame { [SerializeField] private GameObject LionLeft; private GameObject LionMiddle; private GameObject LionPlayer; [SerializeField] private Sprite[] faces; public SpriteRenderer lionHeadLeft, lionHeadMiddle, lionHeadPlayer; private bool isClapping; private float currentClappingLength; private float lastClapStart; private int clapIndex; private ClappyTrioPlayer ClappyTrioPlayer; public bool playerHitLast = false; public static ClappyTrio instance { get; set; } private void Awake() { instance = this; } public override void OnGameSwitch() { SetFace(0, 0); SetFace(1, 0); SetFace(2, 0); PlayAnimationAll("Idle"); } private void Start() { LionMiddle = Instantiate(LionLeft, LionLeft.transform.parent); LionMiddle.transform.localPosition = new Vector3(3.1f, 0); LionPlayer = Instantiate(LionLeft, LionLeft.transform.parent); LionPlayer.transform.localPosition = new Vector3(6.2f, 0); ClappyTrioPlayer = LionPlayer.AddComponent(); lionHeadLeft = LionLeft.transform.GetChild(1).GetComponent(); lionHeadMiddle = LionMiddle.transform.GetChild(1).GetComponent(); lionHeadPlayer = LionPlayer.transform.GetChild(1).GetComponent(); } private void Update() { if (isClapping) { float songPosBeat = Conductor.instance.songPositionInBeats; if (songPosBeat > lastClapStart && songPosBeat < lastClapStart + 1 && clapIndex == 0) { SetFace(0, 4); LionLeft.GetComponent().Play("Clap", 0, 0); Jukebox.PlayOneShotGame("clappyTrio/leftClap"); clapIndex++; } else if (songPosBeat > lastClapStart + currentClappingLength && songPosBeat < lastClapStart + (currentClappingLength * 2) && clapIndex == 1) { SetFace(1, 4); LionMiddle.GetComponent().Play("Clap", 0, 0); Jukebox.PlayOneShotGame("clappyTrio/middleClap"); clapIndex++; } else if (songPosBeat > lastClapStart + (currentClappingLength * 2 - 0.35f) && clapIndex == 2) { ClappyTrioPlayer.SetClapAvailability(lastClapStart + (currentClappingLength * 2 - 0.35f)); clapIndex = 0; isClapping = false; currentClappingLength = 0; ClappyTrioPlayer.clapStarted = false; } } } public void Clap(float beat, float length) { ClappyTrioPlayer.clapStarted = true; ClappyTrioPlayer.canHit = true; // this is technically a lie, this just restores the ability to hit playerHitLast = false; isClapping = true; lastClapStart = beat; currentClappingLength = length; } public void Prepare(int type) { SetFace(0, type); SetFace(1, type); SetFace(2, type); PlayAnimationAll("Prepare"); Jukebox.PlayOneShotGame("clappyTrio/ready"); } public void Bop() { if (playerHitLast) { SetFace(0, 1); SetFace(1, 1); SetFace(2, 1); } else { SetFace(0, 2); SetFace(1, 2); SetFace(2, 0); } PlayAnimationAll("Bop"); } private void PlayAnimationAll(string anim) { LionLeft.GetComponent().Play(anim, -1, 0); LionMiddle.GetComponent().Play(anim, -1, 0); LionPlayer.GetComponent().Play(anim, -1, 0); } public void SetFace(int lion, int type) { if (lion == 0) lionHeadLeft.sprite = faces[type]; if (lion == 1) lionHeadMiddle.sprite = faces[type]; if (lion == 2) lionHeadPlayer.sprite = faces[type]; } } }