From f83de2bb23924f1d1fbdc1bf9e211a56fed623e0 Mon Sep 17 00:00:00 2001 From: Adam Graham Date: Tue, 10 Aug 2021 14:42:26 -0500 Subject: [PATCH] Add core game logic --- Assets/Scenes/Tetris.unity | 1201 +++++++++++++-------------------- Assets/Scripts/Board.cs | 148 ++++ Assets/Scripts/Board.cs.meta | 11 + Assets/Scripts/Ghost.cs | 76 +++ Assets/Scripts/Ghost.cs.meta | 11 + Assets/Scripts/Piece.cs | 198 ++++++ Assets/Scripts/Piece.cs.meta | 11 + Assets/Tiles/Ghost.asset | 36 + Assets/Tiles/Ghost.asset.meta | 8 + 9 files changed, 972 insertions(+), 728 deletions(-) create mode 100644 Assets/Scripts/Board.cs create mode 100644 Assets/Scripts/Board.cs.meta create mode 100644 Assets/Scripts/Ghost.cs create mode 100644 Assets/Scripts/Ghost.cs.meta create mode 100644 Assets/Scripts/Piece.cs create mode 100644 Assets/Scripts/Piece.cs.meta create mode 100644 Assets/Tiles/Ghost.asset create mode 100644 Assets/Tiles/Ghost.asset.meta diff --git a/Assets/Scenes/Tetris.unity b/Assets/Scenes/Tetris.unity index 1d487ca..ce33866 100644 --- a/Assets/Scenes/Tetris.unity +++ b/Assets/Scenes/Tetris.unity @@ -123,6 +123,124 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1 &186167657 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 186167658} + - component: {fileID: 186167660} + - component: {fileID: 186167659} + m_Layer: 0 + m_Name: Tilemap + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &186167658 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 186167657} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1253872413} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!483693784 &186167659 +TilemapRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 186167657} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 0 + m_ReflectionProbeUsage: 0 + 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: 1 + m_ChunkSize: {x: 32, y: 32, z: 32} + m_ChunkCullingBounds: {x: 0, y: 0, z: 0} + m_MaxChunkCount: 16 + m_MaxFrameAge: 16 + m_SortOrder: 0 + m_Mode: 0 + m_DetectChunkCullingBounds: 0 + m_MaskInteraction: 0 +--- !u!1839735485 &186167660 +Tilemap: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 186167657} + m_Enabled: 1 + m_Tiles: {} + m_AnimatedTiles: {} + m_TileAssetArray: [] + m_TileSpriteArray: [] + m_TileMatrixArray: [] + m_TileColorArray: [] + m_TileObjectToInstantiateArray: [] + m_AnimationFrameRate: 1 + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_Origin: {x: 0, y: 0, z: 0} + m_Size: {x: 0, y: 0, z: 1} + m_TileAnchor: {x: 0.5, y: 0.5, z: 0} + m_TileOrientation: 0 + m_TileOrientationMatrix: + e00: 1 + e01: 0 + e02: 0 + e03: 0 + e10: 0 + e11: 1 + e12: 0 + e13: 0 + e20: 0 + e21: 0 + e22: 1 + e23: 0 + e30: 0 + e31: 0 + e32: 0 + e33: 1 --- !u!1 &519420028 GameObject: m_ObjectHideFlags: 0 @@ -134,6 +252,7 @@ GameObject: - component: {fileID: 519420032} - component: {fileID: 519420031} - component: {fileID: 519420029} + - component: {fileID: 519420030} m_Layer: 0 m_Name: Main Camera m_TagString: MainCamera @@ -149,6 +268,26 @@ AudioListener: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 519420028} m_Enabled: 1 +--- !u!114 &519420030 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 519420028} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6a160d838ff8b4b4693ac20007e008c7, type: 3} + m_Name: + m_EditorClassIdentifier: + m_AssetsPPU: 8 + m_RefResolutionX: 80 + m_RefResolutionY: 160 + m_UpscaleRT: 0 + m_PixelSnapping: 0 + m_CropFrameX: 0 + m_CropFrameY: 0 + m_StretchFill: 0 --- !u!20 &519420031 Camera: m_ObjectHideFlags: 0 @@ -159,7 +298,7 @@ Camera: m_Enabled: 1 serializedVersion: 2 m_ClearFlags: 2 - m_BackGroundColor: {r: 0, g: 0, b: 0, a: 0} + m_BackGroundColor: {r: 0.18382978, g: 0.2093617, b: 0.24, a: 1} m_projectionMatrixMode: 1 m_GateFitMode: 2 m_FOVAxisMode: 0 @@ -206,7 +345,7 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &1887623652 +--- !u!1 &564011153 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -214,53 +353,9 @@ GameObject: m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component: - - component: {fileID: 1887623654} - - component: {fileID: 1887623653} - m_Layer: 0 - m_Name: Grid - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!156049354 &1887623653 -Grid: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1887623652} - m_Enabled: 1 - m_CellSize: {x: 1, y: 1, z: 0} - m_CellGap: {x: 0, y: 0, z: 0} - m_CellLayout: 0 - m_CellSwizzle: 0 ---- !u!4 &1887623654 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1887623652} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: - - {fileID: 2096189155} - m_Father: {fileID: 0} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &2096189154 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 2096189155} - - component: {fileID: 2096189157} - - component: {fileID: 2096189156} + - component: {fileID: 564011154} + - component: {fileID: 564011156} + - component: {fileID: 564011155} m_Layer: 0 m_Name: Tilemap m_TagString: Untagged @@ -268,27 +363,27 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!4 &2096189155 +--- !u!4 &564011154 Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2096189154} + m_GameObject: {fileID: 564011153} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalPosition: {x: 0, y: 0, z: -1} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1887623654} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!483693784 &2096189156 +--- !u!483693784 &564011155 TilemapRenderer: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2096189154} + m_GameObject: {fileID: 564011153} m_Enabled: 1 m_CastShadows: 0 m_ReceiveShadows: 0 @@ -321,7 +416,7 @@ TilemapRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 0 + m_SortingOrder: 2 m_ChunkSize: {x: 32, y: 32, z: 32} m_ChunkCullingBounds: {x: 0, y: 0, z: 0} m_MaxChunkCount: 16 @@ -330,689 +425,25 @@ TilemapRenderer: m_Mode: 0 m_DetectChunkCullingBounds: 0 m_MaskInteraction: 0 ---- !u!1839735485 &2096189157 +--- !u!1839735485 &564011156 Tilemap: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2096189154} + m_GameObject: {fileID: 564011153} m_Enabled: 1 - m_Tiles: - - first: {x: -6, y: -11, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -5, y: -11, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -4, y: -11, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -3, y: -11, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -2, y: -11, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -1, y: -11, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 0, y: -11, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 1, y: -11, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 2, y: -11, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 3, y: -11, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 4, y: -11, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: -11, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: -10, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: -10, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: -9, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: -9, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: -8, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: -8, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: -7, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: -7, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: -6, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: -6, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: -5, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: -5, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: -4, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: -4, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: -3, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: -3, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: -2, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: -2, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: -1, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: -1, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: 0, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: 0, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: 1, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: 1, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: 2, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: 2, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: 3, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: 3, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: 4, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: 4, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: 5, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: 5, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: 6, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: 6, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: 7, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: 7, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: 8, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: 8, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: 9, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: 9, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -6, y: 10, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -5, y: 10, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -4, y: 10, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -3, y: 10, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -2, y: 10, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: -1, y: 10, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 0, y: 10, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 1, y: 10, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 2, y: 10, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 3, y: 10, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 4, y: 10, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 5, y: 10, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 0 - m_TileSpriteIndex: 0 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 + m_Tiles: {} m_AnimatedTiles: {} - m_TileAssetArray: - - m_RefCount: 64 - m_Data: {fileID: 11400000, guid: 9e2688d592617d44ea74683c8f61accf, type: 2} - m_TileSpriteArray: - - m_RefCount: 64 - m_Data: {fileID: 21300000, guid: 201aebd630f12cf41bd9524548e38803, type: 3} - m_TileMatrixArray: - - m_RefCount: 64 - m_Data: - e00: 1 - e01: 0 - e02: 0 - e03: 0 - e10: 0 - e11: 1 - e12: 0 - e13: 0 - e20: 0 - e21: 0 - e22: 1 - e23: 0 - e30: 0 - e31: 0 - e32: 0 - e33: 1 - m_TileColorArray: - - m_RefCount: 64 - m_Data: {r: 1, g: 1, b: 1, a: 1} + m_TileAssetArray: [] + m_TileSpriteArray: [] + m_TileMatrixArray: [] + m_TileColorArray: [] m_TileObjectToInstantiateArray: [] m_AnimationFrameRate: 1 m_Color: {r: 1, g: 1, b: 1, a: 1} - m_Origin: {x: -6, y: -11, z: 0} - m_Size: {x: 12, y: 22, z: 1} + m_Origin: {x: 0, y: 0, z: 0} + m_Size: {x: 0, y: 0, z: 1} m_TileAnchor: {x: 0.5, y: 0.5, z: 0} m_TileOrientation: 0 m_TileOrientationMatrix: @@ -1032,3 +463,317 @@ Tilemap: e31: 0 e32: 0 e33: 1 +--- !u!1 &1062971706 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1062971708} + - component: {fileID: 1062971707} + m_Layer: 0 + m_Name: Border + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!212 &1062971707 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1062971706} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + 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: 3 + m_Sprite: {fileID: 21300000, guid: dcd88b8f2120d9c4f8d1d9826b673819, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 0 + m_Size: {x: 10.677083, y: 20.677084} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_MaskInteraction: 0 + m_SpriteSortPoint: 0 +--- !u!4 &1062971708 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1062971706} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 4 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1253872411 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1253872413} + - component: {fileID: 1253872412} + - component: {fileID: 1253872414} + m_Layer: 0 + m_Name: Ghost + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!156049354 &1253872412 +Grid: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1253872411} + m_Enabled: 1 + m_CellSize: {x: 1, y: 1, z: 1} + m_CellGap: {x: 0, y: 0, z: 0} + m_CellLayout: 0 + m_CellSwizzle: 0 +--- !u!4 &1253872413 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1253872411} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 186167658} + m_Father: {fileID: 0} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1253872414 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1253872411} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8d159ef6a04487d48afc5338ee3de43c, type: 3} + m_Name: + m_EditorClassIdentifier: + tile: {fileID: 11400000, guid: a10927dec698b7c49b1375f89e8db4d2, type: 2} + board: {fileID: 1887623656} + trackingPiece: {fileID: 1887623655} +--- !u!1 &1887623652 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1887623654} + - component: {fileID: 1887623653} + - component: {fileID: 1887623656} + - component: {fileID: 1887623655} + m_Layer: 0 + m_Name: Board + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!156049354 &1887623653 +Grid: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1887623652} + m_Enabled: 1 + m_CellSize: {x: 1, y: 1, z: 0} + m_CellGap: {x: 0, y: 0, z: 0} + m_CellLayout: 0 + m_CellSwizzle: 0 +--- !u!4 &1887623654 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1887623652} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 564011154} + m_Father: {fileID: 0} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1887623655 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1887623652} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b6570178d836e8642a13a0b983600cf3, type: 3} + m_Name: + m_EditorClassIdentifier: + stepDelay: 1 + moveDelay: 0.1 + lockDelay: 0.5 +--- !u!114 &1887623656 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1887623652} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0d4fe201741a0f14c82a9ce960b9f5e4, type: 3} + m_Name: + m_EditorClassIdentifier: + tetrominoes: + - tile: {fileID: 11400000, guid: aa44b5216a5f39e4881c5323564afe81, type: 2} + tetromino: 0 + - tile: {fileID: 11400000, guid: f6c4109fd0d185b419e5e665b07c42f0, type: 2} + tetromino: 1 + - tile: {fileID: 11400000, guid: 89eae29ecf56ea14c8b3927213a00066, type: 2} + tetromino: 2 + - tile: {fileID: 11400000, guid: 66df2645ff909154b9c8f7c006a6af32, type: 2} + tetromino: 3 + - tile: {fileID: 11400000, guid: ae5c5dcd9d2744248ba2beb6b8dab80f, type: 2} + tetromino: 4 + - tile: {fileID: 11400000, guid: 8316c87896e7b6448a324d8a66e43174, type: 2} + tetromino: 5 + - tile: {fileID: 11400000, guid: be0a34e2a842ae742b4fa8541a5f9fcf, type: 2} + tetromino: 6 + boardSize: {x: 10, y: 20} + spawnPosition: {x: -1, y: 8, z: 0} +--- !u!1 &2144466704 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2144466706} + - component: {fileID: 2144466705} + m_Layer: 0 + m_Name: Grid + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!212 &2144466705 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2144466704} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + 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: 6ff6b85966aeb3f4ab304af07f4dd424, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 2 + m_Size: {x: 10, y: 20} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_MaskInteraction: 0 + m_SpriteSortPoint: 0 +--- !u!4 &2144466706 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2144466704} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Scripts/Board.cs b/Assets/Scripts/Board.cs new file mode 100644 index 0000000..828ec4a --- /dev/null +++ b/Assets/Scripts/Board.cs @@ -0,0 +1,148 @@ +using UnityEngine; +using UnityEngine.Tilemaps; + +public class Board : MonoBehaviour +{ + public Tilemap tilemap { get; private set; } + public Piece activePiece { get; private set; } + + public TetrominoData[] tetrominoes; + public Vector2Int boardSize = new Vector2Int(10, 20); + public Vector3Int spawnPosition = new Vector3Int(-1, 8, 0); + + public RectInt Bounds { + get + { + Vector2Int position = new Vector2Int(-this.boardSize.x / 2, -this.boardSize.y / 2); + return new RectInt(position, this.boardSize); + } + } + + private void Awake() + { + this.tilemap = GetComponentInChildren(); + this.activePiece = GetComponentInChildren(); + + for (int i = 0; i < this.tetrominoes.Length; i++) { + this.tetrominoes[i].Initialize(); + } + } + + private void Start() + { + SpawnPiece(); + } + + public void SpawnPiece() + { + int random = Random.Range(0, this.tetrominoes.Length); + TetrominoData data = this.tetrominoes[random]; + + this.activePiece.Initialize(this, this.spawnPosition, data); + Set(this.activePiece); + } + + public void Set(Piece piece) + { + for (int i = 0; i < piece.cells.Length; i++) + { + Vector3Int tilePosition = piece.cells[i] + piece.position; + this.tilemap.SetTile(tilePosition, piece.data.tile); + } + } + + public void Clear(Piece piece) + { + for (int i = 0; i < piece.cells.Length; i++) + { + Vector3Int tilePosition = piece.cells[i] + piece.position; + this.tilemap.SetTile(tilePosition, null); + } + } + + public bool IsValidPosition(Piece piece, Vector3Int position) + { + RectInt bounds = this.Bounds; + + // The position is only valid if every cell is valid + for (int i = 0; i < piece.cells.Length; i++) + { + Vector3Int tilePosition = piece.cells[i] + position; + + // An out of bounds tile is invalid + if (!bounds.Contains((Vector2Int)tilePosition)) { + return false; + } + + // A tile already occupies the position, thus invalid + if (this.tilemap.HasTile(tilePosition)) { + return false; + } + } + + return true; + } + + public void ClearLines() + { + RectInt bounds = this.Bounds; + int row = bounds.yMin; + + // Clear from bottom to top + while (row < bounds.yMax) + { + // Only advance to the next row if the current is not cleared + // because the tiles above will fall down when a row is cleared + if (IsLineFull(row)) { + LineClear(row); + } else { + row++; + } + } + } + + public bool IsLineFull(int row) + { + RectInt bounds = this.Bounds; + + for (int col = bounds.xMin; col < bounds.xMax; col++) + { + Vector3Int position = new Vector3Int(col, row, 0); + + // The line is not full if a tile is missing + if (!this.tilemap.HasTile(position)) { + return false; + } + } + + return true; + } + + public void LineClear(int row) + { + RectInt bounds = this.Bounds; + + // Clear all tiles in the row + for (int col = bounds.xMin; col < bounds.xMax; col++) + { + Vector3Int position = new Vector3Int(col, row, 0); + this.tilemap.SetTile(position, null); + } + + // Shift every row above down one + while (row < bounds.yMax) + { + for (int col = bounds.xMin; col < bounds.xMax; col++) + { + Vector3Int position = new Vector3Int(col, row + 1, 0); + TileBase above = this.tilemap.GetTile(position); + + position = new Vector3Int(col, row, 0); + this.tilemap.SetTile(position, above); + } + + row++; + } + } + +} diff --git a/Assets/Scripts/Board.cs.meta b/Assets/Scripts/Board.cs.meta new file mode 100644 index 0000000..d35cfd9 --- /dev/null +++ b/Assets/Scripts/Board.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0d4fe201741a0f14c82a9ce960b9f5e4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Ghost.cs b/Assets/Scripts/Ghost.cs new file mode 100644 index 0000000..094c7bf --- /dev/null +++ b/Assets/Scripts/Ghost.cs @@ -0,0 +1,76 @@ +using UnityEngine; +using UnityEngine.Tilemaps; + +public class Ghost : MonoBehaviour +{ + public Tile tile; + public Board board; + public Piece trackingPiece; + + public Tilemap tilemap { get; private set; } + public Vector3Int[] cells { get; private set; } + public Vector3Int position { get; private set; } + + private void Awake() + { + this.tilemap = GetComponentInChildren(); + this.cells = new Vector3Int[4]; + } + + private void LateUpdate() + { + Clear(); + Copy(); + Drop(); + Set(); + } + + private void Clear() + { + for (int i = 0; i < this.cells.Length; i++) + { + Vector3Int tilePosition = this.cells[i] + this.position; + this.tilemap.SetTile(tilePosition, null); + } + } + + private void Copy() + { + for (int i = 0; i < this.cells.Length; i++) { + this.cells[i] = this.trackingPiece.cells[i]; + } + } + + private void Drop() + { + Vector3Int position = this.trackingPiece.position; + + int current = position.y; + int bottom = -this.board.boardSize.y / 2 - 1; + + this.board.Clear(this.trackingPiece); + + for (int row = current; row >= bottom; row--) + { + position.y = row; + + if (this.board.IsValidPosition(this.trackingPiece, position)) { + this.position = position; + } else { + break; + } + } + + this.board.Set(this.trackingPiece); + } + + private void Set() + { + for (int i = 0; i < this.cells.Length; i++) + { + Vector3Int tilePosition = this.cells[i] + this.position; + this.tilemap.SetTile(tilePosition, this.tile); + } + } + +} diff --git a/Assets/Scripts/Ghost.cs.meta b/Assets/Scripts/Ghost.cs.meta new file mode 100644 index 0000000..908475d --- /dev/null +++ b/Assets/Scripts/Ghost.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8d159ef6a04487d48afc5338ee3de43c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Piece.cs b/Assets/Scripts/Piece.cs new file mode 100644 index 0000000..d8e91df --- /dev/null +++ b/Assets/Scripts/Piece.cs @@ -0,0 +1,198 @@ +using UnityEngine; + +public class Piece : MonoBehaviour +{ + public Board board { get; private set; } + public TetrominoData data { get; private set; } + public Vector3Int[] cells { get; private set; } + public Vector3Int position { get; private set; } + public int rotationIndex { get; private set; } + + public float stepDelay = 1f; + public float moveDelay = 0.1f; + public float lockDelay = 0.5f; + + private float stepTime; + private float moveTime; + private float lockTime; + + public void Initialize(Board board, Vector3Int position, TetrominoData data) + { + this.board = board; + this.position = position; + this.rotationIndex = 0; + this.data = data; + + this.stepTime = Time.time + this.stepDelay; + this.moveTime = Time.time + this.moveDelay; + this.lockTime = 0f; + + UpdateCells(); + } + + private void UpdateCells() + { + if (this.cells == null) { + this.cells = new Vector3Int[this.data.cells.Length]; + } + + for (int i = 0; i < this.cells.Length; i++) { + this.cells[i] = (Vector3Int)this.data.rotations[this.rotationIndex, i]; + } + } + + private void Update() + { + this.board.Clear(this); + + // We use a timer to allow the player to make adjustments to the piece + // before it locks in place + this.lockTime += Time.deltaTime; + + // Handle rotation + if (Input.GetKeyDown(KeyCode.Q)) { + Rotate(-1); + } else if (Input.GetKeyDown(KeyCode.E)) { + Rotate(1); + } + + // Handle hard drop + if (Input.GetKeyDown(KeyCode.Space)) { + HardDrop(); + } + + // Allow the player to hold movement keys but only after a move delay + // so it does not move too fast + if (Time.time > this.moveTime) { + HandleMoveInputs(); + } + + // Advance the piece to the next row every x seconds + if (Time.time > this.stepTime) { + Step(); + } + + this.board.Set(this); + } + + private void HandleMoveInputs() + { + this.moveTime = Time.time + this.moveDelay; + + // Soft drop movement + if (Input.GetKey(KeyCode.S)) { + Move(Vector2Int.down); + } + + // Left/right movement + if (Input.GetKey(KeyCode.A)) { + Move(Vector2Int.left); + } else if (Input.GetKey(KeyCode.D)) { + Move(Vector2Int.right); + } + } + + private void Step() + { + this.stepTime = Time.time + this.stepDelay; + + // Do not move down if the player is already holding down + // otherwise it can cause a double movement + if (!Input.GetKey(KeyCode.S)) { + Move(Vector2Int.down); + } + + // Once the piece has been inactive for too long it becomes locked + if (this.lockTime >= this.lockDelay) { + Lock(); + } + } + + private void HardDrop() + { + while (Move(Vector2Int.down)) { + continue; + } + + Lock(); + } + + private void Lock() + { + this.board.Set(this); + this.board.ClearLines(); + this.board.SpawnPiece(); + } + + private bool Move(Vector2Int translation) + { + Vector3Int newPosition = this.position; + newPosition.x += translation.x; + newPosition.y += translation.y; + + bool valid = this.board.IsValidPosition(this, newPosition); + + // Only save the movement if the new position is valid + if (valid) + { + this.position = newPosition; + this.lockTime = 0f; // reset + } + + return valid; + } + + private void Rotate(int direction) + { + // Store the current rotation in case the rotation fails and we need to revert + int originalRotation = this.rotationIndex; + + // Update the cell data to the new rotation + this.rotationIndex = Wrap(this.rotationIndex + direction, 0, 4); + UpdateCells(); + + // Revert the rotation if the wall kick tests fail + if (!TestWallKicks(direction)) + { + this.rotationIndex = originalRotation; + UpdateCells(); + } + } + + private bool TestWallKicks(int rotationDirection) + { + int wallKickIndex = GetWallKickIndex(rotationDirection); + + for (int i = 0; i < 5; i++) + { + Vector2Int translation = this.data.wallKicks[wallKickIndex, i]; + + if (Move(translation)) { + return true; + } + } + + return false; + } + + private int GetWallKickIndex(int rotationDirection) + { + int wallKickIndex = this.rotationIndex * 2; + + if (rotationDirection < 0) { + wallKickIndex--; + } + + return Wrap(wallKickIndex, 0, this.data.wallKicks.GetLength(0)); + } + + private int Wrap(int input, int min, int max) + { + if (input < min) { + return max - (min - input) % (max - min); + } else { + return min + (input - min) % (max - min); + } + } + +} diff --git a/Assets/Scripts/Piece.cs.meta b/Assets/Scripts/Piece.cs.meta new file mode 100644 index 0000000..3d6d482 --- /dev/null +++ b/Assets/Scripts/Piece.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b6570178d836e8642a13a0b983600cf3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tiles/Ghost.asset b/Assets/Tiles/Ghost.asset new file mode 100644 index 0000000..7519450 --- /dev/null +++ b/Assets/Tiles/Ghost.asset @@ -0,0 +1,36 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 13312, guid: 0000000000000000e000000000000000, type: 0} + m_Name: Ghost + m_EditorClassIdentifier: + m_Sprite: {fileID: 21300000, guid: de0f4de3209ba2c42874afb3c5329c15, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_Transform: + e00: 1 + e01: 0 + e02: 0 + e03: 0 + e10: 0 + e11: 1 + e12: 0 + e13: 0 + e20: 0 + e21: 0 + e22: 1 + e23: 0 + e30: 0 + e31: 0 + e32: 0 + e33: 1 + m_InstancedGameObject: {fileID: 0} + m_Flags: 1 + m_ColliderType: 1 diff --git a/Assets/Tiles/Ghost.asset.meta b/Assets/Tiles/Ghost.asset.meta new file mode 100644 index 0000000..fcec1d2 --- /dev/null +++ b/Assets/Tiles/Ghost.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a10927dec698b7c49b1375f89e8db4d2 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: