Пример #1
0
 def _add_static_shape(self, static_shape):
     """Adds a shape to the space. Static shapes should be be attached to 
     a rigid body with an infinite mass and moment of inertia. Also, don't 
     add the rigid body used to the space, as that will cause it to fall 
     under the effects of gravity."""
     self._static_shapes[static_shape.id] = static_shape
     cp.cpSpaceAddStaticShape(self._space, static_shape._shape)
Пример #2
0
 def __init__(self, space, start, end, color=(0,255,255,255), radius=50):
     self.color = color
     self.start = start
     self.end = end
     self.radius = radius
     self.shape = cp.cpSegmentShapeNew(BACKGROUND,
         vec2d(*start), vec2d(*end), radius)
     self.shape.contents.e = 0.1
     self.shape.contents.u = 0.2
     cp.cpSpaceAddStaticShape(space, self.shape)
Пример #3
0
    rabbyt.set_default_attribs()

    ### Physics stuff
    cp.cpInitChipmunk()
    space = cp.cpSpaceNew()
    space.contents.gravity = vec2d(0.0, -900.0)

    cp.cpSpaceResizeStaticHash(space, 50.0, 2000)
    cp.cpSpaceResizeActiveHash(space, 50.0, 100)

    wallBody = cp.cpBodyNew(1e100, 1e100)
    wallShape = cp.cpSegmentShapeNew(wallBody, vec2d(-300, -300),
                                     vec2d(300, -300), 0.0)
    wallShape.contents.u = 1.0
    wallShape.contents.collision_type = COLLTYPE_DEFAULT
    cp.cpSpaceAddStaticShape(space, wallShape)

    shapes = []
    sprites = []

    for x in range(-200, 200, 15):
        for y in range(-200, 400, 15):
            shape, sprite = create_cube(space,
                                        xy=(x + random.random() * 10, y))
            shapes.append(shape)
            sprites.append(sprite)

    clock = pygame.time.Clock()
    running = True
    while running:
        clock.tick(40)
Пример #4
0
    rabbyt.set_default_attribs()

    ### Physics stuff
    cp.cpInitChipmunk()
    space = cp.cpSpaceNew()
    space.contents.gravity = vec2d(0.0, -900.0)
    
    cp.cpSpaceResizeStaticHash(space, 50.0, 2000)
    cp.cpSpaceResizeActiveHash(space, 50.0, 100)

    wallBody = cp.cpBodyNew(1e100, 1e100)
    wallShape = cp.cpSegmentShapeNew(wallBody, vec2d(-300, -300),
            vec2d(300, -300), 0.0)
    wallShape.contents.u = 1.0
    wallShape.contents.collision_type = COLLTYPE_DEFAULT
    cp.cpSpaceAddStaticShape(space, wallShape)


    shapes = []
    sprites = []

    for x in range(-200, 200, 15):
        for y in range(-200, 400, 15):
            shape, sprite = create_cube(space, xy = (x+random.random()*10,y))
            shapes.append(shape)
            sprites.append(sprite)


    clock = pygame.time.Clock()
    running = True
    while running: