Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testManyBoxCrash(self):
space = p.Space()
for x in [1,2]:
for y in range(16):
size = 10
box_points = map(Vec2d, [(-size, -size), (-size, size), (size,size), (size, -size)])
body = p.Body(10,20)
shape = p.Poly(body, list(box_points), Vec2d(0,0))
space.add(body, shape)
space.step(1/50.0)
####################################################################
def main():
pygame.init()
screen = pygame.display.set_mode((600, 600))
clock = pygame.time.Clock()
running = True
### Physics stuff
space = pymunk.Space()
pointer_body = pymunk.Body()
ps = [(80,0),(0,20),(0,-20)]
moment = pymunk.moment_for_poly(1, ps)
gun_body = pymunk.Body(1, moment)
gun_body.position = 300,300
gun_shape = pymunk.Poly(gun_body, ps)
rest_angle = 0
stiffness = 125000.
damping = 6000.
rotary_spring = pymunk.constraint.DampedRotarySpring(pointer_body, gun_body, rest_angle, stiffness, damping)
space.add(gun_body, gun_shape, rotary_spring)
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:
def __init__(self, width, height, x, y, angle = 0):
self.point_list = ((-width / 2, -height / 2),
(+width / 2, -height / 2),
(+width / 2, +height / 2),
(-width / 2, +height / 2))
self.graphic_shape = arcade.create_rectangle_filled(x, y, width, height, arcade.color.WHITE, tilt_angle=angle)
self.body = pymunk.Body(body_type=pymunk.Body.STATIC)
self.body.position = pymunk.Vec2d(x, y)
self.body.angle = math.radians(angle)
self.pymunk_shape = pymunk.Poly.create_box(self.body, (width, height))
self.pymunk_shape.friction = 1
self.pymunk_shape.elasticity = 0.9
def create_bananas(space):
mass = 10
size = 50
points = [(-size, -size), (-size, size), (size, size), (size, -size)]
moment = pymunk.moment_for_poly(mass, points, (0, 0))
body = pymunk.Body(mass, moment)
x = random.randint(0, 500)
body.position = Vec2d(x, x)
banana = pymunk.Poly(body, points, (0, 0))
banana.elasticity = 0.95
space.add(body, banana)
return banana
b.position = (120,560)
b.angle = 3.14/4
s = pymunk.Circle(b, 40)
space.add(s)
# Static Polys
b = pymunk.Body(body_type=pymunk.Body.STATIC)
b.position = (120,460)
b.angle = 3.14/4
s = pymunk.Poly(b, [(0, -25),(30, 25),(-30, 25)])
space.add(s)
b = pymunk.Body(body_type=pymunk.Body.STATIC)
b.position = (120,500)
t = pymunk.Transform(ty=-100)
s = pymunk.Poly(b, [(0, -25),(30, 25),(-30, 25)], t, radius=1)
space.add(s)
b = pymunk.Body(body_type=pymunk.Body.STATIC)
b.position = (50,430)
t = pymunk.Transform(ty=-100)
s = pymunk.Poly(b, [(0.0, -30.0), (19.0, -23.0), (30.0, -5.0), (26.0, 15.0), (10.0, 28.0), (-10.0, 28.0), (-26.0, 15.0), (-30.0, -5.0), (-19.0, -23.0)], t)
space.add(s)
### Kinematic
captions.append(((220,680), "Kinematic Shapes"))
# Kinematic Segments
b = pymunk.Body(body_type=pymunk.Body.KINEMATIC)
segments = [ pymunk.Segment(b, (180, 400), (180, 600), 0)
,pymunk.Segment(b, (190, 400), (190, 600), 1)
,pymunk.Segment(b, (200, 400), (200, 600), 3)
def create_arrow():
vs = [(-30,0), (0,3), (10,0), (0,-3)]
mass = 1
moment = pymunk.moment_for_poly(mass, vs)
arrow_body = pymunk.Body(mass, moment)
arrow_shape = pymunk.Poly(arrow_body, vs)
arrow_shape.friction = .5
arrow_shape.collision_type = 1
return arrow_body, arrow_shape
b = pymunk.Body(body_type=pymunk.Body.KINEMATIC)
b.position = (290,630)
s = pymunk.Circle(b, 10, (-30,0))
space.add(s)
b = pymunk.Body(body_type=pymunk.Body.KINEMATIC)
b.position = (290,560)
b.angle = 3.14/4
s = pymunk.Circle(b, 40)
space.add(s)
# Kinematic Polys
b = pymunk.Body(body_type=pymunk.Body.KINEMATIC)
b.position = (290,460)
b.angle = 3.14/4
s = pymunk.Poly(b, [(0, -25),(30, 25),(-30, 25)])
space.add(s)
b = pymunk.Body(body_type=pymunk.Body.KINEMATIC)
b.position = (290,500)
t = pymunk.Transform(ty=-100)
s = pymunk.Poly(b, [(0, -25),(30, 25),(-30, 25)], t, radius=3)
space.add(s)
b = pymunk.Body(body_type=pymunk.Body.KINEMATIC)
b.position = (230,430)
t = pymunk.Transform(ty=-100)
s = pymunk.Poly(b, [(19.0, -50.0), (30.0, -5.0), (26.0, 15.0), (10.0, 38.0), (-10.0, 38.0), (-26.0, 15.0), (-30.0, -5.0), (-19.0, -50.0)], t)
space.add(s)
### Dynamic
captions.append(((390,680), "Dynamic Shapes"))
def __init__(self, x, y, angle, vertices):
self.graphic_shape = arcade.create_polygon(vertices, arcade.color.WHITE, 1)
self.graphic_shape.center_x = x
self.graphic_shape.center_y = y
self.body = pymunk.Body(body_type=pymunk.Body.STATIC)
self.body.position = pymunk.Vec2d(x, y)
self.body.angle = math.radians(angle)
self.pymunk_shape = pymunk.Poly(self.body,vertices)
self.pymunk_shape.friction = 1
self.pymunk_shape.elasticity = 0.9
def create_arrow():
vs = [(-30,0), (0,3), (10,0), (0,-3)]
mass = 1
moment = pymunk.moment_for_poly(mass, vs)
arrow_body = pymunk.Body(mass, moment)
arrow_shape = pymunk.Poly(arrow_body, vs)
arrow_shape.friction = .5
arrow_shape.collision_type = 1
return arrow_body, arrow_shape