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

89 lines
2.3 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2022-03-14 14:21:05 +00:00
using HeavenStudio.Util;
2022-03-14 14:21:05 +00:00
namespace HeavenStudio.Games.Scripts_ClappyTrio
{
public class ClappyTrioPlayer : MonoBehaviour
{
ClappyTrio game;
private double lastClapBeat;
2021-12-25 02:37:03 +00:00
private float lastClapLength;
2021-12-24 03:36:16 +00:00
public bool clapStarted = false;
public bool canHit;
private GameObject clapEffect;
private void Awake()
2021-12-24 03:36:16 +00:00
{
game = ClappyTrio.instance;
2021-12-24 03:36:16 +00:00
clapEffect = transform.GetChild(4).GetChild(3).gameObject;
}
private void Update()
{
if (PlayerInput.GetIsAction(ClappyTrio.InputAction_BasicPress) && !game.IsExpectingInputNow(ClappyTrio.InputAction_BasicPress.inputLockCategory))
{
Clap(false);
game.ScoreMiss();
}
}
public void QueueClap(double startBeat, float length)
{
lastClapBeat = startBeat;
lastClapLength = length;
game.ScheduleInput(startBeat, length, ClappyTrio.InputAction_BasicPress, Just, Miss, Out);
}
private void Just(PlayerActionEvent caller, float state)
{
if (!canHit) {
Clap(false);
return;
}
if (state >= 1f || state <= -1f) { //todo: proper near miss feedback
Clap(false);
return;
2022-02-05 20:28:04 +00:00
}
Clap(true);
2022-02-05 20:28:04 +00:00
}
2021-12-25 02:37:03 +00:00
private void Miss(PlayerActionEvent caller) {
game.misses++;
game.emoCounter = 2;
if (clapStarted)
this.canHit = false;
}
private void Out(PlayerActionEvent caller) {}
private void Clap(bool just)
{
game.emoCounter = 2;
if (just)
{
2021-12-24 03:36:16 +00:00
clapEffect.SetActive(true);
SoundByte.PlayOneShotGame("clappyTrio/rightClap");
}
else
{
2021-12-24 03:36:16 +00:00
clapEffect.SetActive(false);
SoundByte.PlayOneShot("miss");
game.misses++;
2021-12-24 03:36:16 +00:00
if (clapStarted)
this.canHit = false;
}
clapStarted = false;
game.SetFace(game.Lion.Count - 1, 4);
this.GetComponent<Animator>().Play("Clap", 0, 0);
}
}
}