2021-12-21 04:38:59 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2021-12-23 22:39:03 +00:00
|
|
|
using RhythmHeavenMania.Util;
|
|
|
|
|
2021-12-21 04:38:59 +00:00
|
|
|
namespace RhythmHeavenMania.Games.ClappyTrio
|
|
|
|
{
|
|
|
|
public class ClappyTrio : MonoBehaviour
|
|
|
|
{
|
2021-12-23 22:39:03 +00:00
|
|
|
[SerializeField] private GameObject LionLeft;
|
|
|
|
private GameObject LionMiddle;
|
|
|
|
private GameObject LionPlayer;
|
|
|
|
|
|
|
|
[SerializeField] private Sprite[] faces;
|
2021-12-24 00:58:48 +00:00
|
|
|
public SpriteRenderer lionHeadLeft, lionHeadMiddle, lionHeadPlayer;
|
2021-12-23 22:39:03 +00:00
|
|
|
|
|
|
|
private bool isClapping;
|
|
|
|
private float currentClappingLength;
|
|
|
|
private float lastClapStart;
|
|
|
|
private int clapIndex;
|
|
|
|
|
2021-12-24 00:58:48 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2021-12-24 00:58:48 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
if (songPosBeat > lastClapStart && songPosBeat < lastClapStart + 1 && clapIndex == 0)
|
|
|
|
{
|
2021-12-24 00:58:48 +00:00
|
|
|
SetFace(0, 4);
|
2021-12-23 22:39:03 +00:00
|
|
|
LionLeft.GetComponent<Animator>().Play("Clap", 0, 0);
|
|
|
|
Jukebox.PlayOneShotGame("clappyTrio/leftClap");
|
|
|
|
|
|
|
|
clapIndex++;
|
|
|
|
}
|
|
|
|
else if (songPosBeat > lastClapStart + currentClappingLength && songPosBeat < lastClapStart + (currentClappingLength * 2) && clapIndex == 1)
|
|
|
|
{
|
2021-12-24 00:58:48 +00:00
|
|
|
SetFace(1, 4);
|
2021-12-23 22:39:03 +00:00
|
|
|
LionMiddle.GetComponent<Animator>().Play("Clap", 0, 0);
|
|
|
|
Jukebox.PlayOneShotGame("clappyTrio/middleClap");
|
|
|
|
|
|
|
|
clapIndex++;
|
|
|
|
}
|
2021-12-24 00:58:48 +00:00
|
|
|
else if (songPosBeat > lastClapStart + (currentClappingLength * 2 - 0.35f) && clapIndex == 2)
|
2021-12-23 22:39:03 +00:00
|
|
|
{
|
2021-12-24 00:58:48 +00:00
|
|
|
ClappyTrioPlayer.SetClapAvailability(lastClapStart + (currentClappingLength * 2 - 0.35f));
|
2021-12-23 22:39:03 +00:00
|
|
|
|
2021-12-24 00:58:48 +00:00
|
|
|
clapIndex = 0;
|
|
|
|
isClapping = false;
|
|
|
|
currentClappingLength = 0;
|
2021-12-23 22:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Clap(float beat, float length)
|
|
|
|
{
|
2021-12-24 00:58:48 +00:00
|
|
|
playerHitLast = false;
|
2021-12-23 22:39:03 +00:00
|
|
|
isClapping = true;
|
|
|
|
lastClapStart = beat;
|
|
|
|
currentClappingLength = length;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Prepare(int type)
|
|
|
|
{
|
|
|
|
SetFace(0, type);
|
|
|
|
SetFace(1, type);
|
|
|
|
SetFace(2, type);
|
2021-12-24 00:58:48 +00:00
|
|
|
PlayAnimationAll("Prepare");
|
|
|
|
Jukebox.PlayOneShotGame("clappyTrio/ready");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Bop()
|
|
|
|
{
|
|
|
|
if (playerHitLast)
|
|
|
|
{
|
|
|
|
SetFace(0, 1);
|
|
|
|
SetFace(1, 1);
|
|
|
|
SetFace(2, 1);
|
|
|
|
}
|
|
|
|
PlayAnimationAll("Bop");
|
2021-12-23 22:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void PlayAnimationAll(string anim)
|
|
|
|
{
|
|
|
|
LionLeft.GetComponent<Animator>().Play(anim, 0, 0);
|
|
|
|
LionMiddle.GetComponent<Animator>().Play(anim, 0, 0);
|
|
|
|
LionPlayer.GetComponent<Animator>().Play(anim, 0, 0);
|
|
|
|
}
|
|
|
|
|
2021-12-24 00:58:48 +00:00
|
|
|
public void SetFace(int lion, int type)
|
2021-12-21 04:38:59 +00:00
|
|
|
{
|
2021-12-23 22:39:03 +00:00
|
|
|
if (lion == 0)
|
2021-12-24 00:58:48 +00:00
|
|
|
lionHeadLeft.sprite = faces[type];
|
|
|
|
if (lion == 1)
|
|
|
|
lionHeadMiddle.sprite = faces[type];
|
|
|
|
if (lion == 2)
|
|
|
|
lionHeadPlayer.sprite = faces[type];
|
2021-12-21 04:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|