From 183ae4221d11de05b1d7b7191f883fa88bbd0749 Mon Sep 17 00:00:00 2001 From: AstrlJelly Date: Fri, 16 Feb 2024 00:45:04 -0500 Subject: [PATCH] so close to being done :(( but weird input bug --- Assets/Resources/Games/slotMonster.prefab | 26 ++++---- .../Animations/SlotMonster/Lose.anim | 2 +- .../Scripts/Games/SlotMonster/SlotButton.cs | 11 +++- .../Scripts/Games/SlotMonster/SlotMonster.cs | 66 +++++++++++-------- 4 files changed, 62 insertions(+), 43 deletions(-) diff --git a/Assets/Resources/Games/slotMonster.prefab b/Assets/Resources/Games/slotMonster.prefab index c23a2f277..1c15898fa 100644 --- a/Assets/Resources/Games/slotMonster.prefab +++ b/Assets/Resources/Games/slotMonster.prefab @@ -168,7 +168,7 @@ SpriteRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 470 + m_SortingOrder: 650 m_Sprite: {fileID: -1233838809, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} m_FlipX: 0 @@ -335,7 +335,7 @@ SpriteRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 770 + m_SortingOrder: 1000 m_Sprite: {fileID: 648886606, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} m_FlipX: 0 @@ -1271,7 +1271,7 @@ SpriteRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 769 + m_SortingOrder: 950 m_Sprite: {fileID: -1598011274, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Color: {r: 0.827451, g: 0.28627452, b: 0.9843137, a: 1} m_FlipX: 0 @@ -1473,7 +1473,7 @@ SpriteRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 770 + m_SortingOrder: 1000 m_Sprite: {fileID: 648886606, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} m_FlipX: 0 @@ -1717,7 +1717,7 @@ SpriteRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 768 + m_SortingOrder: 900 m_Sprite: {fileID: -2050761828, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Color: {r: 0.89019614, g: 0, b: 0, a: 1} m_FlipX: 0 @@ -1961,7 +1961,7 @@ SpriteRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 768 + m_SortingOrder: 900 m_Sprite: {fileID: -2050761828, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Color: {r: 0.38039216, g: 0.9843137, b: 0.25490198, a: 1} m_FlipX: 0 @@ -6815,7 +6815,7 @@ ParticleSystemRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 475 + m_SortingOrder: 689 m_RenderMode: 0 m_MeshDistribution: 0 m_SortMode: 0 @@ -6918,7 +6918,7 @@ SpriteRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 480 + m_SortingOrder: 700 m_Sprite: {fileID: -32620696, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} m_FlipX: 0 @@ -7003,7 +7003,7 @@ SpriteRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 769 + m_SortingOrder: 950 m_Sprite: {fileID: -1598011274, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Color: {r: 0.38039216, g: 0.9843137, b: 0.25490198, a: 1} m_FlipX: 0 @@ -7236,7 +7236,7 @@ SpriteRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 769 + m_SortingOrder: 950 m_Sprite: {fileID: -1598011274, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Color: {r: 0.89019614, g: 0, b: 0, a: 1} m_FlipX: 0 @@ -7723,7 +7723,7 @@ SpriteRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 500 + m_SortingOrder: 882 m_Sprite: {fileID: -664749033, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} m_FlipX: 0 @@ -8116,7 +8116,7 @@ SpriteRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 768 + m_SortingOrder: 900 m_Sprite: {fileID: -2050761828, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Color: {r: 0.827451, g: 0.28627452, b: 0.9843137, a: 1} m_FlipX: 0 @@ -8284,7 +8284,7 @@ SpriteRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 770 + m_SortingOrder: 1000 m_Sprite: {fileID: 648886606, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} m_FlipX: 0 diff --git a/Assets/Resources/Sprites/Games/SlotMonster/Animations/SlotMonster/Lose.anim b/Assets/Resources/Sprites/Games/SlotMonster/Animations/SlotMonster/Lose.anim index 9fe70a7a4..2fa816e5e 100644 --- a/Assets/Resources/Sprites/Games/SlotMonster/Animations/SlotMonster/Lose.anim +++ b/Assets/Resources/Sprites/Games/SlotMonster/Animations/SlotMonster/Lose.anim @@ -268,7 +268,7 @@ AnimationClip: m_Level: 0 m_CycleOffset: 0 m_HasAdditiveReferencePose: 0 - m_LoopTime: 1 + m_LoopTime: 0 m_LoopBlend: 0 m_LoopBlendOrientation: 0 m_LoopBlendPositionY: 0 diff --git a/Assets/Scripts/Games/SlotMonster/SlotButton.cs b/Assets/Scripts/Games/SlotMonster/SlotButton.cs index df38cfeb2..d5ff3c8dd 100644 --- a/Assets/Scripts/Games/SlotMonster/SlotButton.cs +++ b/Assets/Scripts/Games/SlotMonster/SlotButton.cs @@ -5,6 +5,7 @@ using System; using UnityEngine; using HeavenStudio.Util; +using UnityEngine.Playables; namespace HeavenStudio.Games.Scripts_SlotMonster { @@ -62,11 +63,17 @@ namespace HeavenStudio.Games.Scripts_SlotMonster // } } - public void Press(bool isHit) + public void Ready() + { + anim.Play("PopUp", 0, 0); + pressed = false; + } + + public void Press(bool isMiss) { anim.DoScaledAnimationAsync("Press", 0.5f); pressed = true; - if (!isHit) { + if (isMiss) { missed = true; input.Disable(); input.CleanUp(); diff --git a/Assets/Scripts/Games/SlotMonster/SlotMonster.cs b/Assets/Scripts/Games/SlotMonster/SlotMonster.cs index d8bc40f90..a2e4016ee 100644 --- a/Assets/Scripts/Games/SlotMonster/SlotMonster.cs +++ b/Assets/Scripts/Games/SlotMonster/SlotMonster.cs @@ -140,6 +140,7 @@ namespace HeavenStudio.Games private List gameEntities; private bool doWin = true; + private bool inputsActive = false; private Sound rollingSound; private int currentEyeSprite = 1; @@ -155,8 +156,8 @@ namespace HeavenStudio.Games private void Update() { - if (PlayerInput.GetIsAction(InputAction_BasicPress) && !IsExpectingInputNow(InputAction_BasicPress)) { - _ = HitButton(); + if (PlayerInput.GetIsAction(InputAction_BasicPress) && !IsExpectingInputNow(InputAction_BasicPress) && inputsActive) { + HitButton(); ScoreMiss(); } } @@ -177,14 +178,14 @@ namespace HeavenStudio.Games // make sure the current button is always between 0 and 2 (buttons 1-3) private int GetCurrentButton() => Array.FindIndex(buttons, button => !button.pressed); - private bool HitButton(bool isHit = false, int timing = 0) // returns true if it's the last one + private void HitButton(bool isHit = false, int timing = 0) // returns true if it's the last one { int thisButton = GetCurrentButton(); - if (thisButton == -1) return false; + if (thisButton == -1) return; bool isLast = thisButton == maxButtons - 1; for (int i = thisButton; i < (isLast ? 3 : thisButton + 1); i++) { - buttons[thisButton].Press(isHit); + buttons[thisButton].Press(!isHit || timing != 0); if (eyeAnims[thisButton].IsPlayingAnimationNames("Spin")) { int eyeSprite = currentEyeSprite; string anim = "EyeItem"; @@ -210,17 +211,23 @@ namespace HeavenStudio.Games SoundByte.PlayOneShotGame(hitSfx, forcePlay: true); if (isLast) { if (rollingSound != null) rollingSound.Stop(); - if (isHit && doWin) { - SoundByte.PlayOneShotGame("slotMonster/win"); - winParticles.Play(); + inputsActive = false; + if (isHit && !isMiss) { + smAnim.DoScaledAnimationAsync("Win", 0.5f); + if (doWin) { + SoundByte.PlayOneShotGame("slotMonster/win"); + winParticles.Play(); + } + } else { + smAnim.DoScaledAnimationAsync("Lose", 0.5f); } } currentButton++; - return isLast && isHit; } public void StartInterval(RiqEntity si, bool autoPass, int eyeSprite, double gameSwitchBeat) { + if (rollingSound != null) rollingSound.Stop(); List slotActions = gameEntities.FindAll(e => e.datamodel == "slotMonster/slot" && e.beat >= si.beat && e.beat < si.beat + si.length); if (slotActions.Count <= 0) return; @@ -235,12 +242,10 @@ namespace HeavenStudio.Games maxButtons = Mathf.Min(slotActions.Count, 3); for (int i = 0; i < maxButtons; i++) // limit to 3 actions { - buttons[i].anim.Play("PopUp", 0, 0); - buttons[i].pressed = false; + buttons[i].Ready(); eyeAnims[i].Play("Idle", 0, 1); int whichSlot = i; RiqEntity slot = slotActions[whichSlot]; - // buttons[i].timing = slot.beat; if (slot.beat < gameSwitchBeat) continue; string sfx = ""; if (slot["drum"] == (int)DrumTypes.Default) { @@ -259,7 +264,7 @@ namespace HeavenStudio.Games if (autoPass) { BeatAction.New(this, new() { new(si.beat + si.length, delegate { - currentEyeSprite = eyeSprite == 0 ? UnityEngine.Random.Range(1, 10) : eyeSprite; + currentEyeSprite = eyeSprite == 0 ? UnityEngine.Random.Range(1, 10) : eyeSprite - 1; PassTurn(si.beat + si.length, 1, si.beat, si, slotActions); })}); } @@ -280,26 +285,24 @@ namespace HeavenStudio.Games } slotActions ??= gameEntities.FindAll(e => e.datamodel == "slotMonster/slot" && e.beat >= startInterval.beat && e.beat < startInterval.beat + startInterval.length); - List actions = new(); + List actions = new() { + new(beat, delegate { inputsActive = true; }) + }; for (int i = 0; i < Mathf.Min(slotActions.Count, 3); i++) // limit to 3 actions { int whichSlot = i; double slotBeat = slotActions[i].beat; + actions.Add(new(beat + length + slotBeat - startBeat, delegate { buttons[whichSlot].TryFlash(); })); - PlayerActionEvent input = ScheduleInput(beat, slotBeat - startBeat + length, InputAction_BasicPress, ButtonHit, null, null, () => { + PlayerActionEvent input = ScheduleInput(beat, slotBeat - startBeat + length, InputAction_BasicPress, ButtonHit, i == slotActions.Count - 1 ? ButtonEndMiss : null, null/*, () => { return GetCurrentButton() == whichSlot && !buttons[whichSlot].pressed; - }); + }*/); + buttons[whichSlot].input = input; } - actions.Add(new(beat + length + startInterval.beat + startInterval.length, delegate { - if (rollingSound != null) rollingSound.Stop(); - if (buttons.Any(x => x.missed)) { // if it's a miss - smAnim.DoScaledAnimationAsync("Lose", 0.5f); - } - })); BeatAction.New(this, actions); } @@ -310,14 +313,23 @@ namespace HeavenStudio.Games <= -1f => 1, _ => 0, }; - bool isWin = HitButton(true, timing); - if (isWin) { - if (rollingSound != null) rollingSound.Stop(); - smAnim.DoScaledAnimationAsync("Win", 0.5f); - } + HitButton(true, timing); if (state is >= 1f or <= -1f) SoundByte.PlayOneShot("nearMiss"); } + private void ButtonEndMiss(PlayerActionEvent caller) + { + Debug.Log("miss i guess"); + if (rollingSound != null) rollingSound.Stop(); + inputsActive = false; + smAnim.DoScaledAnimationAsync("Lose", 0.5f); + foreach (var anim in eyeAnims) { + if (anim.IsPlayingAnimationNames("Spin")) { + anim.Play("Idle", 0, 1); + } + } + } + public void ButtonColor(Color[] colors, Color flashColor) { for (int i = 0; i < buttons.Length; i++) {