From 83ab22c96530c4f0413a64f6b2af30ed9cbce74c Mon Sep 17 00:00:00 2001 From: Kaj Forney Date: Thu, 14 Oct 2021 12:56:24 -0600 Subject: [PATCH] Basic rotation and drop controls. --- Assets/Scenes/level1.unity | 16 ++++++++++------ Assets/Scripts/tetrominoSpawnManager.cs | 5 +++-- Assets/Scripts/tetrominoUserControl.cs | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Assets/Scenes/level1.unity b/Assets/Scenes/level1.unity index 4b511c5..50c35c9 100644 --- a/Assets/Scenes/level1.unity +++ b/Assets/Scenes/level1.unity @@ -837,7 +837,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: -131, y: -53.90451} + m_AnchoredPosition: {x: -130.2, y: 190.6} m_SizeDelta: {x: 437.3, y: 37.9045} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1386772421 @@ -861,7 +861,7 @@ MonoBehaviour: m_PersistentCalls: m_Calls: [] m_FontData: - m_Font: {fileID: 12800000, guid: d10c7dd6930d6abde8068075ad403ff3, type: 3} + m_Font: {fileID: 12800000, guid: 10c39188eb0dddbd68a1ed308d740cd6, type: 3} m_FontSize: 36 m_FontStyle: 0 m_BestFit: 0 @@ -873,7 +873,7 @@ MonoBehaviour: m_HorizontalOverflow: 0 m_VerticalOverflow: 0 m_LineSpacing: 1 - m_Text: 0 + m_Text: 'SCORE:' --- !u!222 &1386772422 CanvasRenderer: m_ObjectHideFlags: 0 @@ -1168,12 +1168,16 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: spawnPoint: {x: 0, y: 0, z: 0} - tetrominoSquare: {fileID: 0} - tetrominoLine: {fileID: 0} + tetrominoSquare: {fileID: 7091960356501607795, guid: 8574b49e2210b483382f987b86d1d3af, + type: 3} + tetrominoLine: {fileID: 7091960356501607795, guid: d6ec5fab3480e3ba59d1fa2a9ebfa993, + type: 3} tetrominoL: {fileID: 0} tetrominoR: {fileID: 0} tetrominoS: {fileID: 0} - tetrominoT: {fileID: 0} + tetrominoT: {fileID: 7091960356501607795, guid: ee7d3b3fab5b29b2fadfed207dd6b211, + type: 3} + tetrominoZ: {fileID: 0} --- !u!4 &1955489875 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/tetrominoSpawnManager.cs b/Assets/Scripts/tetrominoSpawnManager.cs index c265ebe..ff4c9d8 100644 --- a/Assets/Scripts/tetrominoSpawnManager.cs +++ b/Assets/Scripts/tetrominoSpawnManager.cs @@ -13,6 +13,7 @@ public class tetrominoSpawnManager : MonoBehaviour public GameObject tetrominoR; public GameObject tetrominoS; public GameObject tetrominoT; + public GameObject tetrominoZ; private int nextTetromino = 0; @@ -34,7 +35,7 @@ public class tetrominoSpawnManager : MonoBehaviour void spawnTetromino() { - nextTetromino = Random.Range(1, 6); + nextTetromino = Random.Range(1, 7); switch (nextTetromino) { case 0: //Square @@ -46,7 +47,7 @@ public class tetrominoSpawnManager : MonoBehaviour case 2: //T-piece Instantiate(tetrominoT, spawnPoint, Quaternion.identity); break; - default: + default: //if it's not a piece I have a prefab for yet, default to square Instantiate(tetrominoSquare, spawnPoint, Quaternion.identity); break; } diff --git a/Assets/Scripts/tetrominoUserControl.cs b/Assets/Scripts/tetrominoUserControl.cs index b3c315b..e3af076 100644 --- a/Assets/Scripts/tetrominoUserControl.cs +++ b/Assets/Scripts/tetrominoUserControl.cs @@ -24,6 +24,21 @@ public class tetrominoUserControl : MonoBehaviour { activeTetromino.gameObject.transform.position += Vector3.right * 1.0f; } + + if (Input.GetButtonDown("tetrisDrop") && activeTetromino != null) + { + activeTetromino.gameObject.transform.position += Vector3.down * 1.0f; + } + + if (Input.GetButtonDown("tetrisRotateLeft") && activeTetromino != null) + { + activeTetromino.gameObject.transform.Rotate(0,0,90,Space.World); + } + + if (Input.GetButtonDown("tetrisRotateRight") && activeTetromino != null) + { + activeTetromino.gameObject.transform.Rotate(0,0,-90,Space.World); + } } public void setActiveTetromino(GameObject tetromino)