Example #1
0
    public List <Vector2Int> GetRelativeLocationFromPoint(int x, int y, RotationDirection direction)
    {
        List <Vector2Int> relativeLocations = new List <Vector2Int>();

        PieceDimension rotatedPieceLocations = GetRotatedPieceDimension(PieceInfo, direction);

        for (int i = 0; i < rotatedPieceLocations.PieceDimensions.GetLength(0); i++)
        {
            for (int k = 0; k < rotatedPieceLocations.PieceDimensions.GetLength(1); k++)
            {
                if (!rotatedPieceLocations.PieceDimensions[i, k])
                {
                    continue;
                }

                Vector2Int offsetLocation = rotatedPieceLocations.GetRelativeIndex(i, k);
                relativeLocations.Add(new Vector2Int(x + offsetLocation.x, y + offsetLocation.y));
            }
        }

        return(relativeLocations);
    }
Example #2
0
    public PieceDimension GetRotatedPieceDimension(PieceDimension normalDimensions, RotationDirection direction)
    {
        PieceDimension rotatedDirection = new PieceDimension();

        bool[,] PieceDimensions = normalDimensions.PieceDimensions;


        switch (direction)
        {
        case RotationDirection.Normal:
        case RotationDirection.Rotate180:
        {
            rotatedDirection.PieceDimensions = new bool[PieceDimensions.GetLength(0), PieceDimensions.GetLength(1)];
            int newRow    = 0;
            int newColumn = 0;

            for (int i = 0; i < PieceDimensions.GetLength(0); i++)
            {
                newColumn = 0;
                for (int k = 0; k < PieceDimensions.GetLength(1); k++)
                {
                    int checkIndex = direction == RotationDirection.Rotate180 ? PieceDimensions.GetLength(1) - k - 1 : k;
                    rotatedDirection.PieceDimensions[newRow, newColumn] = PieceDimensions[i, checkIndex];

                    // Add in the new pivotPoint into this location
                    if (normalDimensions.PivotPoint.x == i && normalDimensions.PivotPoint.y == k)
                    {
                        rotatedDirection.PivotPoint = new Vector2Int(newRow, newColumn);
                    }

                    newColumn++;
                }
                newRow++;
            }
            break;
        }

        case RotationDirection.Rotate90:
        case RotationDirection.Rotate270:
        {
            rotatedDirection.PieceDimensions = new bool[PieceDimensions.GetLength(1), PieceDimensions.GetLength(0)];
            int newRow    = 0;
            int newColumn = 0;

            for (int i = 0; i < PieceDimensions.GetLength(1); i++)
            {
                newColumn = 0;
                for (int k = 0; k < PieceDimensions.GetLength(0); k++)
                {
                    int checkIndex = direction == RotationDirection.Rotate270 ? PieceDimensions.GetLength(0) - k - 1 : k;
                    rotatedDirection.PieceDimensions[newRow, newColumn] = PieceDimensions[i, checkIndex];

                    // Add in the new pivotPoint into this location
                    if (normalDimensions.PivotPoint.x == i && normalDimensions.PivotPoint.y == checkIndex)
                    {
                        rotatedDirection.PivotPoint = new Vector2Int(newRow, newColumn);
                    }

                    newColumn++;
                }
                newRow++;
            }
        }
        break;
        }

        return(rotatedDirection);
    }