Fixed problem with Trio faces not changing

This commit is contained in:
Starpelly
2021-12-23 19:58:48 -05:00
parent 88d23ef8cc
commit aa3f999721
15 changed files with 667 additions and 29 deletions

52
Assets/Scripts/DebugUI.cs Normal file
View File

@ -0,0 +1,52 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
// hardcoded because im lazy
namespace RhythmHeavenMania
{
public class DebugUI : MonoBehaviour
{
public GameObject Template;
private TMP_Text SongPosBeats;
private TMP_Text BPM;
private TMP_Text currEvent;
private void Start()
{
for (int i = 0; i < 3; i++)
{
GameObject debug = Instantiate(Template, Template.transform.parent);
debug.SetActive(true);
debug.transform.localPosition = new Vector3(Template.transform.localPosition.x, Template.transform.localPosition.y - 44.9301f * i);
switch (i)
{
case 0:
SongPosBeats = debug.transform.GetChild(0).GetComponent<TMP_Text>();
break;
case 1:
BPM = debug.transform.GetChild(0).GetComponent<TMP_Text>();
break;
case 2:
currEvent = debug.transform.GetChild(0).GetComponent<TMP_Text>();
break;
}
}
}
private void Update()
{
SongPosBeats.text = $"SongPosBeats: {Conductor.instance.songPositionInBeats}";
BPM.text = $"BPM: {Conductor.instance.songBpm}";
if (GameManager.instance.currentEvent - 1 >= 0)
currEvent.text = $"CurrentEvent: {GameManager.instance.Beatmap.entities[GameManager.instance.currentEvent - 1].datamodel}";
else
currEvent.text = $"CurrentEvent: {GameManager.instance.Beatmap.entities[GameManager.instance.currentEvent].datamodel}";
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 667da2762ac6e314c91fe7636f4ff3cf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -73,9 +73,10 @@ namespace RhythmHeavenMania
// Claps
new GameAction("clap", delegate { ClappyTrio.instance.Clap(currentBeat, currentLength); }, true ),
new GameAction("bop", delegate { ClappyTrio.instance.Bop(); }, true ),
new GameAction("prepare_0", delegate { ClappyTrio.instance.Prepare(0); }, true ),
new GameAction("prepare_4", delegate { ClappyTrio.instance.Prepare(4); }, true ),
new GameAction("prepare", delegate { ClappyTrio.instance.Prepare(0); }, true ),
new GameAction("prepare_alt", delegate { ClappyTrio.instance.Prepare(3); }, true ),
})
};

View File

@ -58,6 +58,16 @@ namespace RhythmHeavenMania
if (Beatmap.entities.Count < 1)
return;
if (Input.GetKeyDown(KeyCode.A))
{
Conductor.instance.musicSource.time += 3;
}
else if (Input.GetKeyDown(KeyCode.S))
{
Conductor.instance.musicSource.time -= 3;
GameManager.instance.SetCurrentEventToClosest();
}
List<float> entities = Beatmap.entities.Select(c => c.beat).ToList();
if (currentEvent < Beatmap.entities.Count && currentEvent >= 0)

View File

@ -0,0 +1,16 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RhythmHeavenMania
{
public class GameProperties
{
public class Latency
{
public static float early = 0.71f;
public static float perfect = 0.74f;
public static float late = 0.84f;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2446058906fa02d478d3d3307954f70b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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];
}
}
}

View 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);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 301b662d20e353048bac2801dc41a3f7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -76,16 +76,6 @@ namespace RhythmHeavenMania.Games.ForkLifter
{
currentHitInList = 0;
}
if (Input.GetKeyDown(KeyCode.A))
{
Conductor.instance.musicSource.time += 3;
}
else if (Input.GetKeyDown(KeyCode.S))
{
Conductor.instance.musicSource.time -= 3;
GameManager.instance.SetCurrentEventToClosest();
}
}
public void Eat()

View File

@ -0,0 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RhythmHeavenMania
{
public class PlayerInput
{
public static bool Pressed()
{
return (Input.GetKeyDown(KeyCode.Z) || Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0));
}
public static bool Pressing()
{
return (Input.GetKey(KeyCode.Z) || Input.GetKey(KeyCode.Space) || Input.GetMouseButton(0));
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9503627b14bba414cae0fbc5da9e4120
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: