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

97 lines
2.5 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RhythmHeavenMania.Util;
namespace RhythmHeavenMania.Games.ClappyTrio
{
public class ClappyTrioPlayer : PlayerActionObject
{
private float lastClapBeat;
2021-12-25 02:37:03 +00:00
private float lastClapLength;
[SerializeField] private bool clapVacant;
private int lastIndex;
private bool hit;
2021-12-24 03:36:16 +00:00
public bool clapStarted = false;
public bool canHit;
private GameObject clapEffect;
2022-02-03 22:20:26 +00:00
new int aceTimes = 0;
2021-12-24 03:36:16 +00:00
private void Start()
{
clapEffect = transform.GetChild(4).GetChild(3).gameObject;
}
public override void OnAce()
{
if (aceTimes == 0)
{
Clap(true);
aceTimes++;
}
}
private void Update()
{
2021-12-25 02:37:03 +00:00
if (clapVacant == true)
{
2022-02-03 22:20:26 +00:00
float normalizedBeat = (Conductor.instance.GetPositionFromBeat(lastClapBeat, lastClapLength));
StateCheck(normalizedBeat);
if (normalizedBeat > Minigame.LateTime())
{
clapVacant = false;
lastIndex = 0;
lastClapLength = 0;
lastClapBeat = 0;
}
}
2022-02-05 20:28:04 +00:00
if (PlayerInput.Pressed())
{
Clap(false);
}
}
2021-12-25 02:37:03 +00:00
public void SetClapAvailability(float startBeat, float length)
{
2022-01-27 00:33:52 +00:00
aceTimes = 0;
lastClapBeat = startBeat;
clapVacant = true;
2021-12-25 02:37:03 +00:00
lastClapLength = length;
}
private void Clap(bool overrideCanHit)
{
bool canHit = state.early != true && state.late != true && state.perfect == true && hit == false;
if (canHit || overrideCanHit)
{
2021-12-24 03:36:16 +00:00
clapEffect.SetActive(true);
Jukebox.PlayOneShotGame("clappyTrio/rightClap");
2021-12-24 03:36:16 +00:00
if (this.canHit)
ClappyTrio.instance.playerHitLast = true;
}
else
{
2021-12-24 03:36:16 +00:00
clapEffect.SetActive(false);
Jukebox.PlayOneShot("miss");
ClappyTrio.instance.playerHitLast = false;
2021-12-24 03:36:16 +00:00
if (clapStarted)
this.canHit = false;
}
ClappyTrio.instance.SetFace(ClappyTrio.instance.Lion.Count - 1, 4);
this.GetComponent<Animator>().Play("Clap", 0, 0);
}
}
}