Example #1
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)
Example #2
0
 def __init__(self, body, a, b, radius):
     """Create a Segment
     
     :Parameters:
         body : `Body`
             The body to attach the segment to
         a : (x,y) or `Vec2d`
             The first endpoint of the segment
         b : (x,y) or `Vec2d`
             The first endpoint of the segment
         radius : float
             The thickness of the segment
     """
     self._body = body
     self._shape = cp.cpSegmentShapeNew(body._body, a, b, radius)
     self._shapecontents = self._shape.contents
Example #3
0
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):
        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()
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):
        for y in range(-200, 400, 15):
            shape, sprite = create_cube(space, xy = (x+random.random()*10,y))
            shapes.append(shape)
            sprites.append(sprite)