HeavenStudioPlus/Assets/Scripts/Games/ClappyTrio/ClappyTrio.cs

213 lines
7.1 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2021-12-23 22:39:03 +00:00
using RhythmHeavenMania.Util;
namespace RhythmHeavenMania.Games.ClappyTrio
{
2021-12-24 03:36:16 +00:00
public class ClappyTrio : Minigame
{
public int lionCount = 3;
public List<GameObject> Lion;
2021-12-23 22:39:03 +00:00
[SerializeField] private Sprite[] faces;
private bool isClapping;
private float currentClappingLength;
private float lastClapStart;
private int clapIndex;
private ClappyTrioPlayer ClappyTrioPlayer;
public bool playerHitLast = false;
2021-12-23 22:39:03 +00:00
public static ClappyTrio instance { get; set; }
private void Awake()
{
instance = this;
}
2021-12-24 03:36:16 +00:00
public override void OnGameSwitch()
{
for (int i = 0; i < Lion.Count; i++)
{
SetFace(i, 0);
}
2021-12-24 03:36:16 +00:00
PlayAnimationAll("Idle");
}
2021-12-23 22:39:03 +00:00
private void Start()
{
float maxWidth = 9.2f;
float minus = 0;
float newSpacing = maxWidth / lionCount;
if (lionCount > 3)
{
Lion[0].transform.localPosition = new Vector3(-1.5f, 0);
maxWidth = 6.2f;
minus = 1.5f;
}
for (int i = 1; i < lionCount; i++)
{
GameObject lion = Instantiate(Lion[0], Lion[0].transform.parent);
// lion.transform.localPosition = new Vector3(Lion[0].transform.localPosition.x + (1.0333f * lionCount) - i, 0);
lion.transform.localPosition = new Vector3((newSpacing) * (i) - minus, 0);
Lion.Add(lion);
if (i == lionCount - 1)
{
ClappyTrioPlayer = lion.AddComponent<ClappyTrioPlayer>();
}
}
/*LionMiddle = Instantiate(LionLeft, LionLeft.transform.parent);
2021-12-23 22:39:03 +00:00
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<ClappyTrioPlayer>();
lionHeadLeft = LionLeft.transform.GetChild(1).GetComponent<SpriteRenderer>();
lionHeadMiddle = LionMiddle.transform.GetChild(1).GetComponent<SpriteRenderer>();
lionHeadPlayer = LionPlayer.transform.GetChild(1).GetComponent<SpriteRenderer>();*/
2021-12-23 22:39:03 +00:00
}
private void Update()
{
if (isClapping)
{
float songPosBeat = Conductor.instance.songPositionInBeats;
for (int i = 0; i < Lion.Count; i++)
{
2021-12-25 02:37:03 +00:00
float length = currentClappingLength * (i);
float lengthplusone = (currentClappingLength * (i + 1));
// i spent like 25 minutes trying to figure out what was wrong with this when i forgot to subtract the currentClapLength :(
if (i == Lion.Count - 1)
2021-12-25 02:37:03 +00:00
{
length = 0;
}
2021-12-25 02:37:03 +00:00
if (songPosBeat > lastClapStart + length && songPosBeat < lastClapStart + lengthplusone && clapIndex == i)
{
if (i == Lion.Count - 1)
{
2021-12-25 02:37:03 +00:00
ClappyTrioPlayer.SetClapAvailability(lastClapStart + (currentClappingLength * (i - 1)), currentClappingLength);
clapIndex = 0;
isClapping = false;
currentClappingLength = 0;
ClappyTrioPlayer.clapStarted = false;
}
else
{
SetFace(i, 4);
Lion[i].GetComponent<Animator>().Play("Clap", 0, 0);
Jukebox.PlayOneShotGame("clappyTrio/leftClap");
clapIndex++;
}
break;
}
}
/*if (songPosBeat > lastClapStart && songPosBeat < lastClapStart + 1 && clapIndex == 0)
2021-12-23 22:39:03 +00:00
{
Debug.Log(Conductor.instance.songPositionInBeats);
SetFace(0, 4);
Lion[0].GetComponent<Animator>().Play("Clap", 0, 0);
2021-12-23 22:39:03 +00:00
Jukebox.PlayOneShotGame("clappyTrio/leftClap");
clapIndex++;
}
else if (songPosBeat > lastClapStart + currentClappingLength && songPosBeat < lastClapStart + (currentClappingLength * 2) && clapIndex == 1)
{
Debug.Log(Conductor.instance.songPositionInBeats);
SetFace(1, 4);
Lion[1].GetComponent<Animator>().Play("Clap", 0, 0);
2021-12-23 22:39:03 +00:00
Jukebox.PlayOneShotGame("clappyTrio/middleClap");
clapIndex++;
}
else if (songPosBeat > lastClapStart + (currentClappingLength * 2 - 0.35f) && clapIndex == 2)
2021-12-23 22:39:03 +00:00
{
Debug.Log(Conductor.instance.songPositionInBeats);
ClappyTrioPlayer.SetClapAvailability(lastClapStart + (currentClappingLength * 2 - 0.35f));
2021-12-23 22:39:03 +00:00
clapIndex = 0;
isClapping = false;
currentClappingLength = 0;
2021-12-24 03:36:16 +00:00
ClappyTrioPlayer.clapStarted = false;
}*/
2021-12-23 22:39:03 +00:00
}
}
public void Clap(float beat, float length)
{
2021-12-24 03:36:16 +00:00
ClappyTrioPlayer.clapStarted = true;
ClappyTrioPlayer.canHit = true; // this is technically a lie, this just restores the ability to hit
playerHitLast = false;
2021-12-23 22:39:03 +00:00
isClapping = true;
lastClapStart = beat;
currentClappingLength = length;
}
public void Prepare(int type)
{
for (int i = 0; i < Lion.Count; i++)
{
SetFace(i, type);
}
PlayAnimationAll("Prepare");
Jukebox.PlayOneShotGame("clappyTrio/ready");
}
public void Bop()
{
if (playerHitLast)
{
for (int i = 0; i < Lion.Count; i++)
{
SetFace(i, 1);
}
}
2021-12-24 03:36:16 +00:00
else
{
for (int i = 0; i < Lion.Count; i++)
{
if (i == Lion.Count - 1)
{
SetFace(i, 0);
}
else
{
SetFace(i, 2);
}
}
2021-12-24 03:36:16 +00:00
}
PlayAnimationAll("Bop");
2021-12-23 22:39:03 +00:00
}
private void PlayAnimationAll(string anim)
{
for (int i = 0; i < Lion.Count; i++)
{
Lion[i].GetComponent<Animator>().Play(anim, -1, 0);
}
2021-12-23 22:39:03 +00:00
}
public void SetFace(int lion, int type)
{
Lion[lion].transform.GetChild(1).GetComponent<SpriteRenderer>().sprite = faces[type];
}
}
}