コード例 #1
0
ファイル: playfield.py プロジェクト: MarquisLP/pyroller
    def __init__(self, space, rect, playfield=None):
        super(PlungerAssembly, self).__init__()
        self.chute_counter = 0
        self.rect = Rect(0, 0, 1, 1)

        spring_strength = 100 * plunger_mass
        chute_opening = playfield.position + rect.center - (rect.width / 2. -
                                                            ball_radius * 4, 0)
        plunger_rect = Rect(0, 0, rect.width * .2, ball_radius / 2.)
        anchor0 = chute_opening - playfield.position - (ball_radius * 3., 0)
        anchor1 = anchor0 + (rect.width * .8, 0)
        anchor2 = -plunger_rect.width / 2., 0

        plunger_body = Body(plunger_mass, pymunk.inf)
        plunger_shape = Poly.create_box(plunger_body, plunger_rect.size)
        plunger_shape.layers = 1
        plunger_shape.friction = 0.1
        plunger_shape.elasticity = 1.0
        plunger_shape.collision_type = plunger_type
        plunger_body.position = chute_opening + (plunger_rect.width / 2., 0)

        j0 = GrooveJoint(playfield, plunger_body, anchor0, anchor1, anchor2)
        j1 = DampedSpring(playfield, plunger_body, anchor0, anchor2, 0,
                          spring_strength, 5)

        s0 = Circle(Body(), ball_radius / 2.)
        s0.layers = 1
        s0.sensor = True
        s0.collision_type = sensor0_type
        s0.body.position = chute_opening + (ball_radius * 4., 0.0)

        s1 = Circle(Body(), ball_radius * 3.)
        s1.layers = 1
        s1.sensor = True
        s1.collision_type = sensor1_type
        s1.body.position = chute_opening

        def inc_counter(space, arbiter):
            self.chute_counter += 1
            return True

        def dec_counter(space, arbiter):
            self.chute_counter -= 1

        f = space.add_collision_handler
        f(sensor1_type, plunger_type, begin=inc_counter, separate=dec_counter)

        self.playfield = playfield
        self.plunger_offset = playfield.position - plunger_body.position + (
            ball_radius * 3, 0)
        self.spring = j1
        self.spring_length = rect.width / 2.
        self.spring_strength = spring_strength
        self.plunger_body = plunger_body
        self.ball_chute = Rect(0, 0, ball_radius * 2., ball_radius * 2.)
        self.ball_chute.center = chute_opening
        self._original_image = pygame.Surface(plunger_rect.size)
        self._original_image.fill((192, 255, 255))
        self.shapes = [plunger_shape, s0, s1, j0, j1]
        self.visible = 0
コード例 #2
0
ファイル: playfield.py プロジェクト: paulpaterson/pyroller
    def __init__(self, space, rect, playfield=None):
        super(PlungerAssembly, self).__init__()
        self.chute_counter = 0
        self.rect = pygame.Rect(0, 0, 0, 0)

        spring_strength = 100 * plunger_mass
        chute_opening = playfield.position + rect.center - (rect.width / 2 - ball_radius * 4, 0)
        plunger_rect = pygame.Rect(0, 0, rect.width * .2, ball_radius / 2)
        anchor0 = chute_opening - playfield.position - (ball_radius * 3, 0)
        anchor1 = anchor0 + (rect.width * .8, 0)
        anchor2 = -plunger_rect.width / 2, 0

        plunger_body = Body(plunger_mass, pymunk.inf)
        plunger_shape = Poly.create_box(plunger_body, plunger_rect.size)
        plunger_shape.layers = 1
        plunger_shape.friction = 0
        plunger_shape.elasticity = 1.0
        plunger_shape.collision_type = plunger_type
        plunger_body.position = chute_opening + (plunger_rect.width / 2, 0)

        j0 = GrooveJoint(playfield, plunger_body, anchor0, anchor1, anchor2)
        j1 = DampedSpring(playfield, plunger_body, anchor0, anchor2, 0, spring_strength, 5)

        s0 = Circle(Body(), ball_radius / 2)
        s0.layers = 1
        s0.sensor = True
        s0.collision_type = sensor0_type
        s0.body.position = chute_opening + (ball_radius * 4, 0)

        s1 = Circle(Body(), ball_radius * 3)
        s1.layers = 1
        s1.sensor = True
        s1.collision_type = sensor1_type
        s1.body.position = chute_opening

        def inc_counter(space, arbiter):
            self.chute_counter += 1
            return True

        def dec_counter(space, arbiter):
            self.chute_counter -= 1

        f = space.add_collision_handler
        f(sensor1_type, plunger_type, begin=inc_counter, separate=dec_counter)

        self.playfield = playfield
        self.plunger_offset = playfield.position - plunger_body.position + (ball_radius * 3, 0)
        self.spring = j1
        self.spring_length = rect.width / 2
        self.spring_strength = spring_strength
        self.plunger_body = plunger_body
        self.ball_chute = pygame.Rect(0, 0, ball_radius * 2, ball_radius * 2)
        self.ball_chute.center = chute_opening
        self._original_image = pygame.Surface(plunger_rect.size)
        self._original_image.fill((192, 255, 255))
        self.shapes = [plunger_shape, s0, s1, j0, j1]
        self.visible = 0
コード例 #3
0
ファイル: playfield.py プロジェクト: paulpaterson/pyroller
 def __init__(self, space, rect, playfield=None):
     super(Spinner, self).__init__()
     r, cy = rect.width / 2, rect.height / 2
     assert (r == cy)
     body = Body(.1, moment_for_circle(.1, 0, r))
     body.position = rect.center
     top = Circle(body, r)
     top.layers = 2
     rect2 = pygame.Rect((-r, -cy), rect.size)
     cross0 = Segment(body, rect2.midleft, rect2.midright, 1)
     cross1 = Segment(body, rect2.midtop, rect2.midbottom, 1)
     j0 = PivotJoint(playfield, body, body.position)
     j1 = SimpleMotor(playfield, body, 0)
     j1.max_force = 200
     self.shapes = [top, cross0, cross1, j0, j1]
     self.rect = pygame.Rect(rect)
     self._original_image = prepare.GFX['pachinko-spinner']
コード例 #4
0
 def __init__(self, space, rect, playfield=None):
     super(Spinner, self).__init__()
     r, cy = rect.width / 2, rect.height / 2
     assert (r == cy)
     body = Body(.1, moment_for_circle(.1, 0, r))
     body.position = rect.center
     top = Circle(body, r)
     top.layers = 2
     rect2 = pygame.Rect((-r, -cy), rect.size)
     cross0 = Segment(body, rect2.midleft, rect2.midright, 1)
     cross1 = Segment(body, rect2.midtop, rect2.midbottom, 1)
     j0 = PivotJoint(playfield, body, body.position)
     j1 = SimpleMotor(playfield, body, 0)
     j1.max_force = 200
     self.shapes = [top, cross0, cross1, j0, j1]
     self.rect = pygame.Rect(rect)
     self._original_image = prepare.GFX['pachinko-spinner']