Ejemplo n.º 1
0
 def __init__(self, space, mass, radius, pos=(300,300), color=(0,240,0,255)):
     self.color = color
     self.mass = mass
     self.radius = radius
     ball_moment = cp.cpMomentForCircle(mass, 5, 0.0, vec2d(0,0))
     self.body = cp.cpBodyNew( mass, ball_moment )
     self.shape = cp.cpCircleShapeNew(self.body,
             radius, vec2d(0.0, 0.0) )
     self.shape.contents.e = 0.5
     self.set_position( pos )
     cp.cpSpaceAddBody(space, self.body)
     cp.cpSpaceAddShape( space, self.shape )
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
    def __init__(self, space, mass, width, height, pos, color=(255,0,0,255)):
        poly = [
            [ width/2, height/2 ],
            [ width/2, -height/2 ],
            [ -width/2, -height/2 ],
            [ -width/2, height/2 ],
            ]
        p_num = len(poly)
        P_ARR = vec2d * p_num
        p_arr = P_ARR(vec2d(0,0))
        for i, (x,y) in enumerate( poly ):
            p_arr[i].x = x
            p_arr[i].y = y

        moment = cp.cpMomentForPoly( mass, p_num, p_arr, vec2d(0,0))
        self.color = color
        self.body = cp.cpBodyNew( mass, moment )
        self.body.contents.p = vec2d( *pos )
        cp.cpSpaceAddBody( space, self.body )
        self.shape = shape = cp.cpPolyShapeNew(
            self.body, p_num, p_arr, vec2d(0,0)
            )
        shape.contents.u = 0.5
        cp.cpSpaceAddShape(space, shape)
Ejemplo n.º 5
0
 def _add_body(self, body):
     """Adds a body to the space"""
     self._bodies.add(body)
     cp.cpSpaceAddBody(self._space, body._body)