mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 11:47:38 +02:00
Fixed problem with Trio faces not changing
This commit is contained in:
@ -13,12 +13,18 @@ namespace RhythmHeavenMania.Games.ClappyTrio
|
||||
private GameObject LionPlayer;
|
||||
|
||||
[SerializeField] private Sprite[] faces;
|
||||
public SpriteRenderer lionHeadLeft, lionHeadMiddle, lionHeadPlayer;
|
||||
|
||||
private bool isClapping;
|
||||
private float currentClappingLength;
|
||||
private float lastClapStart;
|
||||
private int clapIndex;
|
||||
|
||||
private ClappyTrioPlayer ClappyTrioPlayer;
|
||||
|
||||
public bool playerHitLast = false;
|
||||
|
||||
|
||||
public static ClappyTrio instance { get; set; }
|
||||
|
||||
private void Awake()
|
||||
@ -33,6 +39,12 @@ namespace RhythmHeavenMania.Games.ClappyTrio
|
||||
|
||||
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>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@ -43,6 +55,7 @@ namespace RhythmHeavenMania.Games.ClappyTrio
|
||||
|
||||
if (songPosBeat > lastClapStart && songPosBeat < lastClapStart + 1 && clapIndex == 0)
|
||||
{
|
||||
SetFace(0, 4);
|
||||
LionLeft.GetComponent<Animator>().Play("Clap", 0, 0);
|
||||
Jukebox.PlayOneShotGame("clappyTrio/leftClap");
|
||||
|
||||
@ -50,23 +63,26 @@ namespace RhythmHeavenMania.Games.ClappyTrio
|
||||
}
|
||||
else if (songPosBeat > lastClapStart + currentClappingLength && songPosBeat < lastClapStart + (currentClappingLength * 2) && clapIndex == 1)
|
||||
{
|
||||
SetFace(1, 4);
|
||||
LionMiddle.GetComponent<Animator>().Play("Clap", 0, 0);
|
||||
Jukebox.PlayOneShotGame("clappyTrio/middleClap");
|
||||
|
||||
clapIndex++;
|
||||
}
|
||||
else if (songPosBeat > lastClapStart + (currentClappingLength * 2) && clapIndex == 2)
|
||||
else if (songPosBeat > lastClapStart + (currentClappingLength * 2 - 0.35f) && clapIndex == 2)
|
||||
{
|
||||
LionPlayer.GetComponent<Animator>().Play("Clap", 0, 0);
|
||||
Jukebox.PlayOneShotGame("clappyTrio/rightClap");
|
||||
ClappyTrioPlayer.SetClapAvailability(lastClapStart + (currentClappingLength * 2 - 0.35f));
|
||||
|
||||
clapIndex++;
|
||||
clapIndex = 0;
|
||||
isClapping = false;
|
||||
currentClappingLength = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Clap(float beat, float length)
|
||||
{
|
||||
playerHitLast = false;
|
||||
isClapping = true;
|
||||
lastClapStart = beat;
|
||||
currentClappingLength = length;
|
||||
@ -74,11 +90,22 @@ namespace RhythmHeavenMania.Games.ClappyTrio
|
||||
|
||||
public void Prepare(int type)
|
||||
{
|
||||
PlayAnimationAll("Prepare");
|
||||
Jukebox.PlayOneShotGame("clappyTrio/ready");
|
||||
SetFace(0, type);
|
||||
SetFace(1, type);
|
||||
SetFace(2, type);
|
||||
PlayAnimationAll("Prepare");
|
||||
Jukebox.PlayOneShotGame("clappyTrio/ready");
|
||||
}
|
||||
|
||||
public void Bop()
|
||||
{
|
||||
if (playerHitLast)
|
||||
{
|
||||
SetFace(0, 1);
|
||||
SetFace(1, 1);
|
||||
SetFace(2, 1);
|
||||
}
|
||||
PlayAnimationAll("Bop");
|
||||
}
|
||||
|
||||
private void PlayAnimationAll(string anim)
|
||||
@ -88,14 +115,14 @@ namespace RhythmHeavenMania.Games.ClappyTrio
|
||||
LionPlayer.GetComponent<Animator>().Play(anim, 0, 0);
|
||||
}
|
||||
|
||||
private void SetFace(int lion, int type)
|
||||
public void SetFace(int lion, int type)
|
||||
{
|
||||
if (lion == 0)
|
||||
LionLeft.transform.GetChild(1).GetComponent<SpriteRenderer>().sprite = faces[type];
|
||||
else if (lion == 1)
|
||||
LionMiddle.transform.GetChild(1).GetComponent<SpriteRenderer>().sprite = faces[type];
|
||||
else if (lion == 3)
|
||||
LionPlayer.transform.GetChild(1).GetComponent<SpriteRenderer>().sprite = faces[type];
|
||||
lionHeadLeft.sprite = faces[type];
|
||||
if (lion == 1)
|
||||
lionHeadMiddle.sprite = faces[type];
|
||||
if (lion == 2)
|
||||
lionHeadPlayer.sprite = faces[type];
|
||||
}
|
||||
}
|
||||
}
|
95
Assets/Scripts/Games/ClappyTrio/ClappyTrioPlayer.cs
Normal file
95
Assets/Scripts/Games/ClappyTrio/ClappyTrioPlayer.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
using RhythmHeavenMania.Util;
|
||||
|
||||
namespace RhythmHeavenMania.Games.ClappyTrio
|
||||
{
|
||||
public class ClappyTrioPlayer : MonoBehaviour
|
||||
{
|
||||
public bool early;
|
||||
public bool perfect;
|
||||
public bool late;
|
||||
|
||||
private float lastClapBeat;
|
||||
private bool clapVacant;
|
||||
|
||||
private int lastIndex;
|
||||
|
||||
private float perfectTime = 0.25f, lateTime = 0.46f;
|
||||
|
||||
private bool hit;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (PlayerInput.Pressed())
|
||||
{
|
||||
Clap();
|
||||
}
|
||||
|
||||
if (clapVacant == true)
|
||||
{
|
||||
float songPosBeat = Conductor.instance.songPositionInBeats;
|
||||
|
||||
if (songPosBeat > lastClapBeat && songPosBeat < lastClapBeat + perfectTime && lastIndex == 0)
|
||||
{
|
||||
SetEligibility(true, false, false);
|
||||
lastIndex++;
|
||||
}
|
||||
else if (songPosBeat > lastClapBeat + perfectTime && songPosBeat < lastClapBeat + lateTime && lastIndex == 1)
|
||||
{
|
||||
SetEligibility(false, true, false);
|
||||
// Clap();
|
||||
lastIndex++;
|
||||
}
|
||||
else if (songPosBeat > lastClapBeat + lateTime && lastIndex == 2)
|
||||
{
|
||||
SetEligibility(false, false, true);
|
||||
clapVacant = false;
|
||||
lastIndex = 0;
|
||||
hit = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetClapAvailability(float startBeat)
|
||||
{
|
||||
lastClapBeat = startBeat;
|
||||
clapVacant = true;
|
||||
}
|
||||
|
||||
private void SetEligibility(bool early, bool perfect, bool late)
|
||||
{
|
||||
this.early = false;
|
||||
this.perfect = false;
|
||||
this.late = false;
|
||||
|
||||
if (early)
|
||||
this.early = true;
|
||||
else if (perfect)
|
||||
this.perfect = true;
|
||||
else if (late)
|
||||
this.late = true;
|
||||
}
|
||||
|
||||
private void Clap()
|
||||
{
|
||||
bool canHit = early != true && late != true && perfect == true && hit == false;
|
||||
|
||||
if (canHit)
|
||||
{
|
||||
Jukebox.PlayOneShotGame("clappyTrio/rightClap");
|
||||
ClappyTrio.instance.playerHitLast = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Jukebox.PlayOneShot("miss");
|
||||
ClappyTrio.instance.playerHitLast = false;
|
||||
}
|
||||
|
||||
ClappyTrio.instance.SetFace(2, 4);
|
||||
this.GetComponent<Animator>().Play("Clap", 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Games/ClappyTrio/ClappyTrioPlayer.cs.meta
Normal file
11
Assets/Scripts/Games/ClappyTrio/ClappyTrioPlayer.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 301b662d20e353048bac2801dc41a3f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user