Example #1
0
def create_cube(space, mass=5.0, xy=(0, 0)):
    p_num = 4
    P_ARR = vec2d * p_num
    p_arr = P_ARR(vec2d(0, 0))

    s = 5
    sprite = rabbyt.Sprite(shape=(-s, s, s, -s), xy=xy)
    for i, p in enumerate(sprite.shape):
        p_arr[i].x, p_arr[i].y = p

    moment = 500
    body = cp.cpBodyNew(mass, moment)
    body.contents.p = vec2d(*xy)
    cp.cpSpaceAddBody(space, body)

    shape = cp.cpPolyShapeNew(body, p_num, p_arr, vec2d(0, 0))
    shape.contents.u = 0.5
    shape.contents.collision_type = COLLTYPE_DEFAULT
    cp.cpSpaceAddShape(space, shape)

    anims = chipmunk_body_anims(body)
    sprite.x, sprite.y, sprite.rot = anims

    return shape, sprite
def create_cube(space, mass = 5.0, xy = (0,0)):
    p_num = 4
    P_ARR = vec2d * p_num
    p_arr = P_ARR(vec2d(0,0))
    
    s = 5
    sprite = rabbyt.Sprite(shape=(-s,s,s,-s), xy=xy)
    for i, p in enumerate(sprite.shape):
        p_arr[i].x, p_arr[i].y = p

    moment = 500
    body = cp.cpBodyNew(mass, moment)
    body.contents.p = vec2d(*xy)
    cp.cpSpaceAddBody(space, body)
    
    shape = cp.cpPolyShapeNew(body, p_num, p_arr, vec2d(0,0))
    shape.contents.u = 0.5
    shape.contents.collision_type = COLLTYPE_DEFAULT
    cp.cpSpaceAddShape(space, shape)

    anims = chipmunk_body_anims(body)
    sprite.x, sprite.y, sprite.rot = anims

    return shape, sprite
Example #3
0
    anims = chipmunk_body_anims(body)
    sprite.x, sprite.y, sprite.rot = anims

    return shape, sprite


if __name__ == "__main__":
    pygame.init()
    pygame.display.set_mode((800, 600), pygame.OPENGL | pygame.DOUBLEBUF)
    rabbyt.set_viewport((800, 600))
    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):
    anims = chipmunk_body_anims(body)
    sprite.x, sprite.y, sprite.rot = anims

    return shape, sprite

if __name__ == "__main__":
    pygame.init()
    pygame.display.set_mode((800,600), pygame.OPENGL | pygame.DOUBLEBUF)
    rabbyt.set_viewport((800, 600))
    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 = []