Beispiel #1
0
    def get_initial_state(self):
        # return first state
        self.space = space = cp.cpSpaceNew()
        space.contents.gravity = vec2d(0.0, -900.0)

	space.contents.damping = 0.01
        cp.cpSpaceResizeStaticHash(space, 50.0, 200)
        cp.cpSpaceResizeActiveHash(space, 50.0, 10)

        self.ball = ball = Ball(space, 5, 10, pos=(310, 180))
        self.floor = Wall(space, (-60000,40), (60000,40))
        self.base = base = Box(space, 5, 50, 20, (300,100))
        cp.cpResetShapeIdCounter()
        joint = cp.cpPinJointNew(
            ball.body, base.body, vec2d(0,0), vec2d(0,0)
            )
	self.save_angle()
        cp.cpSpaceAddJoint(space, joint)
        if self.rl.episodes%100==0:
            self.save()
        return self.get_state()
Beispiel #2
0
 def __init__(self, iterations=10, elastic_iterations=10):
     """Create a new instace of the Space
     
     If the objects in your Space does not have any elasticity set
     elastic_iterations to 0 to gain a little speedup.
     
     :Parameters:
         iterations : int
             Number of iterations to use in the impulse solver to solve 
             contacts.
         elastic_iterations : int
             Number of iterations to use in the impulse solver to solve 
             elastic contacts.
     """
     self._space = cp.cpSpaceNew(iterations)
     self._space.contents.elasticIterations = elastic_iterations
     self._callbacks = {} # To prevent the gc to collect the callbacks.
     self._default_callback = None
     self._shapes = {}
     self._static_shapes = {}
     self._bodies = set()
     self._joints = set()
    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 = []
    cp.cpSpaceAddShape(space, shape)

    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 = []