def update(dt): global time_left, gameover time_left -= dt time_display.text = "%d seconds remaining" % (time_left) if not gameover and time_left <= 0: gameover_display.text = "Gameover, press ENTER to restart" gameover = True #return elif not gameover and player.getBody().getPosition()[0] > 3600: gameover_display.text = "You won! Press ENTER to play again" gameover = True player.update() # Position everything but try to keep player in the middle of the screen player_pos = player.body.getPosition()[0:2] player_offset = (window.width / 2 - player_pos[0], window.height / 2 - player_pos[1]) window_offset = [0, 0] if player_offset[0] > 0: window_offset[0] = player_offset[0] elif player_offset[0] < -(background.image.width - window.width): window_offset[0] = (background.image.width - window.width + player_offset[0]) if player_offset[1] > 0: window_offset[1] = player_offset[1] elif player_offset[1] < -(background.image.height - window.height): window_offset[1] = (background.image.height - window.height + player_offset[1]) object_offset = (player_offset[0] - window_offset[0], player_offset[1] - window_offset[1]) player.sprite.x, player.sprite.y = (window.width / 2 - window_offset[0], window.height / 2 - window_offset[1]) background.position = object_offset # Convert world positions to screen positions for physics in level_physics: physics.update() physics.getSprite().position = get_window_position(physics.getPosition(), object_offset) for overlay in level_overlays: overlay.getSprite().position = get_window_position( overlay.position, object_offset) # Physics global physics_dt physics_dt += dt # ODE recomends constant world steps to stop jitter while physics_dt > PHYSICS_STEP: space.collide(None, near_callback) world.step(PHYSICS_STEP) contactgroup.empty() physics_dt -= PHYSICS_STEP
def delByPosition(self, task): currentPosition = physics.getPosition(self.actorNode) print "POSITION-Z = ",currentPosition[-1] if currentPosition[-1] < -10 and self.colliding == False: print "Z = ", currentPosition[-1] self.projectileModel.projectileInstance.removeNode() del Projectile.projectileDict[self.ID] return Task.done else: return Task.cont
def getPositionZ(self): currentPosition = physics.getPosition(self.actorNode) return currentPosition[-1]