public void MoveTetromino(Vector3 center, Tetromino tetromino)
 {
     for (var i = 0; i < tetromino.BlockCount; i++)
     {
         var localPos = tetromino.GetLocalBlockPosition(i);
         var pos      = center + new Vector3(localPos.x, localPos.y, 0);
         tetromino.MoveBlock(i, pos);
     }
 }
        public void UpdateTetrominoPositionInGrids(Tetromino tetromino)
        {
            var center = tetromino.Center;

            for (var i = 0; i < tetromino.BlockCount; i++)
            {
                var gridPos = center + tetromino.GetLocalBlockPosition(i);
                var pos     = GetBlockPosition(gridPos);
                tetromino.MoveBlock(i, pos);
            }
        }
Example #3
0
        /// <summary>
        /// add the current blocks to grids
        /// </summary>
        /// <returns> min height and max height of the added blocks </returns>
        public Vector2Int AddToGrid(Tetromino tetromino)
        {
            var center    = tetromino.Center;
            var minHeight = grids.GetLength(1) - 1;
            var maxHeight = 0;

            for (var i = 0; i < tetromino.BlockCount; i++)
            {
                var localPos = tetromino.GetLocalBlockPosition(i);
                var blockPos = center + localPos;
                grids[blockPos.x, blockPos.y] = tetromino.GetBlock(i);
                minHeight = Mathf.Min(blockPos.y, minHeight);
                maxHeight = Mathf.Max(blockPos.y, maxHeight);
            }

            return(new Vector2Int(minHeight, maxHeight));
        }
Example #4
0
        public bool InvalidMove(Tetromino tetromino)
        {
            var center = tetromino.Center;

            for (var i = 0; i < tetromino.BlockCount; i++)
            {
                var localPos = tetromino.GetLocalBlockPosition(i);
                var gridPos  = center + localPos;

                if (gridPos.x < 0 || grids.GetLength(0) <= gridPos.x || gridPos.y < 0 || grids.GetLength(1) <= gridPos.y)
                {
                    return(true);
                }

                if (grids[gridPos.x, gridPos.y] != null)
                {
                    return(true);
                }
            }

            return(false);
        }