From 6c0d780576476f806679cce244f9a855c852d823 Mon Sep 17 00:00:00 2001 From: Rapandrasmus <78219215+Rapandrasmus@users.noreply.github.com> Date: Thu, 22 Jun 2023 00:15:33 +0200 Subject: [PATCH] Height changes added --- .../Games/NightWalkAgb/JumpPlatform.prefab | 1 + .../Games/NightWalkAgb/AgbNightWalk.cs | 20 +++++++++++ .../Scripts/Games/NightWalkAgb/AgbPlatform.cs | 25 ++++++++++++- .../Games/NightWalkAgb/AgbPlatformHandler.cs | 35 +++++++++++++++++-- 4 files changed, 78 insertions(+), 3 deletions(-) diff --git a/Assets/Resources/Prefabs/Games/NightWalkAgb/JumpPlatform.prefab b/Assets/Resources/Prefabs/Games/NightWalkAgb/JumpPlatform.prefab index ef694cd6e..bc96cc1b6 100644 --- a/Assets/Resources/Prefabs/Games/NightWalkAgb/JumpPlatform.prefab +++ b/Assets/Resources/Prefabs/Games/NightWalkAgb/JumpPlatform.prefab @@ -131,6 +131,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 2b6892a770a77394ca687ef93f8935db, type: 3} m_Name: m_EditorClassIdentifier: + platform: {fileID: 8602790381015410525} --- !u!95 &4653690538679061971 Animator: serializedVersion: 5 diff --git a/Assets/Scripts/Games/NightWalkAgb/AgbNightWalk.cs b/Assets/Scripts/Games/NightWalkAgb/AgbNightWalk.cs index aa3b8cc4c..1ac27a191 100644 --- a/Assets/Scripts/Games/NightWalkAgb/AgbNightWalk.cs +++ b/Assets/Scripts/Games/NightWalkAgb/AgbNightWalk.cs @@ -23,6 +23,13 @@ namespace HeavenStudio.Games.Loaders { new Param("mute", false, "Mute Cowbell") } + }, + new GameAction("height", "Platform Height") + { + parameters = new List() + { + new Param("value", new EntityTypes.Integer(-10, 10, 1), "Height Units") + } } }); } @@ -41,6 +48,7 @@ namespace HeavenStudio.Games [NonSerialized] public double countInBeat = -1; [Header("Curves")] [SerializeField] SuperCurveObject.Path[] jumpPaths; + [NonSerialized] public Dictionary platformHeightChanges = new Dictionary(); new void OnDrawGizmos() { @@ -69,6 +77,18 @@ namespace HeavenStudio.Games private void Awake() { instance = this; + List heightEvents = EventCaller.GetAllInGameManagerList("nightWalkAgb", new string[] { "height" }); + foreach (var height in heightEvents) + { + if (platformHeightChanges.ContainsKey(height.beat)) + { + platformHeightChanges[height.beat]["value"] += height["value"]; + } + else + { + platformHeightChanges.Add(height.beat, height); + } + } } public override void OnGameSwitch(double beat) diff --git a/Assets/Scripts/Games/NightWalkAgb/AgbPlatform.cs b/Assets/Scripts/Games/NightWalkAgb/AgbPlatform.cs index efc1d342f..21fcf2d52 100644 --- a/Assets/Scripts/Games/NightWalkAgb/AgbPlatform.cs +++ b/Assets/Scripts/Games/NightWalkAgb/AgbPlatform.cs @@ -23,8 +23,30 @@ namespace HeavenStudio.Games.Scripts_AgbNightWalk private PlatformType type = PlatformType.Flower; + private float additionalHeight = 0f; + private int additionalHeightInUnits = 0; + private int lastAdditionalHeightInUnits = 0; + + [SerializeField] private GameObject platform; + public void StartInput(double beat, double hitBeat) { + if (game == null) game = AgbNightWalk.instance; + if (game.platformHeightChanges.ContainsKey(hitBeat)) + { + handler.defaultHeightUnits += game.platformHeightChanges[hitBeat]["value"]; + } + lastAdditionalHeightInUnits = handler.defaultHeightUnits; + additionalHeight = handler.defaultHeightUnits * handler.heightAmount; + if (game.platformHeightChanges.ContainsKey(hitBeat + 1)) + { + additionalHeightInUnits = lastAdditionalHeightInUnits + game.platformHeightChanges[hitBeat + 1]["value"]; + } + else + { + additionalHeightInUnits = lastAdditionalHeightInUnits; + } + platform.SetActive(!game.platformHeightChanges.ContainsKey(hitBeat + 1)); startBeat = beat; endBeat = hitBeat; if (startBeat < endBeat) @@ -49,7 +71,7 @@ namespace HeavenStudio.Games.Scripts_AgbNightWalk float newPosX = Mathf.LerpUnclamped(handler.playerXPos + (float)((endBeat - startBeat) * handler.platformDistance), handler.playerXPos, normalizedBeat); - transform.localPosition = new Vector3(newPosX, handler.defaultYPos); + transform.localPosition = new Vector3(newPosX, handler.defaultYPos + additionalHeight); if (cond.songPositionInBeats > endBeat + (handler.platformCount * 0.5f)) { @@ -66,6 +88,7 @@ namespace HeavenStudio.Games.Scripts_AgbNightWalk } private void Just(PlayerActionEvent caller, float state) { + handler.RaiseHeight(Conductor.instance.songPositionInBeats, lastAdditionalHeightInUnits, additionalHeightInUnits); game.playYan.Jump(Conductor.instance.songPositionInBeats); if (state >= 1 || state <= -1) { diff --git a/Assets/Scripts/Games/NightWalkAgb/AgbPlatformHandler.cs b/Assets/Scripts/Games/NightWalkAgb/AgbPlatformHandler.cs index d45865160..ec6f7ec43 100644 --- a/Assets/Scripts/Games/NightWalkAgb/AgbPlatformHandler.cs +++ b/Assets/Scripts/Games/NightWalkAgb/AgbPlatformHandler.cs @@ -1,3 +1,4 @@ +using HeavenStudio.Util; using System; using System.Collections; using System.Collections.Generic; @@ -11,10 +12,15 @@ namespace HeavenStudio.Games.Scripts_AgbNightWalk [Header("Properties")] [SerializeField] private AgbPlatform platformRef; public float defaultYPos = -11.76f; + public float heightAmount = 2; + [NonSerialized] public int defaultHeightUnits = 0; public float platformDistance = 3.80f; public float playerXPos = -6.78f; [Range(1, 100)] public int platformCount = 20; + private float lastHeight = 0; + private float heightToRaiseTo = 0; + private double raiseBeat = -1; private void Awake() { @@ -28,8 +34,8 @@ namespace HeavenStudio.Games.Scripts_AgbNightWalk for (int i = 0; i < platformCount; i++) { AgbPlatform platform = Instantiate(platformRef, transform); - platform.StartInput(game.countInBeat + i + 8 - (platformCount * 0.5), game.countInBeat + i + 8); platform.handler = this; + platform.StartInput(game.countInBeat + i + 8 - (platformCount * 0.5), game.countInBeat + i + 8); platform.gameObject.SetActive(true); } } @@ -38,12 +44,37 @@ namespace HeavenStudio.Games.Scripts_AgbNightWalk for (int i = 0; i < platformCount; i++) { AgbPlatform platform = Instantiate(platformRef, transform); - platform.StartInput(Math.Ceiling(beat) + i - (platformCount * 1.5), Math.Ceiling(beat) + i - platformCount); platform.handler = this; + platform.StartInput(Math.Ceiling(beat) + i - (platformCount * 1.5), Math.Ceiling(beat) + i - platformCount); platform.gameObject.SetActive(true); } } } + + private void Update() + { + var cond = Conductor.instance; + if (cond.isPlaying && !cond.isPaused) + { + if (raiseBeat != -1) + { + float normalizedBeat = Mathf.Clamp(cond.GetPositionFromBeat(raiseBeat, 1), 0, 1); + EasingFunction.Function func = EasingFunction.GetEasingFunction(EasingFunction.Ease.EaseOutQuint); + + float newPosY = func(lastHeight, heightToRaiseTo, normalizedBeat); + + transform.localPosition = new Vector3(0, -newPosY, 0); + } + } + } + + public void RaiseHeight(double beat, int lastUnits, int currentUnits) + { + raiseBeat = beat; + lastHeight = lastUnits * heightAmount * transform.localScale.y; + heightToRaiseTo = currentUnits * heightAmount * transform.localScale.y; + Update(); + } } }