Exemplo n.º 1
0
def test_concave_no_collision():
    poly_a_points = [(3, 3), (5, 3), (5, 4), (4, 4), (4, 5), (5, 5), (5, 6),
                     (3, 6)]
    poly_b_points = [(6.5, 3.5), (8, 2), (8, 4)]

    poly_a = ConcaveCollider(poly_a_points)
    poly_b = ConvexCollider(poly_b_points)

    assert poly_a.collide(poly_b) is False
Exemplo n.º 2
0
def test_concave_convex_collision():
    poly_a_points = [(3, 3), (5, 3), (5, 4), (4, 4), (4, 5), (5, 5), (5, 6),
                     (3, 6)]
    poly_b_points = [(4.5, 3.5), (6, 2), (6, 4)]

    poly_a = ConcaveCollider(poly_a_points)
    poly_b = ConvexCollider(poly_b_points)

    assert poly_a.collide(poly_b) is True
Exemplo n.º 3
0
def test_move_concave():
    poly_points = [(3, 3), (5, 3), (5, 4), (4, 4), (4, 5), (5, 5), (5, 6),
                   (3, 6)]

    collider = ConcaveCollider(poly_points)

    collider.bottomright = (8, 9)

    assert collider.bottomright == (8, 9)
    assert collider.center == (7.0, 7.5)
Exemplo n.º 4
0
def test_concave_concave_collision():
    poly_a_points = [(3, 3), (5, 3), (5, 4), (4, 4), (4, 5), (5, 5), (5, 6),
                     (3, 6)]
    poly_b_points = [(6.5, 5.5), (4.5, 5.5), (4.5, 6.5), (5.5, 6.5),
                     (5.5, 7.5), (4.5, 7.5), (4.5, 8.5), (6.5, 8.5)]

    poly_a = ConcaveCollider(poly_a_points)
    poly_b = ConcaveCollider(poly_b_points)

    assert poly_a.collide(poly_b) is True
Exemplo n.º 5
0
def test_get_concave_center():
    poly_points = [(3, 3), (5, 3), (5, 4), (4, 4), (4, 5), (5, 5), (5, 6),
                   (3, 6)]

    collider = ConcaveCollider(poly_points)

    assert collider.center == (4.0, 4.5)
Exemplo n.º 6
0
def create_collider(points: List[Tuple[float]], data: Any = None):
    """
    Create correct collider type from given set of points.

    .. code-block:: python

        collider_points = [(3, 3), (5, 3), (5, 4), (4, 4), (4, 5), (5, 5), (5, 6), (3, 6)]
        collider = create_collider(collider_points)

    :param points: A list of coordinate pairs that forms given collider.
    :param data: Any data associated with the collider
    :return: Correct collider type
    :rtype: ConvexCollider or ConcaveCollider
    """
    # Try out first concave
    if _is_concave(points):
        return ConcaveCollider(points, data)
    elif _is_convex(points):
        return ConvexCollider(points, data)
    else:
        raise TypeError("Invalid collider data.")
Exemplo n.º 7
0
gameDisplay = pygame.display.set_mode((400, 300))
gameDisplay.fill(black)
pygame.draw.polygon(gameDisplay, green,
                    ((48, 191), (36, 175), (159, 90), (171, 105)))
pygame.draw.circle(gameDisplay, green, (90, 299 - 70), 35)
pygame.draw.ellipse(gameDisplay, green, [186, 300 - 175, 120, 60])
pygame.draw.polygon(gameDisplay, green,
                    ((200, 70), (200, 20), (230, 20), (230, 30), (210, 30),
                     (210, 60), (230, 60), (230, 70)))

cyan = 0, 255, 255
collider_a_points = [(48, 191), (36, 175), (159, 90), (171, 105)]
collider_c_points = [(200, 70), (200, 20), (230, 20), (230, 30), (210, 30),
                     (210, 60), (230, 60), (230, 70)]

collider_a = ConcaveCollider(collider_a_points)
collider_c = ConcaveCollider(collider_c_points)


def collides_pol(a, b):

    collider_b_points = [(a + rad / 2 + clear, b + rad / 2 + clear)]
    collider_b = ConvexCollider(collider_b_points)

    if collider_a.collide(collider_b) or collider_c.collide(collider_b):
        print("Collision detected")
        return True
    return False


def collides_circle(a, b):