From e64deabf8a79697a25b629e7cbff5cd6bbb9014c Mon Sep 17 00:00:00 2001 From: LadyEbony Date: Sat, 22 Aug 2020 14:49:44 -0700 Subject: [PATCH] better keyboard input --- Assets/RealCode/GameBoard.cs | 55 ++++++++++++++++++-- Assets/Scenes/Board Render/BoardRender.unity | 9 ++++ 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/Assets/RealCode/GameBoard.cs b/Assets/RealCode/GameBoard.cs index 7d0f4f3..4d45e29 100644 --- a/Assets/RealCode/GameBoard.cs +++ b/Assets/RealCode/GameBoard.cs @@ -222,13 +222,57 @@ public class GameBoard : EntityBase, IAutoSerialize, IAutoDeserialize { public bool awaitingNeutral; public static float inputThreshold = 0.3f; - public void PlayerInput() { - float rightIntent = Input.GetAxisRaw("Horizontal"); - float upIntent = Input.GetAxisRaw("Rotate"); + private bool useKeyboard; + private bool GetInputStyle(){ + var key = Input.anyKey; + var h = Input.GetAxisRaw("Horizontal"); + var v = Input.GetAxisRaw("Rotate"); + + if (key){ + return true; + } else if (h != 0f || v != 0f){ + return false; + } + return useKeyboard; + } + + public void PlayerInput() { + + useKeyboard = GetInputStyle(); + + float rightIntent; + float upIntent; + + bool skipNeutal; + + // involved fix for better pc play + if (useKeyboard){ + rightIntent = 0f; + upIntent = 0f; + + if (Input.GetKeyDown(KeyCode.LeftArrow)) + rightIntent = -1f; + if (Input.GetKeyDown(KeyCode.RightArrow)) + rightIntent = 1f; + + if (Input.GetKeyDown(KeyCode.UpArrow)) + upIntent = 1f; + if (Input.GetKeyDown(KeyCode.DownArrow)) + upIntent = -1f; + + skipNeutal = false; + } else { + rightIntent = Input.GetAxisRaw("Horizontal"); + upIntent = Input.GetAxisRaw("Rotate"); + + skipNeutal = true; + } + + var max = Mathf.Max(Mathf.Abs(rightIntent), Mathf.Abs(upIntent)); if (max > 0.3f) { - if (!awaitingNeutral) { + if (!awaitingNeutral || skipNeutal) { if (rightIntent > 0.2f) { dropColumn += 1; } else if (rightIntent < -0.2f) { @@ -249,8 +293,9 @@ public class GameBoard : EntityBase, IAutoSerialize, IAutoDeserialize { dropColumn = ClampRotatedPosition(playerRotation); dropHeight = playerRotation != 3 ? 12 : 13; // Shift the drop height based on rotation + + awaitingNeutral = true; } - awaitingNeutral = true; } else { awaitingNeutral = false; } diff --git a/Assets/Scenes/Board Render/BoardRender.unity b/Assets/Scenes/Board Render/BoardRender.unity index eee8b7b..f52b748 100644 --- a/Assets/Scenes/Board Render/BoardRender.unity +++ b/Assets/Scenes/Board Render/BoardRender.unity @@ -1542,6 +1542,15 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 482421870, guid: adba91609cb1e5448b76682be198fc9b, type: 3} + propertyPath: m_AnchoredPosition.y + value: 49.999878 + objectReference: {fileID: 0} + - target: {fileID: 1736330633687387551, guid: adba91609cb1e5448b76682be198fc9b, + type: 3} + propertyPath: m_AnchoredPosition.y + value: 49.999878 + objectReference: {fileID: 0} - target: {fileID: 1736330635070797285, guid: adba91609cb1e5448b76682be198fc9b, type: 3} propertyPath: m_Name