コード例 #1
0
ファイル: Grid.cs プロジェクト: AlexBraginets/Unity_Tetris_01
    // checks whether there would be a collison of the tetramino with the grid if the tetramino
    // was moved by offset and rotated according to rotation type
    public static bool Collision
        (Grid grid, Tetramino tetramino, Vector2Int offset, Tetramino.RotationType rotation)
    {
        bool collision = false;

        Vector2Int[] tryPoses = tetramino.GetAbsPoses(offset, rotation);
        foreach (Vector2Int pos in tryPoses)
        {
            if (0 <= pos.x && pos.x < grid.blocks.GetLength(0) &&
                0 <= pos.y && pos.y < grid.blocks.GetLength(1))
            {
                collision = grid[pos] != null;
            }
            else
            {
                collision = true;
            }
            if (collision)
            {
                break;
            }
        }
        return(collision);
    }
コード例 #2
0
 // returns cells' WORLD coordinates if the tetramino was moved by offset & rotated according to rotation type
 public Vector2Int[] GetAbsPoses(Vector2Int offset, Tetramino.RotationType rotation)
 {
     Vector2Int[] rotated = RotateArray(Poses, rotationPoint, rotation);
     return(VectorUtil.Add(rotated, centerPos + offset));
 }