def update(self, time_step): """Update all the objects""" for e in self.ents: e.update(time_step) if self.world.graphicsEnabled: self._visibleDynamicEnts = self.dynamicObjectsVisibleInCamera( self.world.camera, excluded=[self.world.playerEnt]) DebugDisplay.update("visible_dynamic_ents", len(self._visibleDynamicEnts))
def update(self, time_step): """Update all the objects""" for e in self.ents: e.update( time_step ) if self.world.graphicsEnabled: self._visibleDynamicEnts = self.dynamicObjectsVisibleInCamera( self.world.camera, excluded=[self.world.playerEnt] ) DebugDisplay.update( "visible_dynamic_ents", len(self._visibleDynamicEnts ) )
def rayHit(body, normal, collision_id, userdata, intersectParam): DebugDisplay.update("collision_id", collision_id) self.onGround = True self.groundNormal = vec3(normal) return intersectParam
def drawScreen( self ): """Draw the screen""" GraphicsCard.resetPolygonCount() GraphicsCard.enable('texture_2d', 'blend', 'cull_face') GraphicsCard.setBlendFunction('src_alpha', 'one_minus_src_alpha' ) GraphicsCard.setFrontFace('ccw') GraphicsCard.loadIdentity() GraphicsCard.multMatrix( self.world.camera.getViewMatrix().toList() ) glLightfv( GL_LIGHT0, GL_POSITION, [0, 1, 0, 0] ) GraphicsCard.clearDepth(1.0) GraphicsCard.clear() #Draw the world self.world.draw() TextureManager.DisableStage( 1 ) TextureManager.DisableStage( 2 ) if Settings.UseShaders: Shader.DisableShaders() #self.font.draw( 0, 0, "FPS: " + str( self.fps ) ) DebugDisplay.update("FPS", self.fps, delay=0.3333 ) DebugDisplay.update("yaw", radianToDegree( self.world.camera.yaw) ) DebugDisplay.update("pitch", radianToDegree( self.world.camera.pitch )) DebugDisplay.update("polygons_drawn", GraphicsCard.polygonsDrawn() ) if self.world.playerEnt: DebugDisplay.update("onGround", self.world.playerEnt.onGround ) DebugDisplay.update("groundNormal", self.world.playerEnt.groundNormal ) GraphicsCard.loadIdentity() if self.consoleVisible: self.console.draw() gl2D.start2D() if Settings.DrawDebugInfo: GraphicsCard.setColorRGBA(1, 1, 1, 1) self.font.draw(0, 0, str(DebugDisplay.globalState)) self.world.scene.drawDebugInfo(self.font) else: GraphicsCard.setColorRGBA(1, 1, 1, 1) pygame.display.set_caption("FPS: " + str(DebugDisplay.get("FPS"))) #self.bigfont.draw(0, 0, "Ninjas Killed: %s" % (self.world.ninjasKilled) ) #self.bigfont.draw(0, 30, "Pirates Killed: %s" % (self.world.piratesKilled) ) #self.bigfont.draw(0, 60, "Treasures Stolen: %s" % (self.world.treasuresTaken) ) #DebugDisplay.globalState.draw( self.font ) gl2D.end2D() #put stuff on the screen pygame.display.flip() err = graphext.GetGLError() while err != GL_NO_ERROR: print err print graphext.GLErrorString( err)
def update(self, timedelta): """Updates the game state""" if timedelta: self.fps = 1.0/timedelta cameraMoveVector = vec3(0,0,0) jump_force = 0 mx, my = 0, 0 if Settings.RunPhysics: move_speed = 100 max_jump_force = 200 else: move_speed = 5 max_jump_force = 5 if isinstance( self.world.camera, Camera.Freecam ): move_speed = 5 max_jump_force = 5 if not self.consoleVisible: if self._isKeyDown(pygame.K_LEFT): mx = -6 if self._isKeyDown(pygame.K_RIGHT): mx = 6 if self._isKeyDown(pygame.K_UP): my = -6 if self._isKeyDown(pygame.K_DOWN): my = 6 if self._isKeyDown(pygame.K_w): cameraMoveVector.z = 1 if self._isKeyDown(pygame.K_s): cameraMoveVector.z = -1 if self._isKeyDown(pygame.K_a): cameraMoveVector.x = -1 if self._isKeyDown(pygame.K_d): cameraMoveVector.x = 1 if self._isKeyDown(pygame.K_x): self.world.frustrum_camera = self.world.camera.asFreecam() if self._isKeyDown(pygame.K_SPACE): #if time_in_seconds() - self.lastjump > 0.5: jump_force = max_jump_force self.lastjump = time_in_seconds() if cameraMoveVector.length(): cameraMoveVector = cameraMoveVector.normalize() cameraMoveVector = cameraMoveVector * move_speed left_btn, middle_btn, right_btn = pygame.mouse.get_pressed() if right_btn or Settings.GrabMouse: mx, my = pygame.mouse.get_rel() else: pygame.mouse.get_rel() self.right_btn = right_btn self.world.camera.turn( degreeToRadian( -mx*0.2 ), degreeToRadian( -my*0.2 ), 0 ) #move the camera cameraMoveVector.y = jump_force self.world.camera.move( cameraMoveVector ) px = self.world.camera.position.x py = self.world.camera.position.y pz = self.world.camera.position.z yaw = self.world.camera.yaw DebugDisplay.update('world_position', (int(px), int(py), int(pz)) ) DebugDisplay.update('opacity', self.world.lightIntensityAt( px, pz) ) #update world self.world.update( timedelta ) if self.network: self.network.update() #update debug display DebugDisplay.step( timedelta )
def drawScreen(self): """Draw the screen""" GraphicsCard.resetPolygonCount() GraphicsCard.enable('texture_2d', 'blend', 'cull_face') GraphicsCard.setBlendFunction('src_alpha', 'one_minus_src_alpha') GraphicsCard.setFrontFace('ccw') GraphicsCard.loadIdentity() GraphicsCard.multMatrix(self.world.camera.getViewMatrix().toList()) glLightfv(GL_LIGHT0, GL_POSITION, [0, 1, 0, 0]) GraphicsCard.clearDepth(1.0) GraphicsCard.clear() #Draw the world self.world.draw() TextureManager.DisableStage(1) TextureManager.DisableStage(2) if Settings.UseShaders: Shader.DisableShaders() #self.font.draw( 0, 0, "FPS: " + str( self.fps ) ) DebugDisplay.update("FPS", self.fps, delay=0.3333) DebugDisplay.update("yaw", radianToDegree(self.world.camera.yaw)) DebugDisplay.update("pitch", radianToDegree(self.world.camera.pitch)) DebugDisplay.update("polygons_drawn", GraphicsCard.polygonsDrawn()) if self.world.playerEnt: DebugDisplay.update("onGround", self.world.playerEnt.onGround) DebugDisplay.update("groundNormal", self.world.playerEnt.groundNormal) GraphicsCard.loadIdentity() if self.consoleVisible: self.console.draw() gl2D.start2D() if Settings.DrawDebugInfo: GraphicsCard.setColorRGBA(1, 1, 1, 1) self.font.draw(0, 0, str(DebugDisplay.globalState)) self.world.scene.drawDebugInfo(self.font) else: GraphicsCard.setColorRGBA(1, 1, 1, 1) pygame.display.set_caption("FPS: " + str(DebugDisplay.get("FPS"))) #self.bigfont.draw(0, 0, "Ninjas Killed: %s" % (self.world.ninjasKilled) ) #self.bigfont.draw(0, 30, "Pirates Killed: %s" % (self.world.piratesKilled) ) #self.bigfont.draw(0, 60, "Treasures Stolen: %s" % (self.world.treasuresTaken) ) #DebugDisplay.globalState.draw( self.font ) gl2D.end2D() #put stuff on the screen pygame.display.flip() err = graphext.GetGLError() while err != GL_NO_ERROR: print err print graphext.GLErrorString(err)
def update(self, timedelta): """Updates the game state""" if timedelta: self.fps = 1.0 / timedelta cameraMoveVector = vec3(0, 0, 0) jump_force = 0 mx, my = 0, 0 if Settings.RunPhysics: move_speed = 100 max_jump_force = 200 else: move_speed = 5 max_jump_force = 5 if isinstance(self.world.camera, Camera.Freecam): move_speed = 5 max_jump_force = 5 if not self.consoleVisible: if self._isKeyDown(pygame.K_LEFT): mx = -6 if self._isKeyDown(pygame.K_RIGHT): mx = 6 if self._isKeyDown(pygame.K_UP): my = -6 if self._isKeyDown(pygame.K_DOWN): my = 6 if self._isKeyDown(pygame.K_w): cameraMoveVector.z = 1 if self._isKeyDown(pygame.K_s): cameraMoveVector.z = -1 if self._isKeyDown(pygame.K_a): cameraMoveVector.x = -1 if self._isKeyDown(pygame.K_d): cameraMoveVector.x = 1 if self._isKeyDown(pygame.K_x): self.world.frustrum_camera = self.world.camera.asFreecam() if self._isKeyDown(pygame.K_SPACE): #if time_in_seconds() - self.lastjump > 0.5: jump_force = max_jump_force self.lastjump = time_in_seconds() if cameraMoveVector.length(): cameraMoveVector = cameraMoveVector.normalize() cameraMoveVector = cameraMoveVector * move_speed left_btn, middle_btn, right_btn = pygame.mouse.get_pressed() if right_btn or Settings.GrabMouse: mx, my = pygame.mouse.get_rel() else: pygame.mouse.get_rel() self.right_btn = right_btn self.world.camera.turn(degreeToRadian(-mx * 0.2), degreeToRadian(-my * 0.2), 0) #move the camera cameraMoveVector.y = jump_force self.world.camera.move(cameraMoveVector) px = self.world.camera.position.x py = self.world.camera.position.y pz = self.world.camera.position.z yaw = self.world.camera.yaw DebugDisplay.update('world_position', (int(px), int(py), int(pz))) DebugDisplay.update('opacity', self.world.lightIntensityAt(px, pz)) #update world self.world.update(timedelta) if self.network: self.network.update() #update debug display DebugDisplay.step(timedelta)