def update_cue_displacement(self, mouse_pos, initial_mouse_dist): displacement = physics.point_distance( mouse_pos, self.target_ball.ball.pos) - initial_mouse_dist + config.ball_radius if displacement > config.cue_max_displacement: self.displacement = config.cue_max_displacement elif displacement < config.ball_radius: self.displacement = config.ball_radius else: self.displacement = displacement
def cue_is_active(self, game_state, events): try: self.angle = events['angle'] print(self.angle, events["displacement"]) self.displacement = events["displacement"] except KeyError: try: initial_mouse_pos = events["mouse_pos"] initial_mouse_dist = physics.point_distance( initial_mouse_pos, self.target_ball.ball.pos) while events["clicked"]: events = event.events() self.update_cue(game_state, initial_mouse_dist, events) except KeyError: pass # undraw leftover aiming lines self.draw_lines(game_state, self.target_ball, self.angle + math.pi, config.table_color) if self.displacement > config.ball_radius+config.cue_safe_displacement: self.ball_hit()
def test_point_distance1(self): assert physics.point_distance(np.array([0, 0]), np.array([3, 4])) == 5
def test_point_distance2(self): assert physics.point_distance(np.array([0, -10]), np.array([0, -10])) == 0
def test_point_distance3(self): assert physics.point_distance(np.array([10, 0]), np.array([-10, 0])) == 20