From c12dc0305996f77f31dd605f98e83a57f12249d8 Mon Sep 17 00:00:00 2001 From: Kaj Forney Date: Thu, 14 Oct 2021 13:46:33 -0600 Subject: [PATCH] Automatically spawn new tetrominoes as needed. --- Assets/Scenes/level1.unity | 91 +++++++++++++++++++++++-- Assets/Scripts/goal.cs | 27 ++++++++ Assets/Scripts/goal.cs.meta | 11 +++ Assets/Scripts/tetromino.cs | 6 +- Assets/Scripts/tetrominoSpawnManager.cs | 12 ++-- Assets/Scripts/tetrominoUserControl.cs | 5 ++ Assets/Sprites/devgrid.png.meta | 2 +- 7 files changed, 142 insertions(+), 12 deletions(-) create mode 100644 Assets/Scripts/goal.cs create mode 100644 Assets/Scripts/goal.cs.meta diff --git a/Assets/Scenes/level1.unity b/Assets/Scenes/level1.unity index 1a3e90c..3715e58 100644 --- a/Assets/Scenes/level1.unity +++ b/Assets/Scenes/level1.unity @@ -220,7 +220,7 @@ SpriteRenderer: m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 0 - m_Sprite: {fileID: 21300000, guid: 4fa2b2dea4f24c074ad58f2bbe2b0acc, type: 3} + m_Sprite: {fileID: 21300000, guid: 13dafb3a4746f6886b8da12ba1c8f74c, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} m_FlipX: 0 m_FlipY: 0 @@ -572,7 +572,7 @@ GameObject: - component: {fileID: 729893852} - component: {fileID: 729893853} m_Layer: 0 - m_Name: Wall + m_Name: left m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -695,7 +695,7 @@ GameObject: - component: {fileID: 978697294} - component: {fileID: 978697295} m_Layer: 0 - m_Name: Wall (2) + m_Name: top m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -1092,7 +1092,7 @@ GameObject: - component: {fileID: 1643835946} - component: {fileID: 1643835947} m_Layer: 0 - m_Name: Wall (1) + m_Name: right m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -1192,3 +1192,86 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &2113729827 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2113729829} + - component: {fileID: 2113729828} + m_Layer: 0 + m_Name: backgroundStatic + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!212 &2113729828 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2113729827} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_Sprite: {fileID: 21300000, guid: b77f39928043c4f4d9d79b8597c9810f, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 0 + m_Size: {x: 100, y: 75} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_MaskInteraction: 0 + m_SpriteSortPoint: 0 +--- !u!4 &2113729829 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2113729827} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -13.13523, y: -0.14690661, z: 500} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 8 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Scripts/goal.cs b/Assets/Scripts/goal.cs new file mode 100644 index 0000000..47fce33 --- /dev/null +++ b/Assets/Scripts/goal.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class goal : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } + + private void OnCollisionEnter2D(Collision2D other) + { + if (other.collider.tag == "Player") + { + Debug.Log("You win!!!"); + } + } +} diff --git a/Assets/Scripts/goal.cs.meta b/Assets/Scripts/goal.cs.meta new file mode 100644 index 0000000..316a30f --- /dev/null +++ b/Assets/Scripts/goal.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a6096fcbbaecfc626a61d28cfe652871 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/tetromino.cs b/Assets/Scripts/tetromino.cs index c0e460c..9178c8a 100644 --- a/Assets/Scripts/tetromino.cs +++ b/Assets/Scripts/tetromino.cs @@ -8,7 +8,8 @@ public class tetromino : MonoBehaviour { public float timeBetweenSteps; public bool active = true; - public tetrominoUserControl TetrominoUserControl; + private tetrominoUserControl TetrominoUserControl; + private tetrominoSpawnManager TetrominoSpawnManager; private float stepTimer = 0.0f; private bool wouldCollide = false; @@ -16,6 +17,7 @@ public class tetromino : MonoBehaviour // Start is called before the first frame update void Start() { + TetrominoSpawnManager = FindObjectOfType(); TetrominoUserControl = FindObjectOfType(); TetrominoUserControl.setActiveTetromino(gameObject); } @@ -56,6 +58,8 @@ public class tetromino : MonoBehaviour else { active = false; + TetrominoUserControl.unsetActiveTetromino(); + TetrominoSpawnManager.spawnTetromino(); } } diff --git a/Assets/Scripts/tetrominoSpawnManager.cs b/Assets/Scripts/tetrominoSpawnManager.cs index 8dce6a7..4cd770d 100644 --- a/Assets/Scripts/tetrominoSpawnManager.cs +++ b/Assets/Scripts/tetrominoSpawnManager.cs @@ -20,20 +20,20 @@ public class tetrominoSpawnManager : MonoBehaviour // Start is called before the first frame update void Start() { - + spawnTetromino(); } // Update is called once per frame void Update() { //DEBUG: Spawn a new tetromino on click. - if (Input.GetMouseButtonDown(0)) - { - spawnTetromino(); - } + // if (Input.GetMouseButtonDown(0)) + // { + // spawnTetromino(); + // } } - void spawnTetromino() + public void spawnTetromino() { nextTetromino = Random.Range(1, 7); switch (nextTetromino) diff --git a/Assets/Scripts/tetrominoUserControl.cs b/Assets/Scripts/tetrominoUserControl.cs index e3af076..1178e46 100644 --- a/Assets/Scripts/tetrominoUserControl.cs +++ b/Assets/Scripts/tetrominoUserControl.cs @@ -45,4 +45,9 @@ public class tetrominoUserControl : MonoBehaviour { activeTetromino = tetromino; } + + public void unsetActiveTetromino() + { + activeTetromino = null; + } } diff --git a/Assets/Sprites/devgrid.png.meta b/Assets/Sprites/devgrid.png.meta index 01758f3..ca67d0b 100644 --- a/Assets/Sprites/devgrid.png.meta +++ b/Assets/Sprites/devgrid.png.meta @@ -46,7 +46,7 @@ TextureImporter: spriteMeshType: 0 alignment: 0 spritePivot: {x: 0.5, y: 0.5} - spritePixelsToUnits: 16 + spritePixelsToUnits: 8 spriteBorder: {x: 0, y: 0, z: 0, w: 0} spriteGenerateFallbackPhysicsShape: 1 alphaUsage: 1