From 4f904c99c21221684c83b9ff54c0267b7f3f102a Mon Sep 17 00:00:00 2001 From: Rapandrasmus <78219215+Rapandrasmus@users.noreply.github.com> Date: Wed, 21 Jun 2023 20:12:45 +0200 Subject: [PATCH] Got em inputs in nightwalk gba to work --- Assets/Resources/Games/nightWalkAgb.prefab | 1 + .../Games/NightWalkAgb/JumpPlatform.prefab | 2 +- .../Games/NightWalkAgb/AgbNightWalk.cs | 11 +++- .../Scripts/Games/NightWalkAgb/AgbPlatform.cs | 55 +++++++++++++++++++ .../Games/NightWalkAgb/AgbPlatformHandler.cs | 25 +++++++++ 5 files changed, 91 insertions(+), 3 deletions(-) diff --git a/Assets/Resources/Games/nightWalkAgb.prefab b/Assets/Resources/Games/nightWalkAgb.prefab index 33ad02d08..49b9ac467 100644 --- a/Assets/Resources/Games/nightWalkAgb.prefab +++ b/Assets/Resources/Games/nightWalkAgb.prefab @@ -680,6 +680,7 @@ MonoBehaviour: scheduledInputs: [] firstEnable: 0 playYan: {fileID: 1314280037714680423} + platformHandler: {fileID: 6715217060937385611} --- !u!1 &4465275889429203320 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Resources/Prefabs/Games/NightWalkAgb/JumpPlatform.prefab b/Assets/Resources/Prefabs/Games/NightWalkAgb/JumpPlatform.prefab index 277382dd9..a2acb79db 100644 --- a/Assets/Resources/Prefabs/Games/NightWalkAgb/JumpPlatform.prefab +++ b/Assets/Resources/Prefabs/Games/NightWalkAgb/JumpPlatform.prefab @@ -16,7 +16,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!4 &9016694733661613840 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Games/NightWalkAgb/AgbNightWalk.cs b/Assets/Scripts/Games/NightWalkAgb/AgbNightWalk.cs index d0f119ebb..4adce13db 100644 --- a/Assets/Scripts/Games/NightWalkAgb/AgbNightWalk.cs +++ b/Assets/Scripts/Games/NightWalkAgb/AgbNightWalk.cs @@ -37,6 +37,7 @@ namespace HeavenStudio.Games { public static AgbNightWalk instance; [SerializeField] private AgbPlayYan playYan; + [SerializeField] private AgbPlatformHandler platformHandler; [NonSerialized] public double countInBeat = -1; private void Awake() @@ -47,11 +48,13 @@ namespace HeavenStudio.Games public override void OnGameSwitch(double beat) { SetCountInBeat(beat); + platformHandler.SpawnPlatforms(beat); } public override void OnPlay(double beat) { SetCountInBeat(beat); + platformHandler.SpawnPlatforms(beat); } private void SetCountInBeat(double beat) @@ -85,8 +88,11 @@ namespace HeavenStudio.Games tempEvents.Add(countIn); } } - tempEvents.Sort((x, y) => x.beat.CompareTo(y.beat)); - countInBeat = tempEvents[tempEvents.Count - 1].beat; + if (tempEvents.Count > 0) + { + tempEvents.Sort((x, y) => x.beat.CompareTo(y.beat)); + countInBeat = tempEvents[tempEvents.Count - 1].beat; + } } } UpdateBalloons(beat); @@ -136,6 +142,7 @@ namespace HeavenStudio.Games tempEvents.Add(countIn); } } + if (tempEvents.Count == 0) return true; tempEvents.Sort((x, y) => x.beat.CompareTo(y.beat)); return countInEntity == tempEvents[tempEvents.Count - 1]; } diff --git a/Assets/Scripts/Games/NightWalkAgb/AgbPlatform.cs b/Assets/Scripts/Games/NightWalkAgb/AgbPlatform.cs index 9b3d33473..79deccd90 100644 --- a/Assets/Scripts/Games/NightWalkAgb/AgbPlatform.cs +++ b/Assets/Scripts/Games/NightWalkAgb/AgbPlatform.cs @@ -7,7 +7,62 @@ namespace HeavenStudio.Games.Scripts_AgbNightWalk { public class AgbPlatform : MonoBehaviour { + private double startBeat; + private double endBeat; + private AgbPlatformHandler handler; + public void Init(double beat, double hitBeat, AgbPlatformHandler handlerToPut) + { + handler = handlerToPut; + startBeat = beat; + endBeat = hitBeat; + if (startBeat < endBeat) + { + AgbNightWalk.instance.ScheduleInput(startBeat, endBeat - startBeat, InputType.STANDARD_DOWN, Just, Miss, Empty); + } + } + private void Awake() + { + Update(); + } + + private void Update() + { + var cond = Conductor.instance; + if (cond.isPlaying && !cond.isPaused) + { + float normalizedBeat = cond.GetPositionFromBeat(startBeat, endBeat - startBeat); + + float newPosX = Mathf.LerpUnclamped(handler.playerXPos + (float)((endBeat - startBeat) * handler.platformDistance), handler.playerXPos, normalizedBeat); + + transform.localPosition = new Vector3(newPosX, handler.defaultYPos); + + if (cond.songPositionInBeats > endBeat + (handler.platformCount * 0.5f)) + { + ResetInput(); + } + } + } + + private void ResetInput() + { + double newStartBeat = endBeat + (handler.platformCount * 0.5f); + Init(newStartBeat, newStartBeat + (handler.platformCount * 0.5f), handler); + } + private void Just(PlayerActionEvent caller, float state) + { + if (state >= 1 || state <= -1) + { + return; + } + } + + private void Miss(PlayerActionEvent caller) + { + + } + + private void Empty(PlayerActionEvent caller) { } } } diff --git a/Assets/Scripts/Games/NightWalkAgb/AgbPlatformHandler.cs b/Assets/Scripts/Games/NightWalkAgb/AgbPlatformHandler.cs index 1a30b4a93..16cdc7614 100644 --- a/Assets/Scripts/Games/NightWalkAgb/AgbPlatformHandler.cs +++ b/Assets/Scripts/Games/NightWalkAgb/AgbPlatformHandler.cs @@ -6,11 +6,36 @@ namespace HeavenStudio.Games.Scripts_AgbNightWalk { public class AgbPlatformHandler : MonoBehaviour { + private AgbNightWalk game; [Header("Properties")] [SerializeField] private AgbPlatform platformRef; public float defaultYPos = -11.76f; public float platformDistance = 3.80f; public float playerXPos = -6.78f; + [Range(1, 100)] + public int platformCount = 20; + + private void Awake() + { + game = AgbNightWalk.instance; + } + + public void SpawnPlatforms(double beat) + { + if (game.countInBeat != -1) + { + for (int i = 0; i < platformCount; i++) + { + AgbPlatform platform = Instantiate(platformRef, transform); + platform.Init(game.countInBeat + i - (platformCount * 0.5), game.countInBeat + i + 8, this); + platform.gameObject.SetActive(true); + } + } + else + { + + } + } } }