Ejemplo n.º 1
0
 def create_white_ball(self):
     self.white_ball = ball.BallSprite(0)
     ball_pos = config.white_ball_initial_pos
     while check_if_ball_touches_balls(ball_pos, 0, self.balls):
         ball_pos = [random.randint(int(config.table_margin + config.ball_radius + config.hole_radius),
                                    int(config.white_ball_initial_pos[0])),
                     random.randint(int(config.table_margin + config.ball_radius + config.hole_radius),
                                    int(config.resolution[1] - config.ball_radius - config.hole_radius))]
     self.white_ball.move_to(ball_pos)
     self.balls.add(self.white_ball)
     self.all_sprites.add(self.white_ball)
Ejemplo n.º 2
0
    def is_active(self, game_state, behind_separation_line=False):
        game_state.cue.make_invisible()
        events = event.events()

        while events["clicked"]:
            events = event.events()
            if np.all(np.less(config.table_margin + config.ball_radius + config.hole_radius, events["mouse_pos"])) and \
                    np.all(np.greater(config.resolution - config.table_margin - config.ball_radius - config.hole_radius,
                                      events["mouse_pos"])) and \
                    not collisions.check_if_ball_touches_balls(events["mouse_pos"], self.number, game_state.balls):
                if behind_separation_line:
                    if events["mouse_pos"][0] <= config.white_ball_initial_pos[0]:
                        self.move_to(events["mouse_pos"])
                else:
                    self.move_to(events["mouse_pos"])
            game_state.redraw_all()
        game_state.cue.make_visible(game_state.current_player)
Ejemplo n.º 3
0
 def is_active(self, game_state, behind_separation_line=False):
     game_state.cue.make_invisible()
     events = event.events()
     
     while events["clicked"]:
         events = event.events()
         #print("自行移動白球知道最大(x,y):",self.ball.pos)
         self.white_ball_now=self.ball.pos
         # checks if the user isn't trying to place the ball out of the table or inside another ball
         if np.all(np.less(config.table_margin + config.ball_radius + config.hole_radius, events["mouse_pos"])) and \
                 np.all(np.greater(config.resolution - config.table_margin - config.ball_radius - config.hole_radius,
                                   events["mouse_pos"])) and \
                 not collisions.check_if_ball_touches_balls(events["mouse_pos"], self.number, game_state.balls):
             if behind_separation_line:
                 if events["mouse_pos"][0] <= config.white_ball_initial_pos[0]:
                     self.move_to(events["mouse_pos"])
             else:
                 self.move_to(events["mouse_pos"])
         game_state.redraw_all()
     game_state.cue.make_visible(game_state.current_player)
Ejemplo n.º 4
0
 def create_white_ball(self):
     self.white_ball = ball.BallSprite(0)
     #print(config.white_ball_initial_pos)
     ball_pos = config.white_ball_initial_pos  #sets the intial position of the white ball yoooooo ----- change this
     #print("ball pos:", str(ball_pos))
     #print(self.balls)
     while check_if_ball_touches_balls(ball_pos, 0,
                                       self.balls):  #moves bad ball?
         #print(ball_pos)
         #print("111111")
         ball_pos = [
             random.randint(
                 int(config.table_margin + config.ball_radius +
                     config.hole_radius),
                 int(config.white_ball_initial_pos[0])),
             random.randint(
                 int(config.table_margin + config.ball_radius +
                     config.hole_radius),
                 int(config.resolution[1] - config.ball_radius -
                     config.hole_radius))
         ]
     self.white_ball.move_to(ball_pos)
     self.balls.append(self.white_ball)
     self.all_sprites.append(self.white_ball)