def update_cue(self, game_state, initial_mouse_dist, events):
# updates cue position
current_mouse_pos = events["mouse_pos"]
displacement_from_ball_to_mouse = self.target_ball.ball.pos - current_mouse_pos
self.update_cue_displacement(current_mouse_pos, initial_mouse_dist)
prev_angle = self.angle
# hack to avoid div by zero
if not displacement_from_ball_to_mouse[0] == 0:
self.angle = 0.5 * math.pi - math.atan(
displacement_from_ball_to_mouse[1] / displacement_from_ball_to_mouse[0])
if displacement_from_ball_to_mouse[0] > 0:
self.angle -= math.pi
game_state.redraw_all(update=False)
self.draw_lines(game_state, self.target_ball, prev_angle +
math.pi, config.table_color)
self.draw_lines(game_state, self.target_ball, self.angle +
math.pi, (255, 255, 255))
pygame.display.flip()
评论列表
文章目录