so close to being done :(( but weird input bug

This commit is contained in:
AstrlJelly 2024-02-16 00:45:04 -05:00
parent 08ffbe773d
commit 183ae4221d
4 changed files with 62 additions and 43 deletions

View file

@ -168,7 +168,7 @@ SpriteRenderer:
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 470 m_SortingOrder: 650
m_Sprite: {fileID: -1233838809, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Sprite: {fileID: -1233838809, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1} m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0 m_FlipX: 0
@ -335,7 +335,7 @@ SpriteRenderer:
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 770 m_SortingOrder: 1000
m_Sprite: {fileID: 648886606, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Sprite: {fileID: 648886606, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1} m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0 m_FlipX: 0
@ -1271,7 +1271,7 @@ SpriteRenderer:
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 769 m_SortingOrder: 950
m_Sprite: {fileID: -1598011274, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Sprite: {fileID: -1598011274, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3}
m_Color: {r: 0.827451, g: 0.28627452, b: 0.9843137, a: 1} m_Color: {r: 0.827451, g: 0.28627452, b: 0.9843137, a: 1}
m_FlipX: 0 m_FlipX: 0
@ -1473,7 +1473,7 @@ SpriteRenderer:
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 770 m_SortingOrder: 1000
m_Sprite: {fileID: 648886606, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Sprite: {fileID: 648886606, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1} m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0 m_FlipX: 0
@ -1717,7 +1717,7 @@ SpriteRenderer:
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 768 m_SortingOrder: 900
m_Sprite: {fileID: -2050761828, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Sprite: {fileID: -2050761828, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3}
m_Color: {r: 0.89019614, g: 0, b: 0, a: 1} m_Color: {r: 0.89019614, g: 0, b: 0, a: 1}
m_FlipX: 0 m_FlipX: 0
@ -1961,7 +1961,7 @@ SpriteRenderer:
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 768 m_SortingOrder: 900
m_Sprite: {fileID: -2050761828, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Sprite: {fileID: -2050761828, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3}
m_Color: {r: 0.38039216, g: 0.9843137, b: 0.25490198, a: 1} m_Color: {r: 0.38039216, g: 0.9843137, b: 0.25490198, a: 1}
m_FlipX: 0 m_FlipX: 0
@ -6815,7 +6815,7 @@ ParticleSystemRenderer:
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 475 m_SortingOrder: 689
m_RenderMode: 0 m_RenderMode: 0
m_MeshDistribution: 0 m_MeshDistribution: 0
m_SortMode: 0 m_SortMode: 0
@ -6918,7 +6918,7 @@ SpriteRenderer:
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 480 m_SortingOrder: 700
m_Sprite: {fileID: -32620696, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Sprite: {fileID: -32620696, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1} m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0 m_FlipX: 0
@ -7003,7 +7003,7 @@ SpriteRenderer:
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 769 m_SortingOrder: 950
m_Sprite: {fileID: -1598011274, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Sprite: {fileID: -1598011274, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3}
m_Color: {r: 0.38039216, g: 0.9843137, b: 0.25490198, a: 1} m_Color: {r: 0.38039216, g: 0.9843137, b: 0.25490198, a: 1}
m_FlipX: 0 m_FlipX: 0
@ -7236,7 +7236,7 @@ SpriteRenderer:
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 769 m_SortingOrder: 950
m_Sprite: {fileID: -1598011274, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Sprite: {fileID: -1598011274, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3}
m_Color: {r: 0.89019614, g: 0, b: 0, a: 1} m_Color: {r: 0.89019614, g: 0, b: 0, a: 1}
m_FlipX: 0 m_FlipX: 0
@ -7723,7 +7723,7 @@ SpriteRenderer:
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 500 m_SortingOrder: 882
m_Sprite: {fileID: -664749033, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Sprite: {fileID: -664749033, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1} m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0 m_FlipX: 0
@ -8116,7 +8116,7 @@ SpriteRenderer:
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 768 m_SortingOrder: 900
m_Sprite: {fileID: -2050761828, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Sprite: {fileID: -2050761828, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3}
m_Color: {r: 0.827451, g: 0.28627452, b: 0.9843137, a: 1} m_Color: {r: 0.827451, g: 0.28627452, b: 0.9843137, a: 1}
m_FlipX: 0 m_FlipX: 0
@ -8284,7 +8284,7 @@ SpriteRenderer:
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 770 m_SortingOrder: 1000
m_Sprite: {fileID: 648886606, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} m_Sprite: {fileID: 648886606, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1} m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0 m_FlipX: 0

View file

@ -268,7 +268,7 @@ AnimationClip:
m_Level: 0 m_Level: 0
m_CycleOffset: 0 m_CycleOffset: 0
m_HasAdditiveReferencePose: 0 m_HasAdditiveReferencePose: 0
m_LoopTime: 1 m_LoopTime: 0
m_LoopBlend: 0 m_LoopBlend: 0
m_LoopBlendOrientation: 0 m_LoopBlendOrientation: 0
m_LoopBlendPositionY: 0 m_LoopBlendPositionY: 0

View file

@ -5,6 +5,7 @@ using System;
using UnityEngine; using UnityEngine;
using HeavenStudio.Util; using HeavenStudio.Util;
using UnityEngine.Playables;
namespace HeavenStudio.Games.Scripts_SlotMonster 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); anim.DoScaledAnimationAsync("Press", 0.5f);
pressed = true; pressed = true;
if (!isHit) { if (isMiss) {
missed = true; missed = true;
input.Disable(); input.Disable();
input.CleanUp(); input.CleanUp();

View file

@ -140,6 +140,7 @@ namespace HeavenStudio.Games
private List<RiqEntity> gameEntities; private List<RiqEntity> gameEntities;
private bool doWin = true; private bool doWin = true;
private bool inputsActive = false;
private Sound rollingSound; private Sound rollingSound;
private int currentEyeSprite = 1; private int currentEyeSprite = 1;
@ -155,8 +156,8 @@ namespace HeavenStudio.Games
private void Update() private void Update()
{ {
if (PlayerInput.GetIsAction(InputAction_BasicPress) && !IsExpectingInputNow(InputAction_BasicPress)) { if (PlayerInput.GetIsAction(InputAction_BasicPress) && !IsExpectingInputNow(InputAction_BasicPress) && inputsActive) {
_ = HitButton(); HitButton();
ScoreMiss(); ScoreMiss();
} }
} }
@ -177,14 +178,14 @@ namespace HeavenStudio.Games
// make sure the current button is always between 0 and 2 (buttons 1-3) // make sure the current button is always between 0 and 2 (buttons 1-3)
private int GetCurrentButton() => Array.FindIndex(buttons, button => !button.pressed); 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(); int thisButton = GetCurrentButton();
if (thisButton == -1) return false; if (thisButton == -1) return;
bool isLast = thisButton == maxButtons - 1; bool isLast = thisButton == maxButtons - 1;
for (int i = thisButton; i < (isLast ? 3 : thisButton + 1); i++) 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")) { if (eyeAnims[thisButton].IsPlayingAnimationNames("Spin")) {
int eyeSprite = currentEyeSprite; int eyeSprite = currentEyeSprite;
string anim = "EyeItem"; string anim = "EyeItem";
@ -210,17 +211,23 @@ namespace HeavenStudio.Games
SoundByte.PlayOneShotGame(hitSfx, forcePlay: true); SoundByte.PlayOneShotGame(hitSfx, forcePlay: true);
if (isLast) { if (isLast) {
if (rollingSound != null) rollingSound.Stop(); if (rollingSound != null) rollingSound.Stop();
if (isHit && doWin) { inputsActive = false;
SoundByte.PlayOneShotGame("slotMonster/win"); if (isHit && !isMiss) {
winParticles.Play(); smAnim.DoScaledAnimationAsync("Win", 0.5f);
if (doWin) {
SoundByte.PlayOneShotGame("slotMonster/win");
winParticles.Play();
}
} else {
smAnim.DoScaledAnimationAsync("Lose", 0.5f);
} }
} }
currentButton++; currentButton++;
return isLast && isHit;
} }
public void StartInterval(RiqEntity si, bool autoPass, int eyeSprite, double gameSwitchBeat) public void StartInterval(RiqEntity si, bool autoPass, int eyeSprite, double gameSwitchBeat)
{ {
if (rollingSound != null) rollingSound.Stop();
List<RiqEntity> slotActions = gameEntities.FindAll(e => e.datamodel == "slotMonster/slot" && e.beat >= si.beat && e.beat < si.beat + si.length); List<RiqEntity> slotActions = gameEntities.FindAll(e => e.datamodel == "slotMonster/slot" && e.beat >= si.beat && e.beat < si.beat + si.length);
if (slotActions.Count <= 0) return; if (slotActions.Count <= 0) return;
@ -235,12 +242,10 @@ namespace HeavenStudio.Games
maxButtons = Mathf.Min(slotActions.Count, 3); maxButtons = Mathf.Min(slotActions.Count, 3);
for (int i = 0; i < maxButtons; i++) // limit to 3 actions for (int i = 0; i < maxButtons; i++) // limit to 3 actions
{ {
buttons[i].anim.Play("PopUp", 0, 0); buttons[i].Ready();
buttons[i].pressed = false;
eyeAnims[i].Play("Idle", 0, 1); eyeAnims[i].Play("Idle", 0, 1);
int whichSlot = i; int whichSlot = i;
RiqEntity slot = slotActions[whichSlot]; RiqEntity slot = slotActions[whichSlot];
// buttons[i].timing = slot.beat;
if (slot.beat < gameSwitchBeat) continue; if (slot.beat < gameSwitchBeat) continue;
string sfx = ""; string sfx = "";
if (slot["drum"] == (int)DrumTypes.Default) { if (slot["drum"] == (int)DrumTypes.Default) {
@ -259,7 +264,7 @@ namespace HeavenStudio.Games
if (autoPass) { if (autoPass) {
BeatAction.New(this, new() { new(si.beat + si.length, delegate { 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); 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); slotActions ??= gameEntities.FindAll(e => e.datamodel == "slotMonster/slot" && e.beat >= startInterval.beat && e.beat < startInterval.beat + startInterval.length);
List<BeatAction.Action> actions = new(); List<BeatAction.Action> actions = new() {
new(beat, delegate { inputsActive = true; })
};
for (int i = 0; i < Mathf.Min(slotActions.Count, 3); i++) // limit to 3 actions for (int i = 0; i < Mathf.Min(slotActions.Count, 3); i++) // limit to 3 actions
{ {
int whichSlot = i; int whichSlot = i;
double slotBeat = slotActions[i].beat; double slotBeat = slotActions[i].beat;
actions.Add(new(beat + length + slotBeat - startBeat, delegate { actions.Add(new(beat + length + slotBeat - startBeat, delegate {
buttons[whichSlot].TryFlash(); 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; 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); BeatAction.New(this, actions);
} }
@ -310,14 +313,23 @@ namespace HeavenStudio.Games
<= -1f => 1, <= -1f => 1,
_ => 0, _ => 0,
}; };
bool isWin = HitButton(true, timing); HitButton(true, timing);
if (isWin) {
if (rollingSound != null) rollingSound.Stop();
smAnim.DoScaledAnimationAsync("Win", 0.5f);
}
if (state is >= 1f or <= -1f) SoundByte.PlayOneShot("nearMiss"); 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) public void ButtonColor(Color[] colors, Color flashColor)
{ {
for (int i = 0; i < buttons.Length; i++) { for (int i = 0; i < buttons.Length; i++) {