def reset(self): self.rect.center = CENTER self.speed = 10 if random.random() < 0.5: self.orientation = Vector2.Right() else: self.orientation = Vector2.Left()
def calc_bounce_angle(self, pos): pos = Vector2(pos) ball_pos = Vector2(self.ball.rect.center) delta = pos.y - ball_pos.y delta = min(delta, 55) if delta > 0 else max(delta, -55) if ball_pos.x < pos.x: # Bounces on right paddle result = Vector2.Left() result.theta = pi + delta * pi / 200 else: result = Vector2.Right() result.theta = -delta * pi / 200 return result
def test_create_unitary_axis_vectors_right(): left = Vector2.Right() assert left.x == 1 assert left.y == 0