From a04215ab51c7942da54acad29e82a3d20e05c838 Mon Sep 17 00:00:00 2001 From: Rapandrasmus <78219215+Rapandrasmus@users.noreply.github.com> Date: Tue, 3 Oct 2023 15:06:58 +0200 Subject: [PATCH] epic reset --- .../Games/AnimalAcrobat/AcrobatObstacle.cs | 101 ------- .../Games/AnimalAcrobat/AnimalAcrobat.cs | 274 +----------------- 2 files changed, 1 insertion(+), 374 deletions(-) diff --git a/Assets/Scripts/Games/AnimalAcrobat/AcrobatObstacle.cs b/Assets/Scripts/Games/AnimalAcrobat/AcrobatObstacle.cs index 2053393fd..5668cec9c 100644 --- a/Assets/Scripts/Games/AnimalAcrobat/AcrobatObstacle.cs +++ b/Assets/Scripts/Games/AnimalAcrobat/AcrobatObstacle.cs @@ -5,110 +5,9 @@ using HeavenStudio.Util; namespace HeavenStudio.Games.Scripts_AnimalAcrobat { - public enum ObstacleType - { - Elephant, - Giraffe, - Monkeys, - Monkey - } public class AcrobatObstacle : MonoBehaviour { - [Header("Properties")] - [SerializeField] private float holdLength = 2f; - [SerializeField] private float fullRotateAngle = 120f; - [SerializeField] private Animator anim; - [SerializeField] private ObstacleType type; - [SerializeField] private Transform rotatePivot; - private double startBeat = double.MinValue; - private float halfAngle; - private EasingFunction.Function func; - private AnimalAcrobat game; - private void Awake() - { - halfAngle = fullRotateAngle / 2; - func = EasingFunction.GetEasingFunction(EasingFunction.Ease.EaseInOutQuad); - game = AnimalAcrobat.instance; - } - - public void Init(double beat, double gameSwitchBeat) - { - startBeat = beat; - MultiSound.Play(new MultiSound.Sound[] - { - new MultiSound.Sound("animalAcrobat/eek", startBeat + holdLength - 2), - new MultiSound.Sound("animalAcrobat/eek", startBeat + holdLength - 1), - }); - if (type is ObstacleType.Elephant or ObstacleType.Giraffe) - { - bool isElephant = type is ObstacleType.Elephant; - BeatAction.New(this, new List() - { - new BeatAction.Action(startBeat + holdLength - 2, delegate - { - anim.DoScaledAnimationAsync(isElephant ? "ElephantEar" : "GiraffeEar", 0.5f); - }), - new BeatAction.Action(startBeat + holdLength - 1, delegate - { - anim.DoScaledAnimationAsync(isElephant ? "ElephantEar" : "GiraffeEar", 0.5f); - }), - }); - } - game.ScheduleInput(beat - 1, 1, InputType.STANDARD_DOWN, JustHold, Empty, Empty); - Update(); - } - - private void Update() - { - var cond = Conductor.instance; - if (startBeat != double.MinValue) - { - SwingUpdate(cond); - } - } - - private void SwingUpdate(Conductor cond) - { - float normalizedSwingBeat = cond.GetPositionFromBeat(startBeat, holdLength); - float negativeOffset = (normalizedSwingBeat < 0) ? -1 : 0; - float normalizedAdjusted = Mathf.Abs(normalizedSwingBeat % 1); - bool goingRight = (Mathf.Floor(normalizedSwingBeat) + negativeOffset) % 2 == 0; - float dirMult = goingRight ? 1 : -1; - rotatePivot.localEulerAngles = new Vector3(0, 0, func(-halfAngle * dirMult, halfAngle * dirMult, normalizedAdjusted)); - if (type == ObstacleType.Monkeys) anim.DoNormalizedAnimation("WhiteMonkeysSwing", normalizedSwingBeat); - } - - private void JustHold(PlayerActionEvent caller, float state) - { - SoundByte.PlayOneShotGame("animalAcrobat/grab"); - game.ScheduleInput(startBeat, holdLength, InputType.STANDARD_UP, JustRelease, Empty, Empty); - } - - private void JustRelease(PlayerActionEvent caller, float state) - { - double beat = caller.startBeat + caller.timer; - switch (type) - { - case ObstacleType.Giraffe: - SoundByte.PlayOneShotGame("animalAcrobat/giraffeRelease"); - SoundByte.PlayOneShotGame("animalAcrobat/giraffeReleaseLoop", beat, 1, 1, true).SetLoopParams(beat + 4, 0); - MultiSound.Play(new MultiSound.Sound[] - { - new MultiSound.Sound("animalAcrobat/ringOfFireCymbal", beat + 2), - new MultiSound.Sound("animalAcrobat/audienceCheer", beat + 2.25f), - new MultiSound.Sound("animalAcrobat/flip", beat + 3), - new MultiSound.Sound("cymbal", beat + 4) - }); - break; - default: - SoundByte.PlayOneShotGame("animalAcrobat/release"); - SoundByte.PlayOneShotGame("animalAcrobat/flip", beat + 1); - break; - } - } - - private void Empty(PlayerActionEvent caller) { } } } diff --git a/Assets/Scripts/Games/AnimalAcrobat/AnimalAcrobat.cs b/Assets/Scripts/Games/AnimalAcrobat/AnimalAcrobat.cs index eb32c3bcb..c461eb300 100644 --- a/Assets/Scripts/Games/AnimalAcrobat/AnimalAcrobat.cs +++ b/Assets/Scripts/Games/AnimalAcrobat/AnimalAcrobat.cs @@ -43,279 +43,7 @@ namespace HeavenStudio.Games using HeavenStudio.Util; public class AnimalAcrobat : Minigame { - [SerializeField] private float startCameraMoveLength = 3f; - [Header("Elephant")] - [SerializeField] private AcrobatObstacle elephantRef; - [SerializeField] private float elephantDistance; - [SerializeField] private float elephantStart = 0.004f; - [SerializeField] private float elephantHangCameraMoveLength = 2f; - [SerializeField] private float elephantHangMaxDip = 1f; - [SerializeField] private float elephantReleaseMoveLength = 3f; - [Header("Giraffe")] - [SerializeField] private AcrobatObstacle giraffeRef; - [SerializeField] private float giraffeDistance; - [SerializeField] private float giraffeStart; - [SerializeField] private float afterGiraffeExtraDistance; - [Header("Monkeys")] - [SerializeField] private AcrobatObstacle monkeysRef; - [SerializeField] private float monkeysDistance; - [SerializeField] private float monkeysStart; - [Header("One Monkey")] - [SerializeField] private AcrobatObstacle oneMonkeyRef; - [SerializeField] private float oneMonkeyDistance; - [SerializeField] private float oneMonkeyStart; - - private struct QueuedObstacleCameraMove - { - public double startBeat; - public ObstacleType type; - public float GetLength() - { - return type switch - { - ObstacleType.Elephant => 4f, - ObstacleType.Giraffe => 8f, - ObstacleType.Monkeys => 5f, - ObstacleType.Monkey => 3f, - _ => throw new System.NotImplementedException(), - }; - } - - public float GetHoldLength() - { - return type switch - { - ObstacleType.Elephant => 2f, - ObstacleType.Giraffe => 4f, - ObstacleType.Monkeys => 3f, - ObstacleType.Monkey => 1f, - _ => throw new System.NotImplementedException(), - }; - } - } - - private int movesIndex = 0; - private List moves = new(); - private Vector3 lastCameraPos = new Vector3(0, 0, 0); - private EasingFunction.Function funcInOut; - private EasingFunction.Function funcIn; - private EasingFunction.Function funcOut; - - public static AnimalAcrobat instance; - - private void Awake() - { - instance = this; - funcInOut = EasingFunction.GetEasingFunction(EasingFunction.Ease.EaseInOutQuad); - funcIn = EasingFunction.GetEasingFunction(EasingFunction.Ease.EaseInQuad); - funcOut = EasingFunction.GetEasingFunction(EasingFunction.Ease.EaseOutQuad); - } - - private void LateUpdate() - { - var cond = Conductor.instance; - if (cond.isPlaying && !cond.isPaused) - { - CameraMoveUpdate(cond); - } - } - - private void StartJump(double beat) - { - SoundByte.PlayOneShotGame("animalAcrobat/beginningLeap", beat); - } - - #region Camera - private void CameraMoveUpdate(Conductor cond) - { - if (movesIndex >= moves.Count) return; - var currentMove = moves[movesIndex]; - double songBeat = cond.songPositionInBeats; - if (cond.songPositionInBeats > currentMove.startBeat + currentMove.GetLength()) - { - lastCameraPos = GameCamera.additionalPosition; - movesIndex++; - CameraMoveUpdate(cond); - return; - } - - if (movesIndex == 0 && songBeat >= currentMove.startBeat - 1 && songBeat < currentMove.startBeat) - { - float normalizedBeat = cond.GetPositionFromBeat(currentMove.startBeat - 1, 1); - float newPosX = Mathf.Lerp(lastCameraPos.x, startCameraMoveLength, normalizedBeat); - GameCamera.additionalPosition = new Vector3(newPosX, 0, 0); - } - else if (songBeat >= currentMove.startBeat && songBeat < currentMove.startBeat + currentMove.GetHoldLength()) - { - float normalizedBeat = cond.GetPositionFromBeat(currentMove.startBeat, currentMove.GetHoldLength()); - float newPosX = 0; - float newPosY = 0; - switch (currentMove.type) - { - case ObstacleType.Elephant: - if (movesIndex == 0) newPosX = funcInOut(lastCameraPos.x + startCameraMoveLength, lastCameraPos.x + startCameraMoveLength + elephantHangCameraMoveLength, normalizedBeat); - else newPosX = funcInOut(lastCameraPos.x, lastCameraPos.x + elephantHangCameraMoveLength, normalizedBeat); - - if (normalizedBeat <= 0.5f) - { - float normalizedIn = cond.GetPositionFromBeat(currentMove.startBeat, 1); - newPosY = funcIn(0, -elephantHangMaxDip, normalizedIn); - } - else - { - float normalizedOut = cond.GetPositionFromBeat(currentMove.startBeat + 1, 1); - newPosY = funcOut(-elephantHangMaxDip, 0, normalizedOut); - } - break; - case ObstacleType.Giraffe: - break; - case ObstacleType.Monkeys: - break; - case ObstacleType.Monkey: - break; - default: break; - } - GameCamera.additionalPosition = new Vector3(newPosX, newPosY, 0); - } - else if (songBeat >= currentMove.startBeat + currentMove.GetHoldLength()) - { - float normalizedBeat = cond.GetPositionFromBeat(currentMove.startBeat + currentMove.GetHoldLength(), currentMove.GetLength() - currentMove.GetHoldLength()); - float newPosX = 0; - float newPosY = 0; - switch (currentMove.type) - { - case ObstacleType.Elephant: - if (movesIndex == 0) - { - float baseValue = lastCameraPos.x + startCameraMoveLength + elephantHangCameraMoveLength; - newPosX = Mathf.Lerp(baseValue, baseValue + elephantReleaseMoveLength, normalizedBeat); - } - else - { - float baseValue = lastCameraPos.x + elephantHangCameraMoveLength; - newPosX = Mathf.Lerp(baseValue, baseValue + elephantReleaseMoveLength, normalizedBeat); - } - break; - case ObstacleType.Giraffe: - break; - case ObstacleType.Monkeys: - break; - case ObstacleType.Monkey: - break; - default: break; - } - GameCamera.additionalPosition = new Vector3(newPosX, newPosY, 0); - } - } - #endregion - - #region Spawn Animals - public override void OnPlay(double beat) - { - SpawnAnimals(beat); - } - - public override void OnGameSwitch(double beat) - { - SpawnAnimals(beat); - } - - private void SpawnAnimals(double gameSwitchBeat) - { - var animalEvents = EventCaller.GetAllInGameManagerList("animalAcrobat", new string[] { "elephant", "giraffe", "monkeys", "monkeyLong", "monkeyShort"}); - if (animalEvents.Count == 0) return; - animalEvents.Sort((x, y) => x.beat.CompareTo(y.beat)); - double nextBeat = animalEvents[0].beat; - StartJump(nextBeat - 1); - float startPos = animalEvents[0].datamodel switch - { - "animalAcrobat/elephant" => elephantStart - elephantDistance, - "animalAcrobat/giraffe" => giraffeStart - giraffeDistance, - "animalAcrobat/monkeys" => monkeysStart - monkeysDistance, - "animalAcrobat/monkeyLong" => monkeysStart - monkeysDistance, - "animalAcrobat/monkeyShort" => oneMonkeyStart - oneMonkeyDistance, - _ => throw new System.NotImplementedException() - }; - double nextGameSwitchBeat = double.MaxValue; - var allEnds = EventCaller.GetAllInGameManagerList("gameManager", new string[] { "switchGame", "end" }).FindAll(x => x.beat > gameSwitchBeat); - if (allEnds.Count > 0) nextGameSwitchBeat = allEnds[0].beat; - foreach (var animal in animalEvents) - { - if (animal.beat != nextBeat || animal.beat + animal.length <= gameSwitchBeat || animal.beat > nextGameSwitchBeat) continue; - - nextBeat += animal.length; - switch (animal.datamodel) - { - case "animalAcrobat/elephant": - startPos += elephantDistance; - AcrobatObstacle spawnedElephant = Instantiate(elephantRef, transform); - spawnedElephant.transform.position = new Vector3(startPos, 0, 0); - spawnedElephant.Init(animal.beat, gameSwitchBeat); - moves.Add(new QueuedObstacleCameraMove - { - startBeat = animal.beat, - type = ObstacleType.Elephant - }); - break; - case "animalAcrobat/giraffe": - startPos += giraffeDistance; - AcrobatObstacle spawnedGiraffe = Instantiate(giraffeRef, transform); - spawnedGiraffe.transform.position = new Vector3(startPos, 0, 0); - spawnedGiraffe.Init(animal.beat, gameSwitchBeat); - moves.Add(new QueuedObstacleCameraMove - { - startBeat = animal.beat, - type = ObstacleType.Giraffe - }); - startPos += afterGiraffeExtraDistance; - break; - case "animalAcrobat/monkeys": - startPos += monkeysDistance; - AcrobatObstacle spawnedMonkeyLong = Instantiate(monkeysRef, transform); - spawnedMonkeyLong.transform.position = new Vector3(startPos, 0, 0); - spawnedMonkeyLong.Init(animal.beat, gameSwitchBeat); - moves.Add(new QueuedObstacleCameraMove - { - startBeat = animal.beat, - type = ObstacleType.Monkeys - }); - startPos += oneMonkeyDistance; - AcrobatObstacle spawnedOneMonkeyS = Instantiate(oneMonkeyRef, transform); - spawnedOneMonkeyS.transform.position = new Vector3(startPos, 0, 0); - spawnedOneMonkeyS.Init(animal.beat + 5, gameSwitchBeat); - moves.Add(new QueuedObstacleCameraMove - { - startBeat = animal.beat + 5, - type = ObstacleType.Monkey - }); - break; - case "animalAcrobat/monkeyLong": - startPos += monkeysDistance; - AcrobatObstacle spawnedMonkeys = Instantiate(monkeysRef, transform); - spawnedMonkeys.transform.position = new Vector3(startPos, 0, 0); - spawnedMonkeys.Init(animal.beat, gameSwitchBeat); - moves.Add(new QueuedObstacleCameraMove - { - startBeat = animal.beat, - type = ObstacleType.Monkeys - }); - break; - case "animalAcrobat/monkeyShort": - startPos += oneMonkeyDistance; - AcrobatObstacle spawnedOneMonkey = Instantiate(oneMonkeyRef, transform); - spawnedOneMonkey.transform.position = new Vector3(startPos, 0, 0); - spawnedOneMonkey.Init(animal.beat, gameSwitchBeat); - moves.Add(new QueuedObstacleCameraMove - { - startBeat = animal.beat, - type = ObstacleType.Monkey - }); - break; - default: break; - } - } - } - #endregion + } }