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

90 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 : PlayerActionObject
{
ClappyTrio game;
private float 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.Pressed() && !game.IsExpectingInputNow(InputType.STANDARD_DOWN))
{
Clap(false);
game.ScoreMiss();
}
}
public void QueueClap(float startBeat, float length)
{
lastClapBeat = startBeat;
lastClapLength = length;
game.ScheduleInput(startBeat, length, InputType.STANDARD_DOWN, 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.playerHitLast = false;
if (clapStarted)
this.canHit = false;
}
private void Out(PlayerActionEvent caller) {}
private void Clap(bool just)
{
if (just)
{
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)
game.playerHitLast = true;
}
else
{
2021-12-24 03:36:16 +00:00
clapEffect.SetActive(false);
Jukebox.PlayOneShot("miss");
game.playerHitLast = false;
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);
}
}
}