示例#1
0
    // After a piece is translated or rotated, call this method to find out if the
    // piece is now on top of another or on top of the floor and therefore should
    // be freezed.
    public bool MaybeFreezePiece(GameObject piece)
    {
        bool freeze = false;

        foreach (Transform cube in piece.transform)
        {
            int plane = TetrisHelpers.GetPieceCubePlane(cube);
            int row   = TetrisHelpers.GetPieceCubeRow(cube);
            int col   = TetrisHelpers.GetPieceCubeColumn(cube);

            // Touching the floor.
            if (plane == 0)
            {
                freeze = true;
                break;
            }

            // Cube is on top of a cube from a previously frozen piece.
            if (grid[plane - 1, row, col] != null)
            {
                freeze = true;
                break;
            }
        }

        if (freeze)
        {
            FreezePiece(piece);
        }

        return(freeze);
    }
示例#2
0
    private string GridIndexString(Transform cube)
    {
        int plane = TetrisHelpers.GetPieceCubePlane(cube);
        int row   = TetrisHelpers.GetPieceCubeRow(cube);
        int col   = TetrisHelpers.GetPieceCubeColumn(cube);

        return("[" + plane + ", " + row + ", " + col + "]");
    }
示例#3
0
    private void FreezePiece(GameObject piece)
    {
        foreach (Transform cube in piece.transform)
        {
            int plane = TetrisHelpers.GetPieceCubePlane(cube);
            int row   = TetrisHelpers.GetPieceCubeRow(cube);
            int col   = TetrisHelpers.GetPieceCubeColumn(cube);

            FreezeCube(cube, plane, row, col);
        }

        piece.transform.DetachChildren();
        Destroy(piece);
        ProcessFullPlanes();
    }
示例#4
0
    // Check if we can move a piece along the Z axis by a certain amount.
    // If any of the cubes goes off the grid, we can not move the piece.
    private bool CanMovePieceAxisZ(int amount)
    {
        bool canMove = true;

        foreach (Transform cube in transform)
        {
            int plane   = TetrisHelpers.GetPieceCubePlane(cube);
            int row     = TetrisHelpers.GetPieceCubeRow(cube);
            int col     = TetrisHelpers.GetPieceCubeColumn(cube);
            int nextCol = col + amount;

            if (nextCol < 0)
            {
                canMove = false;
                break;
            }
            if (nextCol >= GameSettings.columnsPerPlane)
            {
                canMove = false;
                break;
            }

            if (GridManager.gm.GridCellOccupied(plane, row, nextCol))
            {
                canMove = false;
                break;
            }
        }

        if (canMove)
        {
            AudioSource.PlayClipAtPoint(moveSFX, transform.position);
        }
        else
        {
            AudioSource.PlayClipAtPoint(canNotMoveSFX, transform.position);
        }

        return(canMove);
    }
示例#5
0
    private bool InvalidPosition(bool ignoreYPosition = false)
    {
        foreach (Transform cube in transform)
        {
            int plane = TetrisHelpers.GetPieceCubePlane(cube);
            int row   = TetrisHelpers.GetPieceCubeRow(cube);
            int col   = TetrisHelpers.GetPieceCubeColumn(cube);

            // One cube of the piece is going outside the game grid...
            if (row < 0 || row >= GameSettings.rowsPerPlane ||
                col < 0 || col >= GameSettings.columnsPerPlane)
            {
                return(true);
            }

            if (!ignoreYPosition)
            {
                if (plane < 0 || plane >= GameSettings.numberOfPlanes)
                {
                    return(true);
                }
            }

            if (ignoreYPosition && plane >= GameSettings.numberOfPlanes)
            {
                continue;
            }

            // One cube of the piece is in a grid position that alreay has a cube
            // from a previous piece...
            if (GridManager.gm.GridCellOccupied(plane, row, col))
            {
                return(true);
            }
        }

        return(false);
    }