def reflected_velocity(self, delta_time: float, boid: Boid) -> Tuple[float, float]: """Returns the x and y movements, if these would take the boid outside of the window boundary then (0, 0) is returned and the velocity is reflected""" x_velocity = boid.x_velocity y_velocity = boid.y_velocity delta_x = x_velocity * delta_time delta_y = y_velocity * delta_time if self.on_border(boid, delta_x, delta_y): if self.on_vertical_border(boid, delta_y): x_velocity = -x_velocity if self.on_horizontal_border(boid, delta_x): y_velocity = -y_velocity rotation = Vector(x_velocity, y_velocity).rotation_normalized() * 3.14 if x_velocity < 0: boid.rotation = rotation else: boid.rotation = -rotation return (0, 0) else: return (delta_x, delta_y)