From 94f0c09d71df6ff0560f6fe348f3eec383a293ce Mon Sep 17 00:00:00 2001 From: Carson Kompon Date: Mon, 28 Feb 2022 12:17:50 -0500 Subject: [PATCH] Added Tap, Double Tap, and Triple Tap to Tap Trial All perfectly playable :) Hopefully this is up to standards with the other games I just wanted to do this to prove to myself that I could LOL --- Assets/Resources/Games/tapTrial.prefab | 108 +++++++++++++++++- Assets/Scripts/Games/TapTrial/Tap.cs | 62 ++++++++++ Assets/Scripts/Games/TapTrial/Tap.cs.meta | 11 ++ Assets/Scripts/Games/TapTrial/TapTrial.cs | 52 ++++----- .../Scripts/Games/TapTrial/TapTrialPlayer.cs | 34 +++++- 5 files changed, 234 insertions(+), 33 deletions(-) create mode 100644 Assets/Scripts/Games/TapTrial/Tap.cs create mode 100644 Assets/Scripts/Games/TapTrial/Tap.cs.meta diff --git a/Assets/Resources/Games/tapTrial.prefab b/Assets/Resources/Games/tapTrial.prefab index 6e243b6e..122d7933 100644 --- a/Assets/Resources/Games/tapTrial.prefab +++ b/Assets/Resources/Games/tapTrial.prefab @@ -113,7 +113,7 @@ Transform: m_LocalScale: {x: 2.166603, y: 2.22111, z: 1} m_Children: [] m_Father: {fileID: 2907041458994465612} - m_RootOrder: 4 + m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &2108081423830504772 SpriteRenderer: @@ -236,6 +236,19 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 6892e03a2f2994b48a4b076fdfae805d, type: 3} m_Name: m_EditorClassIdentifier: + inList: 0 + lastState: 0 + state: + gameObject: {fileID: 0} + early: 0 + perfect: 0 + late: 0 + createBeat: 0 + eligibleHitsList: [] + aceTimes: 0 + isEligible: 0 + triggersAutoplay: 1 + nextBeat: 0 --- !u!1 &335036550381843476 GameObject: m_ObjectHideFlags: 0 @@ -564,6 +577,62 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 +--- !u!1 &1588738713562392816 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 5208471493270040557} + - component: {fileID: 6245594884647355465} + m_Layer: 0 + m_Name: Tap + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 0 +--- !u!4 &5208471493270040557 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1588738713562392816} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 6495189186508343095} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &6245594884647355465 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1588738713562392816} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 01f0b70cc14be2e47998a680099e7986, type: 3} + m_Name: + m_EditorClassIdentifier: + inList: 0 + lastState: 0 + state: + gameObject: {fileID: 0} + early: 0 + perfect: 0 + late: 0 + createBeat: 0 + eligibleHitsList: [] + aceTimes: 0 + isEligible: 0 + triggersAutoplay: 1 + startBeat: 0 --- !u!1 &2036719006303025046 GameObject: m_ObjectHideFlags: 0 @@ -876,6 +945,7 @@ Transform: - {fileID: 2447600723971154318} - {fileID: 6128063303297303287} - {fileID: 7656869706203293275} + - {fileID: 6495189186508343095} - {fileID: 6660332389952895749} - {fileID: 7667021380834212371} - {fileID: 7618359020666823781} @@ -897,6 +967,7 @@ MonoBehaviour: EligibleHits: [] firstEnable: 0 player: {fileID: 3802388599767290996} + tap: {fileID: 1588738713562392816} --- !u!1 &3076910857648561258 GameObject: m_ObjectHideFlags: 0 @@ -926,7 +997,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 2907041458994465612} - m_RootOrder: 5 + m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &8011646622740663204 SpriteRenderer: @@ -1666,7 +1737,7 @@ Transform: m_LocalScale: {x: 2.136603, y: 2.2011096, z: 1} m_Children: [] m_Father: {fileID: 2907041458994465612} - m_RootOrder: 3 + m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &6120332165088402499 SpriteRenderer: @@ -2164,3 +2235,34 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 +--- !u!1 &8537406413473122392 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6495189186508343095} + m_Layer: 0 + m_Name: Beats + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6495189186508343095 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8537406413473122392} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 5208471493270040557} + m_Father: {fileID: 2907041458994465612} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Scripts/Games/TapTrial/Tap.cs b/Assets/Scripts/Games/TapTrial/Tap.cs new file mode 100644 index 00000000..66535026 --- /dev/null +++ b/Assets/Scripts/Games/TapTrial/Tap.cs @@ -0,0 +1,62 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +using RhythmHeavenMania.Util; + +namespace RhythmHeavenMania.Games.TapTrial +{ + public class Tap : PlayerActionObject + { + public float startBeat; + + public int type; + + // Start is called before the first frame update + void Start() + { + PlayerActionInit(this.gameObject, startBeat); + } + + public override void OnAce() + { + Hit(true); + } + + // Update is called once per frame + void Update() + { + if (Conductor.instance.GetPositionFromBeat(startBeat, 2) >= 1) + CleanUp(); + + float normalizedBeat = Conductor.instance.GetPositionFromBeat(startBeat, 1f); + StateCheck(normalizedBeat); + + if(PlayerInput.Pressed()) + { + if(state.perfect) + { + Hit(true); + } + else if(state.notPerfect()) + { + Hit(false); + } + } + + } + + public void Hit(bool hit) + { + TapTrial.instance.player.Tap(hit, type); + + if (hit) + CleanUp(); + } + + public void CleanUp() + { + Destroy(this.gameObject); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Games/TapTrial/Tap.cs.meta b/Assets/Scripts/Games/TapTrial/Tap.cs.meta new file mode 100644 index 00000000..7d4a132e --- /dev/null +++ b/Assets/Scripts/Games/TapTrial/Tap.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 01f0b70cc14be2e47998a680099e7986 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Games/TapTrial/TapTrial.cs b/Assets/Scripts/Games/TapTrial/TapTrial.cs index 26dca1e3..b3755991 100644 --- a/Assets/Scripts/Games/TapTrial/TapTrial.cs +++ b/Assets/Scripts/Games/TapTrial/TapTrial.cs @@ -10,6 +10,7 @@ namespace RhythmHeavenMania.Games.TapTrial { [Header("References")] public TapTrialPlayer player; + public GameObject tap; public static TapTrial instance { get; set; } @@ -22,19 +23,10 @@ namespace RhythmHeavenMania.Games.TapTrial public void Tap(float beat) { - MultiSound.Play(new MultiSound.Sound[] - { - new MultiSound.Sound("tapTrial/ook", beat), - new MultiSound.Sound("tapTrial/tap", beat + 1.0f), - }); + Jukebox.PlayOneShotGame("tapTrial/ook"); + player.anim.Play("TapPrepare", 0, 0); - GameObject beatAction = new GameObject(); - beatAction.transform.SetParent(this.transform); - BeatAction.New(beatAction, new List() - { - new BeatAction.Action(beat + 0.0f, delegate { player.anim.Play("TapPrepare", 0, 0); }), - new BeatAction.Action(beat + 1.0f, delegate { player.anim.Play("Tap", 0, 0); }), - }); + CreateTap(beat); } public void DoubleTap(float beat) @@ -42,18 +34,17 @@ namespace RhythmHeavenMania.Games.TapTrial MultiSound.Play(new MultiSound.Sound[] { new MultiSound.Sound("tapTrial/ookook", beat), - new MultiSound.Sound("tapTrial/ookook", beat + 0.5f), - new MultiSound.Sound("tapTrial/tap", beat + 1.0f), - new MultiSound.Sound("tapTrial/tap", beat + 1.5f), + new MultiSound.Sound("tapTrial/ookook", beat + 0.5f) }); + player.anim.Play("DoubleTapPrepare", 0, 0); + GameObject beatAction = new GameObject(); beatAction.transform.SetParent(this.transform); BeatAction.New(beatAction, new List() { - new BeatAction.Action(beat + 0.0f, delegate { player.anim.Play("DoubleTapPrepare", 0, 0); }), - new BeatAction.Action(beat + 1.0f, delegate { player.anim.Play("DoubleTap", 0, 0); }), - new BeatAction.Action(beat + 1.5f, delegate { player.anim.Play("DoubleTap", 0, 0); }), + new BeatAction.Action(beat + 0.0f, delegate { CreateTap(beat, 1); }), + new BeatAction.Action(beat + 0.5f, delegate { CreateTap(beat + 0.5f, 1); }), }); } @@ -62,20 +53,19 @@ namespace RhythmHeavenMania.Games.TapTrial MultiSound.Play(new MultiSound.Sound[] { new MultiSound.Sound("tapTrial/ooki1", beat), - new MultiSound.Sound("tapTrial/ooki2", beat + 0.5f), - new MultiSound.Sound("tapTrial/tap", beat + 2.0f), - new MultiSound.Sound("tapTrial/tap", beat + 2.5f), - new MultiSound.Sound("tapTrial/tap", beat + 3.0f), + new MultiSound.Sound("tapTrial/ooki2", beat + 0.5f) }); + player.anim.Play("PosePrepare", 0, 0); + player.tripleOffset = 0; + GameObject beatAction = new GameObject(); beatAction.transform.SetParent(this.transform); BeatAction.New(beatAction, new List() { - new BeatAction.Action(beat + 0.0f, delegate { player.anim.Play("PosePrepare", 0, 0); }), - new BeatAction.Action(beat + 2.0f, delegate { player.anim.Play("Tap", 0, 0); }), - new BeatAction.Action(beat + 2.5f, delegate { player.anim.Play("DoubleTap", 0, 0); }), - new BeatAction.Action(beat + 3.0f, delegate { player.anim.Play("Tap", 0, 0); }), + new BeatAction.Action(beat + 1.0f, delegate { CreateTap(beat + 1.0f, 2); }), + new BeatAction.Action(beat + 1.5f, delegate { CreateTap(beat + 1.5f, 2); }), + new BeatAction.Action(beat + 2.0f, delegate { CreateTap(beat + 2.0f, 2); }), }); } @@ -88,5 +78,15 @@ namespace RhythmHeavenMania.Games.TapTrial { } + + public void CreateTap(float beat, int type = 0) + { + GameObject _tap = Instantiate(tap); + _tap.transform.parent = tap.transform.parent; + _tap.SetActive(true); + Tap t = _tap.GetComponent(); + t.startBeat = beat; + t.type = type; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Games/TapTrial/TapTrialPlayer.cs b/Assets/Scripts/Games/TapTrial/TapTrialPlayer.cs index 1dff7441..14297301 100644 --- a/Assets/Scripts/Games/TapTrial/TapTrialPlayer.cs +++ b/Assets/Scripts/Games/TapTrial/TapTrialPlayer.cs @@ -9,6 +9,9 @@ namespace RhythmHeavenMania.Games.TapTrial [Header("References")] [System.NonSerialized] public Animator anim; + public float nextBeat; + public int tripleOffset = 0; + private void Start() { anim = GetComponent(); @@ -16,16 +19,39 @@ namespace RhythmHeavenMania.Games.TapTrial private void Update() { + float normalizedBeat = Conductor.instance.GetPositionFromMargin(nextBeat, 1f); + + if (PlayerInput.Pressed()) { - Tap(false); + Tap(false, 0); } } - public void Tap(bool hit) + public void Tap(bool hit, int type) { - Jukebox.PlayOneShotGame("tapTrial/tonk"); - anim.Play("Tap", 0, 0); + if (hit) + Jukebox.PlayOneShotGame("tapTrial/tap"); + else + Jukebox.PlayOneShotGame("tapTrial/tonk"); + + + switch (type) + { + case 0: + anim.Play("Tap", 0, 0); + break; + case 1: + anim.Play("DoubleTap", 0, 0); + break; + case 2: + if(tripleOffset % 2 == 0) + anim.Play("DoubleTap", 0, 0); + else + anim.Play("Tap", 0, 0); + tripleOffset++; + break; + } } } } \ No newline at end of file