def collision(self, other): down1 = ((other.x - 29, other.y - 15), (other.x + 29, other.y - 15), (other.x + 29, other.y - 14), (other.x - 29, other.y - 14)) up1 = ((other.x - 29, other.y + 15), (other.x + 29, other.y + 15), (other.x + 29, other.y + 16), (other.x - 29, other.y + 16)) left1 = ((other.x - 30, other.y - 15), (other.x - 29, other.y - 15), (other.x - 29, other.y + 15), (other.x - 30, other.y + 15)) right1 = ((other.x + 29, other.y - 15), (other.x + 30, other.y - 15), (other.x + 30, other.y + 15), (other.x + 29, other.y + 15)) ball = ((self.x - 10, self.y - 10), (self.x + 10, self.y - 10), (self.x + 10, self.y + 10), (self.x - 10, self.y + 10)) s = "" if arcade.are_polygons_intersecting(ball, down1): self.y = other.y - (15 + self.radius + 1) s += "y" if arcade.are_polygons_intersecting(ball, up1): self.y = other.y + (15 + self.radius + 1) if s == "": s += "y" if arcade.are_polygons_intersecting(ball, left1): self.x = other.x - (30 + self.radius + 1) s += "x" if arcade.are_polygons_intersecting(ball, right1): self.x = other.x + (30 + self.radius + 1) if len(s) == 1: s += "x" return s
def _check_for_collision(sprite1: Sprite, sprite2: Sprite) -> bool: """ Check for collision between two sprites. :param Sprite sprite1: Sprite 1 :param Sprite sprite2: Sprite 2 :returns: True if sprites overlap. :rtype: bool """ collision_radius_sum = sprite1.collision_radius + sprite2.collision_radius diff_x = sprite1.position[0] - sprite2.position[0] diff_x2 = diff_x * diff_x if diff_x2 > collision_radius_sum * collision_radius_sum: return False diff_y = sprite1.position[1] - sprite2.position[1] diff_y2 = diff_y * diff_y if diff_y2 > collision_radius_sum * collision_radius_sum: return False distance = diff_x2 + diff_y2 if distance > collision_radius_sum * collision_radius_sum: return False return are_polygons_intersecting(sprite1.get_adjusted_hit_box(), sprite2.get_adjusted_hit_box())
def _bip(self, objects): self.detects = False for o in objects: if arcade.are_polygons_intersecting(self._get_points(), o): self.detects = True break return self.detects
def _check_for_collision(sprite1: Sprite, sprite2: Sprite) -> bool: """ Check for collision between two sprites. :param Sprite sprite1: Sprite 1 :param Sprite sprite2: Sprite 2 :returns: Boolean """ collision_radius_sum = sprite1.collision_radius + sprite2.collision_radius diff_x = sprite1.position[0] - sprite2.position[0] diff_x2 = diff_x * diff_x if diff_x2 > collision_radius_sum * collision_radius_sum: return False diff_y = sprite1.position[1] - sprite2.position[1] diff_y2 = diff_y * diff_y if diff_y2 > collision_radius_sum * collision_radius_sum: return False distance = diff_x2 + diff_y2 if distance > collision_radius_sum * collision_radius_sum: return False return are_polygons_intersecting(sprite1.points, sprite2.points)
def collided_with(self, sprite: arcade.Sprite) -> bool: """ Check if this obstacle has collided with the given sprite. :param sprite: to check collision for. :return: True if collision detected. """ return arcade.are_polygons_intersecting(self.points, sprite.points)
def update(self, delta_time): """ All the logic to move, and the game logic goes here. Normally, you'll call update() on the sprite lists that need it. """ if self.is_new_game == True: self.new_timer = self.new_timer - delta_time self.start_timer.set_text(str(int(self.new_timer))) if self.new_timer <= 0.0: self.is_new_game = False self.new_timer = 4.0 return if self.is_need_jump == True: self.bird.vel = Vector(0, 4) self.is_need_jump = False gravity = Vector(0, -0.2) self.bird.apply_force(gravity) self.bird.update() self.spawner.update(delta_time) deleted_tubes = [] for tube in self.spawner.get_tubes(): tube.update() if tube.need_delete == True: deleted_tubes.append(tube) need_start_new_game = False for tube in self.spawner.get_tubes(): bird_points = self.bird.get_points() tube_points = tube.get_points() collision = arcade.are_polygons_intersecting( bird_points, tube_points) if collision == True: need_start_new_game = True break for tube in deleted_tubes: self.spawner.get_tubes().remove(tube) if self.bird.pos.y <= 0: need_start_new_game = True if need_start_new_game == True: self.start_new_game()
def _check_collides(self): self.collides = False for o in self._terrain: if arcade.are_polygons_intersecting(self.get_points(), o): self.collides = True break