Exemplo n.º 1
0
def resolve_all_collisions(balls, holes, table_sides):
    # destroys any circles that are in a hole
    for ball_hole_combination in itertools.product(balls, holes):
        if physics.distance_less_equal(ball_hole_combination[0].ball.pos,
                                       ball_hole_combination[1].pos,
                                       config.hole_radius):
            zope.event.notify(
                event.GameEvent("POTTED", ball_hole_combination[0]))

    # collides balls with the table where it is needed
    for line_ball_combination in itertools.product(table_sides, balls):
        if physics.line_ball_collision_check(line_ball_combination[0],
                                             line_ball_combination[1].ball):
            physics.collide_line_ball(line_ball_combination[0],
                                      line_ball_combination[1].ball)

    ball_list = balls.sprites()
    # ball list is shuffled to randomize ball collisions on the 1st break
    random.shuffle(ball_list)

    for ball_combination in itertools.combinations(ball_list, 2):
        if physics.ball_collision_check(ball_combination[0].ball,
                                        ball_combination[1].ball):
            physics.collide_balls(ball_combination[0].ball,
                                  ball_combination[1].ball)
            zope.event.notify(event.GameEvent("COLLISION", ball_combination))
Exemplo n.º 2
0
    def test_movement11(self):
        # stationary balls do not collide to conserve unnecessary computations
        ball1.set_velocity((0, 0))

        ball2.move_to((0, ball_radius * 2))
        ball2.set_velocity((0, 0))
        assert not physics.ball_collision_check(ball1, ball2)
Exemplo n.º 3
0
    def test_movement7(self):
        ball1.set_velocity((0, 1))

        ball2.move_to((0, ball_radius * 2))
        ball2.set_velocity((200000000, 0))
        assert physics.ball_collision_check(ball1, ball2)
Exemplo n.º 4
0
    def test_movement5(self):
        ball1.set_velocity((1, 1))

        ball2.move_to(-fortyfive_degree_position)
        ball2.set_velocity((1.1, 1))
        assert physics.ball_collision_check(ball1, ball2)
Exemplo n.º 5
0
    def test_movement1(self):
        ball1.set_velocity((1, 1))

        ball2.move_to((-ball_radius, 0))
        ball2.set_velocity((0, 0))
        assert not physics.ball_collision_check(ball1, ball2)
Exemplo n.º 6
0
 def test_distance6(self):
     ball2.move_to(fortyfive_degree_position)
     ball2.set_velocity((0, 0))
     assert physics.ball_collision_check(ball1, ball2)
Exemplo n.º 7
0
 def test_distance5(self):
     ball2.move_to((1, 0))
     ball2.set_velocity((0, 0))
     assert physics.ball_collision_check(ball1, ball2)
Exemplo n.º 8
0
 def test_distance2(self):
     ball2.move_to((0, ball_radius * 2 + 1))
     ball2.set_velocity((0, 0))
     assert not physics.ball_collision_check(ball1, ball2)