How to use the pymunk.Body.STATIC function in pymunk

To help you get started, we’ve selected a few pymunk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pvcraven / arcade / arcade / examples / pymunk_pegboard.py View on Github external
self.space.add(shape)
        self.static_lines.append(shape)

        body = pymunk.Body(body_type=pymunk.Body.STATIC)
        shape = pymunk.Segment(body, [50, 10], [0, 30], 0.0)
        shape.friction = 10
        self.space.add(shape)
        self.static_lines.append(shape)

        radius = 20
        separation = 150
        for row in range(6):
            for column in range(6):
                x = column * separation + (separation // 2 * (row % 2))
                y = row * separation + separation // 2
                body = pymunk.Body(body_type=pymunk.Body.STATIC)
                body.position = x, y
                shape = pymunk.Circle(body, radius, pymunk.Vec2d(0, 0))
                shape.friction = 0.3
                self.space.add(body, shape)

                sprite = CircleSprite("images/bumper.png", shape)
                self.peg_list.append(sprite)
github viblo / pymunk / tests / test_arbiter.py View on Github external
def testContactPointSet(self):
        s = p.Space()
        s.gravity = 0,-100
        
        b1 = p.Body(1, 30)
        c1 = p.Circle(b1, 10)
        b1.position = 5, 3
        c1.collision_type = 1
        
        b2 = p.Body(body_type = p.Body.STATIC)
        c2 = p.Circle(b2, 10)
        c2.collision_type = 2
        
        s.add(b1, c1, b2, c2)
        
        def pre_solve(arb, space, data):
            # check inital values
            ps = arb.contact_point_set
            self.assertEqual(len(ps.points), 1)
            self.assertAlmostEqual(ps.normal.x, 0.8574929257)
            self.assertAlmostEqual(ps.normal.y, 0.5144957554)
            p1 = ps.points[0]
            self.assertAlmostEqual(p1.point_a.x, 8.574929257)
            self.assertAlmostEqual(p1.point_a.y, 5.144957554)
            self.assertAlmostEqual(p1.point_b.x, -3.574929257)
            self.assertAlmostEqual(p1.point_b.y, -2.144957554)
github viblo / pymunk / tests / test_space.py View on Github external
self.assertEqual(s.collision_slop, 6)

        self.assertAlmostEqual(s.collision_bias, 0.0017970074436)
        s.collision_bias = 0.2
        self.assertEqual(s.collision_bias, 0.2)

        self.assertEqual(s.collision_persistence, 3)
        s.collision_persistence = 9
        self.assertEqual(s.collision_persistence, 9)

        self.assertEqual(s.current_time_step, 0)
        s.step(0.1)
        self.assertEqual(s.current_time_step, 0.1)

        self.assertTrue(s.static_body != None)
        self.assertEqual(s.static_body.body_type, p.Body.STATIC)
        
        self.assertEqual(s.threads, 1)
        s.threads = 2
        self.assertEqual(s.threads, 1)
github pvcraven / arcade / arcade / examples / pymunk_test3.py View on Github external
def create_floor(space, sprite_list):
    for x in range(-1000, 2000, SPRITE_SIZE):
        y = SPRITE_SIZE / 2
        sprite = PymunkSprite("images/grassMid.png", x, y, scale=0.5, body_type=pymunk.Body.STATIC)
        sprite_list.append(sprite)
        space.add(sprite.body, sprite.shape)
github estevaofon / angry-birds-python / src / main.py View on Github external
WHITE = (255, 255, 255)
sling_x, sling_y = 135, 450
sling2_x, sling2_y = 160, 450
score = 0
game_state = 0
bird_path = []
counter = 0
restart_counter = False
bonus_score_once = True
bold_font = pygame.font.SysFont("arial", 30, bold=True)
bold_font2 = pygame.font.SysFont("arial", 40, bold=True)
bold_font3 = pygame.font.SysFont("arial", 50, bold=True)
wall = False

# Static floor
static_body = pm.Body(body_type=pm.Body.STATIC)
static_lines = [pm.Segment(static_body, (0.0, 060.0), (1200.0, 060.0), 0.0)]
static_lines1 = [pm.Segment(static_body, (1200.0, 060.0), (1200.0, 800.0), 0.0)]
for line in static_lines:
    line.elasticity = 0.95
    line.friction = 1
    line.collision_type = 3
for line in static_lines1:
    line.elasticity = 0.95
    line.friction = 1
    line.collision_type = 3
space.add(static_lines)


def to_pygame(p):
    """Convert pymunk to pygame coordinates"""
    return int(p.x), int(-p.y+600)
github jshaffstall / PyPhysicsSandbox / pyphysicssandbox / box_shape.py View on Github external
def __init__(self, space, x, y, width, height, radius, mass, static, cosmetic=False):

        if not cosmetic:
            moment = pymunk.moment_for_box(mass, (width, height))

            if static:
                self.body = pymunk.Body(mass, moment, pymunk.Body.STATIC)
            else:
                self.body = pymunk.Body(mass, moment)

            self.body.position = x, y
            self.shape = pymunk.Poly.create_box(self.body, (width, height), radius)
            space.add(self.body, self.shape)

        self.width = width
        self.height = height
        self.radius = radius
        self.static = static
        self._x = x
        self._y = y

        super().__init__(cosmetic)
github pvcraven / arcade / arcade / examples / pymunk_2.py View on Github external
self.last_mouse_position = 0, 0

        self.processing_time_text = None
        self.draw_time_text = None
        self.draw_mode_text = None
        self.shape_1 = None
        self.shape_2 = None
        self.draw_time = 0
        self.processing_time = 0
        self.joints = []

        self.mode = "Drag"

        # Create the floor
        self.floor_height = 80
        body = pymunk.Body(body_type=pymunk.Body.STATIC)
        shape = pymunk.Segment(body, [0, self.floor_height], [SCREEN_WIDTH, self.floor_height], 0.0)
        shape.friction = 10
        self.space.add(shape)
        self.static_lines.append(shape)
github pvcraven / arcade / arcade / examples / pymunk_platformer / create_level.py View on Github external
def create_platform(space, sprite_list, start_x, y, count):
    """ Create a platform """
    for x in range(start_x, start_x + count * SPRITE_SIZE + 1, SPRITE_SIZE):
        sprite = PymunkSprite("../images/grassMid.png", x, y, scale=0.5, body_type=pymunk.Body.STATIC)
        sprite_list.append(sprite)
        space.add(sprite.body, sprite.shape)
github lantunes / cellpylib / demos / physics_demo.py View on Github external
# double blade rotating paddle
# paddle_w = 200
# paddle_h = 2
# paddle_body_position = 300.0, 300.0
# joint_point = paddle_body_position

paddle_mass = 30
paddle_body = pymunk.Body(mass=paddle_mass, moment=pymunk.moment_for_box(paddle_mass, (paddle_w, paddle_h)))
paddle_body.position = paddle_body_position
paddle_shape = pymunk.Poly.create_box(paddle_body, (paddle_w, paddle_h))
paddle_shape.elasticity = 1.0
paddle_shape.friction = 0.0
paddle_shape.color = (0, 0, 0, 255)
space.add(paddle_body, paddle_shape)
pj_body = pymunk.Body(body_type=pymunk.Body.STATIC)
pj_body.position = paddle_body.position
pj = pymunk.PivotJoint(pj_body, paddle_body, joint_point)
pj.elasticity = 1.0
pj.friction = 0.0
space.add(pj)

timestep = 0
while running:
    for event in pygame.event.get():
        if event.type == QUIT:
            running = False
        elif event.type == KEYDOWN and event.key == K_ESCAPE:
            running = False
        elif event.type == KEYDOWN and event.key == K_p:
            pygame.image.save(screen, "bouncing_balls.png")
github jshaffstall / PyPhysicsSandbox / pyphysicssandbox / pivot_joint.py View on Github external
def __init__(self, space, x, y):
        self.body = pymunk.Body(body_type=pymunk.Body.STATIC)
        self.body.position = x, y
        self.shape = []
        self.space = space
        super().__init__()

        space.add(self.body)