def do_action(self, solver, action): action = action[0] self.save_angle() cp.cpBodyApplyForce(self.base.body, vec2d(action*15000,0), vec2d(0,0)) cp.cpSpaceStep(self.space, dt) cp.cpBodyResetForces(self.base.body) clock.tick() self.win.dispatch_events() self.win.clear() self.ball.render() self.floor.render() self.base.render() self.win.flip()
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: clock.tick(40) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False rabbyt.set_time(pygame.time.get_ticks()) rabbyt.scheduler.pump() dt = 1 / 60 / 2 # This is the only call in the loop with ctypes overhead :) cp.cpSpaceStep(space, dt) cp.cpSpaceStep(space, dt) rabbyt.clear() rabbyt.render_unsorted(sprites) pygame.display.flip()
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: clock.tick(40) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False rabbyt.set_time(pygame.time.get_ticks()) rabbyt.scheduler.pump() dt = 1/60/2 # This is the only call in the loop with ctypes overhead :) cp.cpSpaceStep(space, dt) cp.cpSpaceStep(space, dt) rabbyt.clear() rabbyt.render_unsorted(sprites) pygame.display.flip()
def step(self, dt): """Update the space for the given time step. Using a fixed time step is highly recommended. Doing so will increase the efficiency of the contact persistence, requiring an order of magnitude fewer iterations to resolve the collisions in the usual case.""" cp.cpSpaceStep(self._space, dt)