예제 #1
0
파일: main.py 프로젝트: fathat/game-src
    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 )
예제 #2
0
    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)