diff --git a/Assets/Resources/Games/slotMonster.prefab b/Assets/Resources/Games/slotMonster.prefab index 0085c6c6f..0a4c4be14 100644 --- a/Assets/Resources/Games/slotMonster.prefab +++ b/Assets/Resources/Games/slotMonster.prefab @@ -876,6 +876,7 @@ GameObject: m_Component: - component: {fileID: 6713427547028951939} - component: {fileID: 3765927633667635310} + - component: {fileID: 8493640715844712253} m_Layer: 0 m_Name: Button3 m_TagString: Untagged @@ -921,6 +922,24 @@ Animator: m_AllowConstantClipSamplingOptimization: 1 m_KeepAnimatorStateOnDisable: 0 m_WriteDefaultValuesOnDisable: 0 +--- !u!114 &8493640715844712253 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3468298043875673060} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 824e4674e220b544991c5311c2d90ff1, type: 3} + m_Name: + m_EditorClassIdentifier: + pressed: 0 + color: {r: 0.86274517, g: 0, b: 0, a: 0} + anim: {fileID: 3765927633667635310} + srs: + - {fileID: 2877045166871582979} + - {fileID: 4449036682437390073} --- !u!1 &3502234333494748245 GameObject: m_ObjectHideFlags: 0 @@ -1184,6 +1203,7 @@ GameObject: m_Component: - component: {fileID: 6816887475717257767} - component: {fileID: 8656164449290761354} + - component: {fileID: 7161291887338607999} m_Layer: 0 m_Name: Button2 m_TagString: Untagged @@ -1229,6 +1249,24 @@ Animator: m_AllowConstantClipSamplingOptimization: 1 m_KeepAnimatorStateOnDisable: 0 m_WriteDefaultValuesOnDisable: 0 +--- !u!114 &7161291887338607999 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4661475570310962003} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 824e4674e220b544991c5311c2d90ff1, type: 3} + m_Name: + m_EditorClassIdentifier: + pressed: 0 + color: {r: 0.8000001, g: 0.2784314, b: 0.95294124, a: 0} + anim: {fileID: 8656164449290761354} + srs: + - {fileID: 6069226680631927887} + - {fileID: 2214261874876006399} --- !u!1 &4687682230392877706 GameObject: m_ObjectHideFlags: 0 @@ -1323,6 +1361,7 @@ GameObject: m_Component: - component: {fileID: 2864234776698747384} - component: {fileID: 8588887349593004598} + - component: {fileID: 5051449585850381948} m_Layer: 0 m_Name: Button1 m_TagString: Untagged @@ -1368,6 +1407,24 @@ Animator: m_AllowConstantClipSamplingOptimization: 1 m_KeepAnimatorStateOnDisable: 0 m_WriteDefaultValuesOnDisable: 0 +--- !u!114 &5051449585850381948 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5076257341597419496} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 824e4674e220b544991c5311c2d90ff1, type: 3} + m_Name: + m_EditorClassIdentifier: + pressed: 0 + color: {r: 0.3803922, g: 0.9843138, b: 0.25490198, a: 0} + anim: {fileID: 8588887349593004598} + srs: + - {fileID: 4790761080377207371} + - {fileID: 6479832831682828701} --- !u!1 &5449113805416087283 GameObject: m_ObjectHideFlags: 0 @@ -1502,29 +1559,15 @@ MonoBehaviour: SoundSequences: [] scheduledInputs: [] smAnim: {fileID: 8395666848120559718} - eyeSprites: - - {fileID: 1032231447, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} - - {fileID: 90921217, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} - - {fileID: -108380036, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} - - {fileID: -1768230940, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} - - {fileID: -867298969, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} - - {fileID: 1609057261, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} - - {fileID: -1628350790, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} - - {fileID: 1306426365, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} - - {fileID: 811989312, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} - - {fileID: -1260976779, guid: 878a62db1eeb38d46a0db8e2b67b9730, type: 3} eyeAnims: - {fileID: 7955005190241873031} - {fileID: 2460964828755838947} - {fileID: 5491330272697201237} - eyeSRs: - - {fileID: 2787758216707421360} - - {fileID: 1775810850113365420} - - {fileID: 8454085075965419430} - buttonAnims: - - {fileID: 8588887349593004598} - - {fileID: 8656164449290761354} - - {fileID: 3765927633667635310} + buttons: + - {fileID: 5051449585850381948} + - {fileID: 7161291887338607999} + - {fileID: 8493640715844712253} + buttonFlashColor: {r: 1, g: 1, b: 0.68235296, a: 0} --- !u!1 &5849268409563499564 GameObject: m_ObjectHideFlags: 0 @@ -2567,7 +2610,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 9212153283773584803} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0.179, y: 0.2550001, z: 0} + m_LocalPosition: {x: 0.17900002, y: 0.2550001, z: 0} m_LocalScale: {x: 0.8024, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] diff --git a/Assets/Resources/Sprites/Games/SlotMonster/Animations/Button/Flash.anim b/Assets/Resources/Sprites/Games/SlotMonster/Animations/Button/Flash.anim index 1b86821fc..51d9327b1 100644 --- a/Assets/Resources/Sprites/Games/SlotMonster/Animations/Button/Flash.anim +++ b/Assets/Resources/Sprites/Games/SlotMonster/Animations/Button/Flash.anim @@ -127,7 +127,7 @@ AnimationClip: m_AdditiveReferencePoseClip: {fileID: 0} m_AdditiveReferencePoseTime: 0 m_StartTime: 0 - m_StopTime: 0.05 + m_StopTime: 0.06666667 m_OrientationOffsetY: 0 m_Level: 0 m_CycleOffset: 0 @@ -398,4 +398,39 @@ AnimationClip: m_EulerEditorCurves: [] m_HasGenericRootTransform: 0 m_HasMotionFloatCurves: 0 - m_Events: [] + m_Events: + - time: 0 + functionName: AnimateColor + data: + objectReferenceParameter: {fileID: 0} + floatParameter: 0 + intParameter: 0 + messageOptions: 0 + - time: 0.016666668 + functionName: AnimateColor + data: + objectReferenceParameter: {fileID: 0} + floatParameter: 0 + intParameter: 1 + messageOptions: 0 + - time: 0.033333335 + functionName: AnimateColor + data: + objectReferenceParameter: {fileID: 0} + floatParameter: 0 + intParameter: 2 + messageOptions: 0 + - time: 0.05 + functionName: AnimateColor + data: + objectReferenceParameter: {fileID: 0} + floatParameter: 0 + intParameter: 3 + messageOptions: 0 + - time: 0.06666667 + functionName: AnimateColor + data: + objectReferenceParameter: {fileID: 0} + floatParameter: 0 + intParameter: 4 + messageOptions: 0 diff --git a/Assets/Scripts/Games/SlotMonster/SlotButton.cs b/Assets/Scripts/Games/SlotMonster/SlotButton.cs new file mode 100644 index 000000000..39d6adefc --- /dev/null +++ b/Assets/Scripts/Games/SlotMonster/SlotButton.cs @@ -0,0 +1,73 @@ +using System.Collections; +using System.Collections.Generic; +using System; +using UnityEngine; + +using HeavenStudio.Util; + +namespace HeavenStudio.Games.Scripts_SlotMonster +{ + public class SlotButton : MonoBehaviour + { + public bool pressed; + public Color color; // used to ease between button colors and button flash colors! wow + + public Animator anim; + public SpriteRenderer[] srs; + + public bool flashing; + const int FLASH_FRAMES = 4; + public int currentFrame; + + private SlotMonster game; + + public void Init(SlotMonster instance) + { + color = srs[0].color; + game = instance; + } + + private void LateUpdate() + { + if (flashing) { + foreach (var sr in srs) { + // sr.color = Color.Lerp(color, game.buttonFlashColor, currentFrame / FRAMES); + + var normalized = currentFrame / FLASH_FRAMES; + + float newR = EasingFunction.Linear(game.buttonFlashColor.r, color.r, normalized); + float newG = EasingFunction.Linear(game.buttonFlashColor.g, color.g, normalized); + float newB = EasingFunction.Linear(game.buttonFlashColor.b, color.b, normalized); + + sr.color = new Color(newR, newG, newB); + Debug.Log("sr.color : " + sr.color); + Debug.Log("currentFrame : " + currentFrame); + } + } else { + foreach (var sr in srs) { + sr.color = color; + } + } + } + + public void Press() + { + anim.DoScaledAnimationAsync("Press", 0.5f); + pressed = true; + } + + public void TryFlash() + { + if (!pressed) { + anim.DoScaledAnimationAsync("Flash", 0.5f); + } + } + + // animation events + public void AnimateColor(int frame) + { + currentFrame = frame; + flashing = frame < FLASH_FRAMES; + } + } +} diff --git a/Assets/Scripts/Games/SlotMonster/SlotButton.cs.meta b/Assets/Scripts/Games/SlotMonster/SlotButton.cs.meta new file mode 100644 index 000000000..ed7cb9779 --- /dev/null +++ b/Assets/Scripts/Games/SlotMonster/SlotButton.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 824e4674e220b544991c5311c2d90ff1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Games/SlotMonster/SlotMonster.cs b/Assets/Scripts/Games/SlotMonster/SlotMonster.cs index 3bda11078..060f7b74c 100644 --- a/Assets/Scripts/Games/SlotMonster/SlotMonster.cs +++ b/Assets/Scripts/Games/SlotMonster/SlotMonster.cs @@ -20,17 +20,10 @@ namespace HeavenStudio.Games.Loaders { new GameAction("startInterval", "Start Interval") { - preFunction = delegate { - var e = eventCaller.currentEntity; - SoundByte.PlayOneShotGame("slotMonster/start_touch", e.beat - 1, forcePlay: true); - if (eventCaller.gameManager.minigameObj.TryGetComponent(out SlotMonster instance)) { - instance.PreStartInterval(e.beat); - } - }, function = delegate { if (eventCaller.gameManager.minigameObj.TryGetComponent(out SlotMonster instance)) { var e = eventCaller.currentEntity; - instance.StartInterval(e.beat, e.length, e["auto"], e["eyeType"], e, 0); + instance.StartInterval(e.beat, e.length, e["auto"], e["eyeType"], 0); } }, defaultLength = 3f, @@ -79,10 +72,18 @@ namespace HeavenStudio.Games.Loaders priority = 1, parameters = new List() { - new Param("button1", new Color(), "Button 1 Color", "Set the color of the first button."), - new Param("button2", new Color(), "Button 2 Color", "Set the color of the second button."), - new Param("button3", new Color(), "Button 3 Color", "Set the color of the third button."), - new Param("flash", new Color(), "Button Flash Color", "Set the color of the flash of the buttons."), + new Param("button1", new Color(0.38f, 0.98f, 0.25f), "Button 1 Color", "Set the color of the first button."), + new Param("button2", new Color(0.8f, 0.28f, 0.95f), "Button 2 Color", "Set the color of the second button."), + new Param("button3", new Color(0.87f, 0f, 0f), "Button 3 Color", "Set the color of the third button."), + new Param("flash", new Color(1f, 1f, 0.68f), "Button Flash Color", "Set the color of the flash of the buttons."), + }, + }, + new GameAction("test", "Test") + { + function = delegate { + if (eventCaller.gameManager.minigameObj.TryGetComponent(out SlotMonster instance)) { + instance.ScheduleInput(eventCaller.currentEntity.beat, 1, Games.Minigame.InputAction_BasicPress, null, null, null); + } }, }, } @@ -93,6 +94,7 @@ namespace HeavenStudio.Games.Loaders namespace HeavenStudio.Games { + using Scripts_SlotMonster; public class SlotMonster : Minigame { public enum DrumTypes @@ -119,40 +121,31 @@ namespace HeavenStudio.Games [Header("Animators")] [SerializeField] Animator smAnim; - [SerializeField] Sprite[] eyeSprites; [SerializeField] Animator[] eyeAnims; - [SerializeField] SpriteRenderer[] eyeSRs; - [SerializeField] Animator[] buttonAnims; - private double[] buttonstartBeats; - // used to ease between button colors and button flash colors! wow - private Color[] buttonColors; - private Color buttonFlashColor; + [SerializeField] SlotButton[] buttons; + public Color buttonFlashColor; private List gameEntities; private Sound rollingSound; private int currentEyeSprite = 1; private int maxButtons; - private int currentButton { get => currentButton %= 3; set => currentButton = value; } - // private double smPrepareBeat; - + private int currentButton; private void Awake() { - // eyeSRs = eyeAnims.Where(x => x.GetComponent()).ToArray(); + foreach (var button in buttons) { + button.Init(this); + } } private void Update() { - if (PlayerInput.GetIsAction(InputAction_BasicPress) && !IsExpectingInputNow(InputAction_BasicPress) && !buttonAnims[GetCurrentButton()].IsPlayingAnimationNames("Press")) { + if (PlayerInput.GetIsAction(InputAction_BasicPress) && !IsExpectingInputNow(InputAction_BasicPress)) { _ = HitButton(); ScoreMiss(); } - - // if (smPrepareBeat <= conductor.songPositionInBeatsAsDouble) { - - // } } public override void OnPlay(double beat) @@ -163,32 +156,24 @@ namespace HeavenStudio.Games public override void OnGameSwitch(double beat) { gameEntities = GameManager.instance.Beatmap.Entities.FindAll(c => c.datamodel.Split('/')[0] == "slotMonster"); - foreach (RiqEntity e in gameEntities.FindAll(e => e.datamodel == "slotMonster/startInterval" && e.beat - 1 < beat && e.beat + e.length > beat)) - { - Debug.Log("im gonna explode : " + (e.beat - 0.5 > beat)); - if (e.beat - 0.5 > beat) { - PreStartInterval(beat); - } - if (e.beat < beat) { - StartInterval(e.beat, e.length, e["auto"], e["eyeType"], e, beat); - } - // StartInterval(e.beat, e.length, e["auto"], e["eyeType"], e, beat); + foreach (RiqEntity e in gameEntities.FindAll(e => e.datamodel == "slotMonster/startInterval" && e.beat < beat && e.beat + e.length > beat)) { + StartInterval(e.beat, e.length, e["auto"], e["eyeType"], beat); } } // make sure the current button is always between 0 and 2 (buttons 1-3) - private int GetCurrentButton() => currentButton %= 3; + private int GetCurrentButton() => Array.FindIndex(buttons, button => !button.pressed); private bool HitButton(bool isHit = false) // returns true if it's the last one { int thisButton = GetCurrentButton(); - // Debug.Log("BUTTON HIT : " + thisButton); + if (thisButton == -1) return false; bool lastButton = thisButton == maxButtons - 1; string hitSfx = "slotMonster/stop_" + (lastButton && isHit ? "hit" : (thisButton + 1)); SoundByte.PlayOneShotGame(hitSfx, forcePlay: true); for (int i = thisButton; i < (lastButton ? 3 : thisButton + 1); i++) { - buttonAnims[thisButton].DoScaledAnimationAsync("Press", 0.5f); + buttons[thisButton].Press(); if (eyeAnims[thisButton].IsPlayingAnimationNames("Spin")) { int eyeSprite = currentEyeSprite; if (!isHit) { @@ -200,30 +185,29 @@ namespace HeavenStudio.Games eyeAnims[thisButton].Play("EyeItem" + eyeSprite, 0, 0); } } + if (lastButton) { + if (rollingSound != null) rollingSound.Stop(); + } currentButton++; return lastButton && isHit; } - public void PreStartInterval(double beat) + public void StartInterval(double beat, float length, bool autoPass, int eyeSprite, double gameSwitchBeat) { - // smPrepareBeat - smAnim.DoScaledAnimationFromBeatAsync("Prepare", 0.5f, beat - 1); - foreach (var anim in buttonAnims) - { - anim.Play("PopUp", 0, 1); - } - } + List slotActions = gameEntities.FindAll(e => e.datamodel == "slotMonster/slot" && e.beat >= beat && e.beat < beat + length); - public void StartInterval(double beat, float length, bool autoPass, int eyeSprite, RiqEntity startInterval, double gameSwitchBeat) - { - List slotActions = gameEntities.FindAll(e => e.datamodel == "slotMonster/slot" && e.beat >= startInterval.beat && e.beat < startInterval.beat + startInterval.length); + SoundByte.PlayOneShotGame("slotMonster/start_touch", forcePlay: true); + smAnim.DoScaledAnimationFromBeatAsync("Prepare", 0.5f, beat); + foreach (var button in buttons) { + button.anim.Play("PopUp", 0, 1); + } List sounds = new(); List actions = new(); maxButtons = Mathf.Min(slotActions.Count, 3); for (int i = 0; i < maxButtons; i++) // limit to 3 actions { - buttonAnims[i].Play("PopUp", 0, 0); + buttons[i].anim.Play("PopUp", 0, 0); int whichSlot = i; RiqEntity slot = slotActions[whichSlot]; if (slot.beat < gameSwitchBeat) continue; @@ -236,9 +220,7 @@ namespace HeavenStudio.Games // Debug.Log(sfx); sounds.Add(new(sfx + "DrumNTR", slot.beat)); actions.Add(new(slot.beat, delegate { - if (buttonAnims[whichSlot].IsAnimationNotPlaying()) { - buttonAnims[whichSlot].DoScaledAnimationAsync("Flash", 0.5f); - } + buttons[whichSlot].TryFlash(); })); } MultiSound.Play(sounds.ToArray(), false); @@ -255,8 +237,7 @@ namespace HeavenStudio.Games public void PassTurn(double beat, float length, double startBeat = -1, List slotActions = null) { smAnim.DoScaledAnimationFromBeatAsync("Release", 0.5f, beat); - for (int i = 0; i < eyeAnims.Length; i++) - { + for (int i = 0; i < eyeAnims.Length; i++) { eyeAnims[i].DoScaledAnimationAsync("Spin", 0.5f); } SoundByte.PlayOneShotGame("slotMonster/start_rolling", forcePlay: true); @@ -274,17 +255,15 @@ namespace HeavenStudio.Games double slotBeat = slotActions[i].beat; actions.Add(new(beat + length + slotBeat - startBeat, delegate { - if (!buttonAnims[whichSlot].IsPlayingAnimationNames("Press")) { - buttonAnims[whichSlot].DoScaledAnimationAsync("Flash"); - } + buttons[whichSlot].TryFlash(); })); // Debug.Log("input scheduled at : " + (beat + length + slotBeat - startBeat)); PlayerActionEvent input = ScheduleInput(beat, slotBeat - startBeat + length, InputAction_BasicPress, ButtonHit, null, null); - input.IsHittable = () => { - int currentButton = GetCurrentButton(); - return currentButton == whichSlot && !buttonAnims[whichSlot].IsPlayingAnimationNames("Press"); - }; + // input.IsHittable = () => { + // int currentButton = GetCurrentButton(); + // return currentButton == whichSlot && !buttonsPressed[whichSlot]; + // }; } BeatAction.New(this, actions); } @@ -304,9 +283,11 @@ namespace HeavenStudio.Games // // } - public void ButtonColor(Color[] baseColors, Color flashColor) + public void ButtonColor(Color[] colors, Color flashColor) { - buttonColors = baseColors; + for (int i = 0; i < buttons.Length; i++) { + buttons[i].color = colors[i]; + } buttonFlashColor = flashColor; } }