Example #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)
    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: