def collided_with(self, x: float, y: float) -> bool:
        if arcade.is_point_in_polygon(x, y, self.top_points):
            return True

        if arcade.is_point_in_polygon(x, y, self.left_points):
            return True

        if arcade.is_point_in_polygon(x, y, self.bottom_points):
            return True

        if arcade.is_point_in_polygon(x, y, self.right_points):
            return True

        return False
Esempio n. 2
0
def get_sprites_at_point(point: Point,
                         sprite_list: SpriteList) -> List[Sprite]:
    """
    Get a list of sprites at a particular point

    :param Point point: Point to check
    :param SpriteList sprite_list: SpriteList to check against

    :returns: List of sprites colliding, or an empty list.
    """
    if not isinstance(sprite_list, SpriteList):
        raise TypeError(
            f"Parameter 2 is a {type(sprite_list)} instead of expected SpriteList."
        )

    if sprite_list.use_spatial_hash:
        sprite_list_to_check = sprite_list.spatial_hash.get_objects_for_point(
            point)
        # checks_saved = len(sprite_list) - len(sprite_list_to_check)
        # print("Checks saved: ", checks_saved)
    else:
        sprite_list_to_check = sprite_list

    collision_list = [
        sprite2 for sprite2 in sprite_list_to_check if is_point_in_polygon(
            point[0], point[1], sprite2.get_adjusted_hit_box())
    ]

    return collision_list
Esempio n. 3
0
 def on_mouse_press(self, x: float, y: float, button: int, modifiers: int):
     if self.player.state == PlayerStates.WAITING and arcade.is_point_in_polygon(
         x, y, self.player.get_adjusted_hit_box()
     ):
         # player_obj = self.physics_engine.get_physics_object(self.player)
         # player_obj.body_type = arcade.PymunkPhysicsEngine.KINEMATIC
         self.player.state = PlayerStates.DRAGGING
Esempio n. 4
0
 def collided_with(self, x: float, y: float) -> bool:
     for side in [
             self.top_points, self.right_points, self.bottom_points,
             self.left_points
     ]:
         if _arcade.is_point_in_polygon(x, y, side):
             return True
     return False
Esempio n. 5
0
    def collided_with(self, x: float, y: float) -> bool:
        """
        Check if this obstacle has collided with the given Point. Meaning the point is inside this obstacle
        :param x: coordinate of the  point.
        :param y: coordinate of the point.
        :return: True if collision detected.
        """

        return arcade.is_point_in_polygon(x, y, self.points)
Esempio n. 6
0
def test_point_in_rectangle():
    polygon = [
        (0, 0),
        (0, 50),
        (50, 50),
        (50, 0),
    ]
    result = arcade.is_point_in_polygon(25, 25, polygon)
    assert result is True
Esempio n. 7
0
def test_point_not_in_empty_polygon():
    polygon = []
    result = arcade.is_point_in_polygon(25, 25, polygon)
    assert result is False
Esempio n. 8
0
 def get_triangle_coordinate_in_position(self, x, y):
     for i, row in enumerate(self.board_coordinates):
         for j, point_list in enumerate(row):
             if arcade.is_point_in_polygon(x, y, point_list):
                 return self.get_board_coordinate(i, j)
     return None