Beispiel #1
0
    def __init__(self, network):
        self.gameEngine = ClientGameEngine()
        self.network = network
        # self.accept("escape", self.sendMsgDisconnectReq)

        self.gameStart = False
        self.my_clock = 0
        self.player_count = 0
        self.heading = 0
        self.pitch = 40
        self.skip = 0
        self.loss = 0
        self.id = 0
        self.win = False
        self.lose = False

        inputState.watchWithModifiers('forward', 'w')
        inputState.watchWithModifiers('left', 'a')
        inputState.watchWithModifiers('reverse', 's')
        inputState.watchWithModifiers('right', 'd')
        inputState.watchWithModifiers('shoot', 'mouse1')

        # GameUI
        self.healthUI = None
        self.displayUI = GameUI.createDisplayUI("")

        self.serverWait = True
    def __init__(self, enable=True, passMessagesThrough=False):
        self.passMessagesThrough = passMessagesThrough
        self.inputStateTokens = []
        self.WASDTurnTokens = []
        self._ControlManager__WASDTurn = True
        self.controls = {}
        self.currentControls = None
        self.currentControlsName = None
        self.isEnabled = 0
        if enable:
            self.enable()

        self.forceAvJumpToken = None
        if self.passMessagesThrough:
            ist = self.inputStateTokens
            ist.append(
                inputState.watchWithModifiers(
                    'forward', 'arrow_up', inputSource=inputState.ArrowKeys))
            ist.append(
                inputState.watchWithModifiers(
                    'reverse', 'arrow_down', inputSource=inputState.ArrowKeys))
            ist.append(
                inputState.watchWithModifiers(
                    'turnLeft', 'arrow_left',
                    inputSource=inputState.ArrowKeys))
            ist.append(
                inputState.watchWithModifiers(
                    'turnRight',
                    'arrow_right',
                    inputSource=inputState.ArrowKeys))
    def setWASDTurn(self, turn):
        self.__WASDTurn = turn
        if not self.isEnabled:
            return

        turnLeftWASDSet = inputState.isSet("turnLeft", inputSource=inputState.WASD)
        turnRightWASDSet = inputState.isSet("turnRight", inputSource=inputState.WASD)
        slideLeftWASDSet = inputState.isSet("slideLeft", inputSource=inputState.WASD)
        slideRightWASDSet = inputState.isSet("slideRight", inputSource=inputState.WASD)

        for token in self.WASDTurnTokens:
            token.release()

        # If we want Toons to be able to turn instead of sliding left to right:
        if turn:
            self.WASDTurnTokens = (
                inputState.watchWithModifiers("turnLeft", "a", inputSource=inputState.WASD),
                inputState.watchWithModifiers("turnRight", "d", inputSource=inputState.WASD),
            )
            inputState.set("turnLeft", slideLeftWASDSet, inputSource=inputState.WASD)
            inputState.set("turnRight", slideRightWASDSet, inputSource=inputState.WASD)
            inputState.set("slideLeft", False, inputSource=inputState.WASD)
            inputState.set("slideRight", False, inputSource=inputState.WASD)
        else:
            self.WASDTurnTokens = (
                inputState.watchWithModifiers("slideLeft", "a", inputSource=inputState.WASD),
                inputState.watchWithModifiers("slideRight", "d", inputSource=inputState.WASD),
            )
            inputState.set("slideLeft", turnLeftWASDSet, inputSource=inputState.WASD)
            inputState.set("slideRight", turnRightWASDSet, inputSource=inputState.WASD)
            inputState.set("turnLeft", False, inputSource=inputState.WASD)
            inputState.set("turnRight", False, inputSource=inputState.WASD)
Beispiel #4
0
    def __init__(self, enable=True, passMessagesThrough = False):
        assert self.notify.debug("init control manager %s" % (passMessagesThrough))
        assert self.notify.debugCall(id(self))
        self.passMessagesThrough = passMessagesThrough
        self.inputStateTokens = []
        # Used to switch between strafe and turn. We will reset to whatever was last set.
        self.WASDTurnTokens = []
        self.__WASDTurn = True
        self.controls = {}
        self.currentControls = None
        self.currentControlsName = None
        self.isEnabled = 0
        if enable:
            self.enable()
        #self.monitorTask = taskMgr.add(self.monitor, "ControlManager-%s"%(id(self)), priority=-1)
        self.forceAvJumpToken = None



        if self.passMessagesThrough: # for not breaking toontown
            ist=self.inputStateTokens
            ist.append(inputState.watchWithModifiers("forward", "arrow_up", inputSource=inputState.ArrowKeys))
            ist.append(inputState.watchWithModifiers("reverse", "arrow_down", inputSource=inputState.ArrowKeys))
            ist.append(inputState.watchWithModifiers("turnLeft", "arrow_left", inputSource=inputState.ArrowKeys))
            ist.append(inputState.watchWithModifiers("turnRight", "arrow_right", inputSource=inputState.ArrowKeys))
 def enterControlCannon(self):
     self.__setupCamera(1)
     self.cannon = self.cr.doId2do.get(self.cannonId)
     array = []
     array.append(
         inputState.watchWithModifiers('cannonUp',
                                       'arrow_up',
                                       inputSource=inputState.ArrowKeys))
     array.append(
         inputState.watchWithModifiers('cannonDown',
                                       'arrow_down',
                                       inputSource=inputState.ArrowKeys))
     array.append(
         inputState.watchWithModifiers('cannonLeft',
                                       'arrow_left',
                                       inputSource=inputState.ArrowKeys))
     array.append(
         inputState.watchWithModifiers('cannonRight',
                                       'arrow_right',
                                       inputSource=inputState.ArrowKeys))
     self.cist = array
     taskMgr.add(self.__handleCannonControls,
                 'DEagleGame-handleCannonControls')
     taskMgr.add(self.__broadcastCannonAndLTTask,
                 'DEagleGame-broadcastCannonAndLT')
     self.acceptOnce('control', self.controlKeyPressed)
Beispiel #6
0
	def setup(self,level):
		self.actual_start = globalClock.getRealTime()
		self.current_level = level
		#self.interface.set_timer()
		self.interface.create_stage_title(self.current_level)


		self.e = Environment(self)
		if self.current_level == 'L1':
			self.eve.render_eve((1500,1100,1.5))
			#self.eve.render_eve((0,-5250,-15))
			self.e.loadStage1()
			#self.eve.render_eve((1500,1100,1.5))
		elif self.current_level == 'L2':
			self.eve.render_eve((1500,1100,1005))
			#self.eve.render_eve((1363,982,1335))
			#self.eve.render_eve((1345,1690,1335))
			#self.eve.render_eve((179,1594,1435))
			self.e.loadStage2()
		
		self.accept('c', self.toggle_camera)

        	inputState.watchWithModifiers('camera_up', 'arrow_up')
        	inputState.watchWithModifiers('camera_down', 'arrow_down')																
		
		#	TASK FOR ALL GAME STAGES	#
		self.taskMgr.add(self.update_world,'update')
		self.taskMgr.add(self.update_camera,'cam-update')  
 def enterControlCannon(self):
     self.__setupCamera(1)
     self.cannon = self.cr.doId2do.get(self.cannonId)
     array = []
     array.append(
         inputState.watchWithModifiers("cannonUp",
                                       "arrow_up",
                                       inputSource=inputState.ArrowKeys))
     array.append(
         inputState.watchWithModifiers("cannonDown",
                                       "arrow_down",
                                       inputSource=inputState.ArrowKeys))
     array.append(
         inputState.watchWithModifiers("cannonLeft",
                                       "arrow_left",
                                       inputSource=inputState.ArrowKeys))
     array.append(
         inputState.watchWithModifiers("cannonRight",
                                       "arrow_right",
                                       inputSource=inputState.ArrowKeys))
     self.cist = array  # cannonInputStateArray
     taskMgr.add(self.__handleCannonControls,
                 "DEagleGame-handleCannonControls")
     taskMgr.add(self.__broadcastCannonAndLTTask,
                 "DEagleGame-broadcastCannonAndLT")
     self.acceptOnce("control", self.controlKeyPressed)
    def setWASDTurn(self, turn):
        self.__WASDTurn = turn
        if not self.isEnabled:
            return
        turnLeftWASDSet = inputState.isSet('turnLeft', inputSource=inputState.WASD)
        turnRightWASDSet = inputState.isSet('turnRight', inputSource=inputState.WASD)
        slideLeftWASDSet = inputState.isSet('slideLeft', inputSource=inputState.WASD)
        slideRightWASDSet = inputState.isSet('slideRight', inputSource=inputState.WASD)
        for token in self.WASDTurnTokens:
            token.release()

        if turn:
            self.WASDTurnTokens = (inputState.watchWithModifiers('turnLeft', 'a', inputSource=inputState.WASD),
             inputState.watchWithModifiers('turnRight', 'd', inputSource=inputState.WASD))
            inputState.set('turnLeft', slideLeftWASDSet, inputSource=inputState.WASD)
            inputState.set('turnRight', slideRightWASDSet, inputSource=inputState.WASD)
            inputState.set('slideLeft', False, inputSource=inputState.WASD)
            inputState.set('slideRight', False, inputSource=inputState.WASD)
        else:
            self.WASDTurnTokens = (inputState.watchWithModifiers('slideLeft', 'a', inputSource=inputState.WASD),
             inputState.watchWithModifiers('slideRight', 'd', inputSource=inputState.WASD))
            inputState.set('slideLeft', turnLeftWASDSet, inputSource=inputState.WASD)
            inputState.set('slideRight', turnRightWASDSet, inputSource=inputState.WASD)
            inputState.set('turnLeft', False, inputSource=inputState.WASD)
            inputState.set('turnRight', False, inputSource=inputState.WASD)
    def disable(self):
        assert self.notify.debugCall(id(self))
        self.isEnabled = 0

        for token in self.inputStateTokens:
            token.release()
        self.inputStateTokens = []

        for token in self.WASDTurnTokens:
            token.release()
        self.WASDTurnTokens = []

        if self.currentControls:
            self.currentControls.disableAvatarControls()

        if self.passMessagesThrough:  # for not breaking toontown
            ist = self.inputStateTokens
            ist.append(
                inputState.watchWithModifiers(
                    "forward", "arrow_up", inputSource=inputState.ArrowKeys))
            ist.append(
                inputState.watchWithModifiers(
                    "reverse", "arrow_down", inputSource=inputState.ArrowKeys))
            ist.append(
                inputState.watchWithModifiers(
                    "turnLeft", "arrow_left",
                    inputSource=inputState.ArrowKeys))
            ist.append(
                inputState.watchWithModifiers(
                    "turnRight",
                    "arrow_right",
                    inputSource=inputState.ArrowKeys))
 def __init__(self, enable=True, passMessagesThrough = False):
     assert self.notify.debug("init control manager %s" % (passMessagesThrough))
     assert self.notify.debugCall(id(self))
     self.passMessagesThrough = passMessagesThrough
     self.inputStateTokens = []
     # Used to switch between strafe and turn. We will reset to whatever was last set.
     self.WASDTurnTokens = []
     self.__WASDTurn = True
     self.controls = {}
     self.currentControls = None
     self.currentControlsName = None
     self.isEnabled = 0
     if enable:
         self.enable()
     #self.monitorTask = taskMgr.add(self.monitor, "ControlManager-%s"%(id(self)), priority=-1)
     self.forceAvJumpToken = None
     
     
     
     if self.passMessagesThrough: # for not breaking toontown
         ist=self.inputStateTokens
         ist.append(inputState.watchWithModifiers("forward", "arrow_up", inputSource=inputState.ArrowKeys))
         ist.append(inputState.watchWithModifiers("reverse", "arrow_down", inputSource=inputState.ArrowKeys))
         ist.append(inputState.watchWithModifiers("turnLeft", "arrow_left", inputSource=inputState.ArrowKeys))
         ist.append(inputState.watchWithModifiers("turnRight", "arrow_right", inputSource=inputState.ArrowKeys))
    def disable(self):
        self.isEnabled = 0
        for token in self.inputStateTokens:
            token.release()

        self.inputStateTokens = []
        for token in self.WASDTurnTokens:
            token.release()

        self.WASDTurnTokens = []
        if self.currentControls:
            self.currentControls.disableAvatarControls()

        if self.passMessagesThrough:
            ist = self.inputStateTokens
            ist.append(
                inputState.watchWithModifiers(
                    'forward', 'arrow_up', inputSource=inputState.ArrowKeys))
            ist.append(
                inputState.watchWithModifiers(
                    'reverse', 'arrow_down', inputSource=inputState.ArrowKeys))
            ist.append(
                inputState.watchWithModifiers(
                    'turnLeft', 'arrow_left',
                    inputSource=inputState.ArrowKeys))
            ist.append(
                inputState.watchWithModifiers(
                    'turnRight',
                    'arrow_right',
                    inputSource=inputState.ArrowKeys))
Beispiel #12
0
    def setWASDTurn(self, turn):
        self.__WASDTurn = turn

        if not self.isEnabled:
            return

        turnLeftWASDSet = inputState.isSet("turnLeft",
                                           inputSource=inputState.WASD)
        turnRightWASDSet = inputState.isSet("turnRight",
                                            inputSource=inputState.WASD)
        slideLeftWASDSet = inputState.isSet("slideLeft",
                                            inputSource=inputState.WASD)
        slideRightWASDSet = inputState.isSet("slideRight",
                                             inputSource=inputState.WASD)

        for token in self.WASDTurnTokens:
            token.release()

        if turn:  #If we want toons to be able to turn instead of sliding left to right
            self.WASDTurnTokens = (
                inputState.watchWithModifiers("turnLeft",
                                              "a",
                                              inputSource=inputState.WASD),
                inputState.watchWithModifiers("turnRight",
                                              "d",
                                              inputSource=inputState.WASD),
            )

            inputState.set("turnLeft",
                           slideLeftWASDSet,
                           inputSource=inputState.WASD)
            inputState.set("turnRight",
                           slideRightWASDSet,
                           inputSource=inputState.WASD)

            inputState.set("slideLeft", False, inputSource=inputState.WASD)
            inputState.set("slideRight", False, inputSource=inputState.WASD)

        else:
            self.WASDTurnTokens = (
                inputState.watchWithModifiers("slideLeft",
                                              "a",
                                              inputSource=inputState.WASD),
                inputState.watchWithModifiers("slideRight",
                                              "d",
                                              inputSource=inputState.WASD),
            )

            inputState.set("slideLeft",
                           turnLeftWASDSet,
                           inputSource=inputState.WASD)
            inputState.set("slideRight",
                           turnRightWASDSet,
                           inputSource=inputState.WASD)

            inputState.set("turnLeft", False, inputSource=inputState.WASD)
            inputState.set("turnRight", False, inputSource=inputState.WASD)
Beispiel #13
0
 def grabMovement(self):
     # Keyboard
     self.tokenGroup.release()
     # This is used to climbUp
     self.tokenGroup.addToken(inputState.watchWithModifiers('climb', 'q', inputSource=inputState.WASD))
     self.tokenGroup.addToken(inputState.watchWithModifiers('left', 'a', inputSource=inputState.WASD))
     self.tokenGroup.addToken(inputState.watchWithModifiers('right', 'd', inputSource=inputState.WASD))
     self.tokenGroup.addToken(inputState.watchWithModifiers('fall', 's', inputSource=inputState.WASD))
     for item in ['forward', 'left', 'reverse', 'right']:
         inputState.set(item, False, inputSource=inputState.WASD)
     self.isGrabMovement = True
 def _startKeyboardUpdateTask(self):
     self._stopKeyboardUpdateTask()
     self.inputStateTokens = []
     ist = self.inputStateTokens
     ist.append(
         inputState.watchWithModifiers('forward',
                                       'arrow_up',
                                       inputSource=inputState.ArrowKeys))
     ist.append(
         inputState.watchWithModifiers('reverse',
                                       'arrow_down',
                                       inputSource=inputState.ArrowKeys))
Beispiel #15
0
    def __init__(self):
        assert self.notify.debugCall(id(self))
        self.controls = {}
        self.currentControls = None
        self.currentControlsName = None
        self.isEnabled = 1
        #self.monitorTask = taskMgr.add(self.monitor, "ControlManager-%s"%(id(self)), priority=-1)
        self.forceAvJumpToken = None
        # keep track of what we do on the inputState so we can undo it later on
        self.inputStateTokens = []
        ist=self.inputStateTokens
        ist.append(inputState.watch("run", 'runningEvent', "running-on", "running-off"))
        
        ist.append(inputState.watchWithModifiers("forward", "arrow_up", inputSource=inputState.ArrowKeys))
        ist.append(inputState.watch("forward", "force-forward", "force-forward-stop"))
        
        ist.append(inputState.watchWithModifiers("reverse", "arrow_down", inputSource=inputState.ArrowKeys))
        ist.append(inputState.watchWithModifiers("reverse", "mouse4", inputSource=inputState.Mouse))
        
        if self.wantWASD:

            
            
            ist.append(inputState.watchWithModifiers("turnLeft", "arrow_left", inputSource=inputState.ArrowKeys))
            ist.append(inputState.watch("turnLeft", "mouse-look_left", "mouse-look_left-done"))
            ist.append(inputState.watch("turnLeft", "force-turnLeft", "force-turnLeft-stop"))
            
            ist.append(inputState.watchWithModifiers("turnRight", "arrow_right", inputSource=inputState.ArrowKeys))
            ist.append(inputState.watch("turnRight", "mouse-look_right", "mouse-look_right-done"))
            ist.append(inputState.watch("turnRight", "force-turnRight", "force-turnRight-stop"))

            ist.append(inputState.watchWithModifiers("forward", "w", inputSource=inputState.WASD))
            ist.append(inputState.watchWithModifiers("reverse", "s", inputSource=inputState.WASD))

            # Used to switch between strafe and turn. We will default to turn
            self.WASDTurnTokens = ()
            self.setWASDTurn(1)

        else:
            ist.append(inputState.watchWithModifiers("turnLeft", "arrow_left", inputSource=inputState.ArrowKeys))
            ist.append(inputState.watch("turnLeft", "mouse-look_left", "mouse-look_left-done"))
            ist.append(inputState.watch("turnLeft", "force-turnLeft", "force-turnLeft-stop"))
            
            ist.append(inputState.watchWithModifiers("turnRight", "arrow_right", inputSource=inputState.ArrowKeys))
            ist.append(inputState.watch("turnRight", "mouse-look_right", "mouse-look_right-done"))
            ist.append(inputState.watch("turnRight", "force-turnRight", "force-turnRight-stop"))


        # Jump controls
        if self.wantWASD:
            ist.append(inputState.watchWithModifiers("jump", "space"))
        else:
            ist.append(inputState.watch("jump", "control", "control-up"))
Beispiel #16
0
 def enterControlCannon(self):
     self.__setupCamera(1)
     self.cannon = self.cr.doId2do.get(self.cannonId)
     array = []
     array.append(inputState.watchWithModifiers('cannonUp', 'arrow_up', inputSource=inputState.ArrowKeys))
     array.append(inputState.watchWithModifiers('cannonDown', 'arrow_down', inputSource=inputState.ArrowKeys))
     array.append(inputState.watchWithModifiers('cannonLeft', 'arrow_left', inputSource=inputState.ArrowKeys))
     array.append(inputState.watchWithModifiers('cannonRight', 'arrow_right', inputSource=inputState.ArrowKeys))
     self.cist = array
     taskMgr.add(self.__handleCannonControls, 'DEagleGame-handleCannonControls')
     taskMgr.add(self.__broadcastCannonAndLTTask, 'DEagleGame-broadcastCannonAndLT')
     self.acceptOnce('control', self.controlKeyPressed)
Beispiel #17
0
    def disable(self):
        self.isEnabled = 0

        for token in self.inputStateTokens:
            token.release()
        self.inputStateTokens = []

        for token in self.WASDTurnTokens:
            token.release()
        self.WASDTurnTokens = []

        if self.currentControls:
            self.currentControls.disableAvatarControls()
            
        if self.passMessagesThrough: # for not breaking toontown          
            if self.wantWASD:
                print ':(ToontownControlManager) WASD support was enabled.'
                self.istWASD.append(inputState.watchWithModifiers("forward", "w", inputSource=inputState.WASD))
                self.istWASD.append(inputState.watchWithModifiers("reverse", "s", inputSource=inputState.WASD))
                self.istWASD.append(inputState.watchWithModifiers("turnLeft", "a", inputSource=inputState.WASD))
                self.istWASD.append(inputState.watchWithModifiers("turnRight", "d", inputSource=inputState.WASD))
            else:
                print ':(ToontownControlManager) WASD support was disabled.'
                self.istNormal.append(inputState.watchWithModifiers("forward", "arrow_up", inputSource=inputState.ArrowKeys))
                self.istNormal.append(inputState.watchWithModifiers("reverse", "arrow_down", inputSource=inputState.ArrowKeys))
                self.istNormal.append(inputState.watchWithModifiers("turnLeft", "arrow_left", inputSource=inputState.ArrowKeys))
                self.istNormal.append(inputState.watchWithModifiers("turnRight", "arrow_right", inputSource=inputState.ArrowKeys))
Beispiel #18
0
    def __init__(self):
        #the window props
        wp = WindowProperties.getDefault()
        wp.setUndecorated(False)
        wp.setFullscreen(False)
        wp.setSize(cfg['win-size'][0], cfg['win-size'][1])
        wp.setOrigin(-2, -2)
        wp.setFixedSize(False)
        wp.setTitle("Grass and Gas - wezu -PyWeek 21")
        #open the window
        base.openMainWindow(props=wp)

        base.setBackgroundColor(0, 0, 0, 1)
        base.disableMouse()

        self.mode = DRIVING

        #make sure the config is ok
        cfg['hardware-skinning'] = ConfigVariableBool('hardware-skinning',
                                                      True).getValue()
        cfg['srgb'] = ConfigVariableBool('framebuffer-srgb', False).getValue()
        cfg['win-size'] = [
            ConfigVariableInt('win-size', '640 480').getWord(0),
            ConfigVariableInt('win-size', '640 480').getWord(1)
        ]
        cfg['music-volume'] = ConfigVariableInt('music-volume',
                                                '50').getValue()
        cfg['sound-volume'] = ConfigVariableInt('sound-volume',
                                                '100').getValue()
        cfg['key-forward'] = ConfigVariableString('key-forward',
                                                  'w').getValue()
        cfg['key-back'] = ConfigVariableString('key-back', 's').getValue()
        cfg['key-left'] = ConfigVariableString('key-left', 'a').getValue()
        cfg['key-right'] = ConfigVariableString('key-right', 'd').getValue()
        cfg['key-jump'] = ConfigVariableString('key-jump', 'space').getValue()
        cfg['key-cut-grass'] = ConfigVariableString('key-cut-grass',
                                                    'shift').getValue()
        cfg['key-enter-exit-car'] = ConfigVariableString(
            'key-enter-exit-car', 'tab').getValue()
        cfg['shadow-size'] = ConfigVariableInt('shadow-size', 1024).getValue()
        cfg['shadow-area'] = ConfigVariableInt('shadow-area', 50).getValue()

        self.accept('escape', self.doExit)
        self.accept('f1', self.hideHelp)
        self.accept(cfg['key-jump'], self.doFlip)
        self.accept(cfg['key-enter-exit-car'], self.changeMode)
        self.accept(cfg['key-cut-grass'], self.shear)
        self.accept('window-event', self.onWindowEvent)

        inputState.watchWithModifiers('forward', cfg['key-forward'])
        inputState.watchWithModifiers('reverse', cfg['key-back'])
        inputState.watchWithModifiers('turnLeft', cfg['key-left'])
        inputState.watchWithModifiers('turnRight', cfg['key-right'])

        # Task
        taskMgr.add(self.update, 'updateWorld')
        taskMgr.doMethodLater(5.0, self.countGrass, 'grass_counter')

        # Physics
        self.setup()
Beispiel #19
0
    def bind_keys(self):
        self.acceptOnce('Pause-game', self.pause)
        base.taskMgr.add(self.keyboard_watcher, 'player_keyboard_watcher')

        self.watch_tokens.append(inputState.watchWithModifiers('forward', Options.key_forward))
        self.watch_tokens.append(inputState.watchWithModifiers('back', Options.key_back))
        self.watch_tokens.append(inputState.watchWithModifiers('left', Options.key_left))
        self.watch_tokens.append(inputState.watchWithModifiers('right', Options.key_right))

        if self.__noclip:
            self.watch_tokens.append(inputState.watchWithModifiers('up', Options.key_jump))
            self.watch_tokens.append(inputState.watchWithModifiers('down', Options.key_crouch))
        else:
            self.accept(Options.key_jump, self.char.jump)
            self.accept(Options.key_crouch, self.char.crouch, [True])
            self.accept(Options.key_crouch + '-up', self.char.crouch, [False])
            self.accept(Options.key_ability1, self.char.ability1, [True])
            self.accept(Options.key_ability1 + '-up', self.char.ability1, [False])
            self.accept(Options.key_ability2, self.char.ability2, [True])
            self.accept(Options.key_ability2 + '-up', self.char.ability2, [False])
            self.accept(Options.key_ability3, self.char.ability3)

        if base.mouseWatcherNode.hasMouse():
            win.center_cursor()

            base.taskMgr.add(self.mouse_watcher, 'player_mouse_watcher', appendTask=True,
                             extraArgs=[Options.mouse_sensitivity, Options.invert_mouse])

            if not self.__noclip:
                self.watch_tokens.append(inputState.watchWithModifiers('fire1', Options.key_fire1))
                self.watch_tokens.append(inputState.watchWithModifiers('fire2', Options.key_fire2))
    def disable(self):
        self.isEnabled = 0
        for token in self.istNormal:
            token.release()

        self.istNormal = []
        for token in self.inputStateTokens:
            token.release()

        self.inputStateTokens = []
        for token in self.istWASD:
            token.release()

        self.istWASD = []
        for token in self.WASDTurnTokens:
            token.release()

        self.WASDTurnTokens = []
        if self.currentControls:
            self.currentControls.disableAvatarControls()
        keymap = settings.get('keymap', {})
        if self.passMessagesThrough:
            if self.wantWASD:
                self.istWASD.append(inputState.watchWithModifiers('forward', keymap.get('MOVE_UP', base.MOVE_UP), inputSource=inputState.WASD))
                self.istWASD.append(inputState.watchWithModifiers('reverse', keymap.get('MOVE_DOWN', base.MOVE_DOWN), inputSource=inputState.WASD))
                self.istWASD.append(inputState.watchWithModifiers('turnLeft', keymap.get('MOVE_LEFT', base.MOVE_LEFT), inputSource=inputState.WASD))
                self.istWASD.append(inputState.watchWithModifiers('turnRight', keymap.get('MOVE_RIGHT', base.MOVE_RIGHT), inputSource=inputState.WASD))
            else:
                self.istNormal.append(inputState.watchWithModifiers('forward', base.MOVE_UP, inputSource=inputState.ArrowKeys))
                self.istNormal.append(inputState.watchWithModifiers('reverse', base.MOVE_DOWN, inputSource=inputState.ArrowKeys))
                self.istNormal.append(inputState.watchWithModifiers('turnLeft', base.MOVE_LEFT, inputSource=inputState.ArrowKeys))
                self.istNormal.append(inputState.watchWithModifiers('turnRight', base.MOVE_RIGHT, inputSource=inputState.ArrowKeys))
    def disable(self):
        self.isEnabled = 0

        for token in self.inputStateTokens:
            token.release()
        self.inputStateTokens = []

        for token in self.WASDTurnTokens:
            token.release()
        self.WASDTurnTokens = []

        if self.currentControls:
            self.currentControls.disableAvatarControls()

        # This is so we don't break Toontown...
        if self.passMessagesThrough:
            if self.wantWASD:
                self.istWASD.append(inputState.watchWithModifiers("forward", "w", inputSource=inputState.WASD))
                self.istWASD.append(inputState.watchWithModifiers("reverse", "s", inputSource=inputState.WASD))
                self.istWASD.append(inputState.watchWithModifiers("turnLeft", "a", inputSource=inputState.WASD))
                self.istWASD.append(inputState.watchWithModifiers("turnRight", "d", inputSource=inputState.WASD))
            else:
                self.istNormal.append(
                    inputState.watchWithModifiers("forward", "arrow_up", inputSource=inputState.ArrowKeys)
                )
                self.istNormal.append(
                    inputState.watchWithModifiers("reverse", "arrow_down", inputSource=inputState.ArrowKeys)
                )
                self.istNormal.append(
                    inputState.watchWithModifiers("turnLeft", "arrow_left", inputSource=inputState.ArrowKeys)
                )
                self.istNormal.append(
                    inputState.watchWithModifiers("turnRight", "arrow_right", inputSource=inputState.ArrowKeys)
                )
 def _startKeyboardUpdateTask(self):
     self._stopKeyboardUpdateTask()
     self.inputStateTokens = []
     ist = self.inputStateTokens
     ist.append(inputState.watchWithModifiers('forward', 'arrow_up', inputSource=inputState.ArrowKeys))
     ist.append(inputState.watchWithModifiers('reverse', 'arrow_down', inputSource=inputState.ArrowKeys))
     ist.append(inputState.watchWithModifiers('turnLeft', 'arrow_left', inputSource=inputState.ArrowKeys))
     ist.append(inputState.watchWithModifiers('turnRight', 'arrow_right', inputSource=inputState.ArrowKeys))
     ist.append(inputState.watchWithModifiers('forward', 'w', inputSource=inputState.WASD))
     ist.append(inputState.watchWithModifiers('reverse', 's', inputSource=inputState.WASD))
     ist.append(inputState.watchWithModifiers('turnLeft', 'a', inputSource=inputState.WASD))
     ist.append(inputState.watchWithModifiers('turnRight', 'd', inputSource=inputState.WASD))
     ist.append(inputState.watchWithModifiers('turnLeft', 'q', inputSource=inputState.QE))
     ist.append(inputState.watchWithModifiers('turnRight', 'e', inputSource=inputState.QE))
     taskMgr.add(self._keyboardUpdateTask, '%s-KeyboardUpdate' % self._getTopNodeName(), priority=40)
Beispiel #23
0
    def __init__(self, _game):

        # Reset Player
        self.accept('r', self.msgPlayerReset)

        # Change movement axis
        self.accept('1', self.msgChangeMovement, ['1'])
        self.accept('2', self.msgChangeMovement, ['2'])
        self.accept('3', self.msgChangeMovement, ['3'])
        self.accept('4', self.msgChangeMovement, ['4'])

        ## MOVEMENT INPUTS ##
        inputState.watchWithModifiers('up', 'w')
        inputState.watchWithModifiers('down', 's')
        inputState.watchWithModifiers('left', 'a')
        inputState.watchWithModifiers('right', 'd')
        inputState.watchWithModifiers('space', 'space')
 def enable(self):
     if self.isEnabled:
         return
     self.isEnabled = 1
     keymap = settings.get('keymap', {})
     self.inputStateTokens.extend((inputState.watch('run', 'runningEvent', 'running-on', 'running-off'), inputState.watch('forward', 'force-forward', 'force-forward-stop')))
     if self.wantWASD:
         self.istWASD.extend((inputState.watch('turnLeft', 'mouse-look_left', 'mouse-look_left-done'),
          inputState.watch('turnLeft', 'force-turnLeft', 'force-turnLeft-stop'),
          inputState.watch('turnRight', 'mouse-look_right', 'mouse-look_right-done'),
          inputState.watch('turnRight', 'force-turnRight', 'force-turnRight-stop'),
          inputState.watchWithModifiers('forward', keymap.get('MOVE_UP', base.MOVE_UP), inputSource=inputState.WASD),
          inputState.watchWithModifiers('reverse', keymap.get('MOVE_DOWN', base.MOVE_DOWN), inputSource=inputState.WASD),
          inputState.watchWithModifiers('jump', keymap.get('JUMP', base.JUMP))))
         self.setWASDTurn(True)
     else:
         self.istNormal.extend((inputState.watchWithModifiers('forward', base.MOVE_UP, inputSource=inputState.ArrowKeys),
          inputState.watchWithModifiers('reverse', base.MOVE_DOWN, inputSource=inputState.ArrowKeys),
          inputState.watchWithModifiers('turnLeft', base.MOVE_LEFT, inputSource=inputState.ArrowKeys),
          inputState.watchWithModifiers('turnRight', base.MOVE_RIGHT, inputSource=inputState.ArrowKeys),
          inputState.watch('jump', base.JUMP, base.JUMP + '-up')))
         self.istNormal.extend((inputState.watch('turnLeft', 'mouse-look_left', 'mouse-look_left-done'),
          inputState.watch('turnLeft', 'force-turnLeft', 'force-turnLeft-stop'),
          inputState.watch('turnRight', 'mouse-look_right', 'mouse-look_right-done'),
          inputState.watch('turnRight', 'force-turnRight', 'force-turnRight-stop')))
     if self.currentControls:
         self.currentControls.enableAvatarControls()
Beispiel #25
0
    def disable(self):
        self.isEnabled = 0

        for token in self.inputStateTokens:
            token.release()
        self.inputStateTokens = []

        for token in self.WASDTurnTokens:
            token.release()
        self.WASDTurnTokens = []

        if self.currentControls:
            self.currentControls.disableAvatarControls()

        # This is so we don't break Toontown...
        if self.passMessagesThrough:
            if self.wantWASD:
                self.istWASD.append(
                    inputState.watchWithModifiers("forward",
                                                  "w",
                                                  inputSource=inputState.WASD))
                self.istWASD.append(
                    inputState.watchWithModifiers("reverse",
                                                  "s",
                                                  inputSource=inputState.WASD))
                self.istWASD.append(
                    inputState.watchWithModifiers("turnLeft",
                                                  "a",
                                                  inputSource=inputState.WASD))
                self.istWASD.append(
                    inputState.watchWithModifiers("turnRight",
                                                  "d",
                                                  inputSource=inputState.WASD))
            else:
                self.istNormal.append(
                    inputState.watchWithModifiers(
                        "forward",
                        "arrow_up",
                        inputSource=inputState.ArrowKeys))
                self.istNormal.append(
                    inputState.watchWithModifiers(
                        "reverse",
                        "arrow_down",
                        inputSource=inputState.ArrowKeys))
                self.istNormal.append(
                    inputState.watchWithModifiers(
                        "turnLeft",
                        "arrow_left",
                        inputSource=inputState.ArrowKeys))
                self.istNormal.append(
                    inputState.watchWithModifiers(
                        "turnRight",
                        "arrow_right",
                        inputSource=inputState.ArrowKeys))
Beispiel #26
0
    def __init__(self):      
        #the window props
        wp = WindowProperties.getDefault()                  
        wp.setUndecorated(False)          
        wp.setFullscreen(False)     
        wp.setSize(cfg['win-size'][0], cfg['win-size'][1])  
        wp.setOrigin(-2,-2)  
        wp.setFixedSize(False)  
        wp.setTitle("Grass and Gas - wezu -PyWeek 21")
        #open the window
        base.openMainWindow(props = wp)  
          
        base.setBackgroundColor(0, 0, 0, 1)
        base.disableMouse()   
        
        self.mode=DRIVING
        
        #make sure the config is ok
        cfg['hardware-skinning']=ConfigVariableBool('hardware-skinning', True).getValue()     
        cfg['srgb']=ConfigVariableBool('framebuffer-srgb', False).getValue()
        cfg['win-size']=[ConfigVariableInt('win-size', '640 480').getWord(0), ConfigVariableInt('win-size', '640 480').getWord(1)] 
        cfg['music-volume']=ConfigVariableInt('music-volume', '50').getValue()
        cfg['sound-volume']=ConfigVariableInt('sound-volume', '100').getValue()
        cfg['key-forward']=ConfigVariableString('key-forward','w').getValue()
        cfg['key-back']=ConfigVariableString('key-back','s').getValue()
        cfg['key-left']=ConfigVariableString('key-left','a').getValue()
        cfg['key-right']=ConfigVariableString('key-right','d').getValue()
        cfg['key-jump']=ConfigVariableString('key-jump','space').getValue()
        cfg['key-cut-grass']=ConfigVariableString('key-cut-grass','shift').getValue()
        cfg['key-enter-exit-car']=ConfigVariableString('key-enter-exit-car','tab').getValue()
        cfg['shadow-size']=ConfigVariableInt('shadow-size',1024).getValue()
        cfg['shadow-area']=ConfigVariableInt('shadow-area',50).getValue()
        
       
        
        self.accept('escape', self.doExit)
        self.accept('f1', self.hideHelp)
        self.accept(cfg['key-jump'], self.doFlip)
        self.accept( cfg['key-enter-exit-car'], self.changeMode)
        self.accept(cfg['key-cut-grass'], self.shear)
        self.accept( 'window-event', self.onWindowEvent)
        
        inputState.watchWithModifiers('forward', cfg['key-forward'])
        inputState.watchWithModifiers('reverse', cfg['key-back'])
        inputState.watchWithModifiers('turnLeft', cfg['key-left'])
        inputState.watchWithModifiers('turnRight', cfg['key-right'])

        # Task
        taskMgr.add(self.update, 'updateWorld') 
        taskMgr.doMethodLater(5.0, self.countGrass, 'grass_counter')
        
        # Physics
        self.setup()
Beispiel #27
0
	def __init__(self,game,render,world,accept,health=100,damage=0):
		super(Eve,self).__init__('Eve',health,damage)
		#----- INSTANCE VARIABLES -----#
		self.state = {'normal': True, 'jumping' : False, 'rolling' : False}
		self.speed = Vec3(0, 0, 0)
        	self.omega = 0.0
		self.tiresCollected = 0
		self.accept = accept
		self.ready = True

		#----- PRIVATE INSTANCE VARIABLES -----#		
		self.__render = render
		self.__world = world
		self.__game = game

		#----- ACTOR SETUP -----#
        	self.actorNP1 = Actor('models/eve/eve.egg', {
                         				    'run' : 'models/eve/eve-run.egg',
                         				    'walk' : 'models/eve/eve-walk.egg',
                         				    'jump' : 'models/eve/eve-jump.egg'})
        	self.actorNP2 = Actor('models/eve/eve-tireroll.egg', {'roll' : 'models/eve/eve-tireroll.egg'})
		self.actorNP1.setPlayRate(2,'walk')
		

		#----- PREPARE SFX -----#
		self.jump = base.loader.loadSfx("sfx/jump.wav")
		self.jump.setVolume(.1)
		self.running = base.loader.loadSfx("sfx/walking.wav")
		self.running.setLoop(True)
		self.running.setPlayRate(1.55)
		self.running.setVolume(.08)
		self.land = base.loader.loadSfx("sfx/land.flac")
		self.land.setLoop(False)
		self.land.setVolume(.05)
		self.roll = base.loader.loadSfx("sfx/rolling.wav")
		self.roll.setLoop(True)
		self.roll.setVolume(.09)
		self.ouch = base.loader.loadSfx("sfx/ouch.wav")
		self.ouch.setLoop(False)
		self.ouch.setVolume(.75)
		self.ouch.setPlayRate(1.25)
		self.throw = base.loader.loadSfx("sfx/throw.wav")
		self.throw.setLoop(False)
		self.throw.setVolume(.75)
		self.blocked = base.loader.loadSfx("sfx/blocked.wav")
		self.blocked.setVolume(.05)
		
		#----- SETUP CONTROL FOR EVE -----#
        	inputState.watchWithModifiers('forward', 'w')
        	inputState.watchWithModifiers('turnLeft', 'a')
        	inputState.watchWithModifiers('turnRight', 'd')	
        	inputState.watchWithModifiers('backwards', 's')	
Beispiel #28
0
    def __init__(self):

        # Input
        self.accept('space', self.doJump)

        inputState.watchWithModifiers('forward', 'w')
        inputState.watchWithModifiers('reverse', 's')
        inputState.watchWithModifiers('turnLeft', 'a')
        inputState.watchWithModifiers('turnRight', 'd')

        health = 100
        self.isNotWalking = False
        self.isJumping = False
Beispiel #29
0
    def __init__(self):

        # Input
        self.accept('space', self.doJump)

        inputState.watchWithModifiers('forward', 'w')
        inputState.watchWithModifiers('reverse', 's')
        inputState.watchWithModifiers('turnLeft', 'a')
        inputState.watchWithModifiers('turnRight', 'd')

        health = 100
        self.isNotWalking = False
        self.isJumping = False
Beispiel #30
0
 def __init__(self, av):
     FSM.__init__(self, 'CameraFSM')
     self.av = av
     self.orbitCamera = ShipCamera.ShipCamera(self.av)
     self.orbitCamera.setLookAtOffset(Vec3(0, 0, self.av.getHeight()))
     self.fpsCamera = FPSCamera.FPSCamera(self.av)
     self.cannonCamera = CannonCamera.CannonCamera()
     self.cannonDefenseCamera = CannonDefenseCamera.CannonDefenseCamera()
     self.currentCamera = None
     self.cameras = (self.orbitCamera, self.fpsCamera, self.cannonCamera, self.cannonDefenseCamera)
     self._rmbToken = inputState.watchWithModifiers('RMB', 'mouse3')
    def disable(self):
        assert self.notify.debugCall(id(self))
        self.isEnabled = 0

        for token in self.inputStateTokens:
            token.release()
        self.inputStateTokens = []

        for token in self.WASDTurnTokens:
            token.release()
        self.WASDTurnTokens = []

        if self.currentControls:
            self.currentControls.disableAvatarControls()
            
        if self.passMessagesThrough: # for not breaking toontown
            ist=self.inputStateTokens
            ist.append(inputState.watchWithModifiers("forward", "arrow_up", inputSource=inputState.ArrowKeys))
            ist.append(inputState.watchWithModifiers("reverse", "arrow_down", inputSource=inputState.ArrowKeys))
            ist.append(inputState.watchWithModifiers("turnLeft", "arrow_left", inputSource=inputState.ArrowKeys))
            ist.append(inputState.watchWithModifiers("turnRight", "arrow_right", inputSource=inputState.ArrowKeys))
Beispiel #32
0
    def __init__(self):

        # Heightfield (static)
        self.height = 38.0

        ShowBase.__init__(self)
        base.setBackgroundColor(0.1, 0.1, 0.8, 1)
        base.setFrameRateMeter(True)

        base.cam.setPos(0, -150, 200)
        base.cam.lookAt(0, 0, 0)

        # Light
        alight = AmbientLight('ambientLight')
        alight.setColor(Vec4(0.5, 0.5, 0.5, 1))
        alightNP = render.attachNewNode(alight)

        dlight = DirectionalLight('directionalLight')
        dlight.setDirection(Vec3(1, 1, -1))
        dlight.setColor(Vec4(0.7, 0.7, 0.7, 1))
        dlightNP = render.attachNewNode(dlight)

        render.clearLight()
        render.setLight(alightNP)
        render.setLight(dlightNP)

        # Input
        self.accept('escape', self.doExit)

        inputState.watchWithModifiers('forward', 'w')
        inputState.watchWithModifiers('left', 'a')
        inputState.watchWithModifiers('reverse', 's')
        inputState.watchWithModifiers('backward', 'x')
        inputState.watchWithModifiers('right', 'd')

        # Task
        taskMgr.add(self.update, 'updateWorld')

        # Physics
        self.setup()
Beispiel #33
0
    def __init__(self, _game):
        
        self.game = _game
        
        ## MOVEMENT INPUTS ## 
        inputState.watchWithModifiers('forward', 'w')
        inputState.watchWithModifiers('backward', 's')
        inputState.watchWithModifiers('left', 'a')
        inputState.watchWithModifiers('right', 'd')

        self.oldInputCmds = []

        taskMgr.add(self.doMovement,"updateMovement")
        taskMgr.doMethodLater(0.1, self.catchInput, 'CatchInput')
    def setWASDTurn(self, turn):
        # This probably needs to be cleaned up, I don't think Toontown uses slide anywhere
        self.__WASDTurn = turn

        if not self.isEnabled:
            return
        
        keymap = settings.get('keymap', {})
        
        turnLeftWASDSet = inputState.isSet("turnLeft", inputSource=inputState.WASD)
        turnRightWASDSet = inputState.isSet("turnRight", inputSource=inputState.WASD)
        slideLeftWASDSet = inputState.isSet("slideLeft", inputSource=inputState.WASD)
        slideRightWASDSet = inputState.isSet("slideRight", inputSource=inputState.WASD)

        for token in self.WASDTurnTokens:
            token.release()

        if turn:
            self.WASDTurnTokens = (
                inputState.watchWithModifiers("turnLeft", keymap.get('MOVE_LEFT', base.MOVE_LEFT), inputSource=inputState.WASD),
                inputState.watchWithModifiers("turnRight", keymap.get('MOVE_RIGHT', base.MOVE_RIGHT), inputSource=inputState.WASD),
                )

            inputState.set("turnLeft", slideLeftWASDSet, inputSource=inputState.WASD)
            inputState.set("turnRight", slideRightWASDSet, inputSource=inputState.WASD)

            inputState.set("slideLeft", False, inputSource=inputState.WASD)
            inputState.set("slideRight", False, inputSource=inputState.WASD)

        else:
            self.WASDTurnTokens = (
                inputState.watchWithModifiers("slideLeft", keymap.get('MOVE_LEFT', base.MOVE_LEFT), inputSource=inputState.WASD),
                inputState.watchWithModifiers("slideRight", keymap.get('MOVE_RIGHT', base.MOVE_RIGHT), inputSource=inputState.WASD),
                )

            inputState.set("slideLeft", turnLeftWASDSet, inputSource=inputState.WASD)
            inputState.set("slideRight", turnRightWASDSet, inputSource=inputState.WASD)
                
            inputState.set("turnLeft", False, inputSource=inputState.WASD)
            inputState.set("turnRight", False, inputSource=inputState.WASD)
    def __init__(self):
        ShowBase.__init__(self)

        self.setupLights()
        # Input
        self.accept('escape', self.doExit)
        self.accept('r', self.doReset)
        self.accept('f3', self.toggleDebug)
        self.accept('space', self.doJump)
	self.accept("q", self.setKey, ["cam-left", True])
	self.accept("e", self.setKey, ["cam-right", True])
	self.accept("q-up", self.setKey, ["cam-left", False])
	self.accept("e-up", self.setKey, ["cam-right", False])

        inputState.watchWithModifiers('forward', 'w')
        inputState.watchWithModifiers('reverse', 's')
        inputState.watchWithModifiers('turnLeft', 'a')
        inputState.watchWithModifiers('turnRight', 'd')

        # Task
        taskMgr.add(self.update, 'updateWorld')

        self.setup()
        base.setBackgroundColor(0.1, 0.1, 0.8, 1)
        base.setFrameRateMeter(True)
        base.disableMouse()
        base.camera.setPos(self.characterNP.getPos()+4)
        base.camera.setHpr(self.characterNP.getHpr())
        base.camera.lookAt(self.characterNP)
        # Create a floater object.  We use the "floater" as a temporary
        # variable in a variety of calculations.
        self.floater = NodePath(PandaNode("floater"))
        self.floater.reparentTo(render)
		
		# Game state variables
        self.isMoving = False
	self.tokensCount = 0
	self.lifeCount = 2
	# OnscreenText object to show Start and Finish game
	self.textObject = OnscreenText(text = 'Lets Go!!!', pos = (0, 0), scale = 0.1)
	
	# Post the instructions
	self.title = addTitle("TIME: 00:00")
	self.inst1 = addInstructions(0.06, "LIFE: "+ str(self.lifeCount))
	self.inst2 = addInstructions(0.12, "TOKEN: "+ str(self.tokensCount))
	
	self.startTime = globalClock.getFrameTime()

	# This is used to store which keys are currently pressed.
	self.keyMap = {"cam-left": 0, "cam-right": 0}
Beispiel #36
0
    def __init__(self):
        ShowBase.__init__(self)

        self.setBackgroundColor(0.0, 0.0, 0.0)
        self.disableMouse()

        self.camLens.setNearFar(1.0, 100.0)
        self.camLens.setFov(75.0)

        self.root = self.render.attachNewNode("Root")
        self.root.setPos(0.0, 0.0, 0.0)
        
        self.taskMgr.add(self.physicsTask, "physicsTask")
        self.taskMgr.add(self.egoUpdateTask, "egoUpdateTask")

        self.modelCube = loader.loadModel("cube.egg")

        self.cube = self.modelCube.copyTo(self.root)
        self.cube.setPos((0,0,0))

        physicsClient = p.connect(p.DIRECT)#or p.DIRECT for non-graphical version
        p.setAdditionalSearchPath(pybullet_data.getDataPath()) #optionally
        p.setGravity(0,0,-10)
        planeId = p.loadURDF("plane.urdf")
        cubeStartPos = [0,0,1]
        cubeStartOrientation = p.getQuaternionFromEuler([0,0,0])
        p.setAdditionalSearchPath(os.path.dirname(os.path.abspath(__file__))) #optionally
        self.boxId = p.loadURDF("car.urdf",cubeStartPos, cubeStartOrientation)

        p.enableJointForceTorqueSensor(self.boxId, 0)
        p.enableJointForceTorqueSensor(self.boxId, 1)

        p.changeDynamics(self.boxId, -1, lateralFriction=0.1)
        p.changeDynamics(self.boxId, 0, lateralFriction=0.1)
        p.changeDynamics(self.boxId, 1, lateralFriction=0.1)

        self.control_force = 0
        self.semi_force = 1

        inputState.watchWithModifiers("throttle", "w")
        inputState.watchWithModifiers("brake", "s")
        inputState.watchWithModifiers("exit", "escape")
        inputState.watchWithModifiers("oobe", "o")

        self.prev_control_force = 0
        self.control_alpha = 0.9999

        self.integrator = 0
Beispiel #37
0
 def generalMovement(self):
     # Keyboard
     self.tokenGroup.release()
     self.tokenGroup.addToken(inputState.watchWithModifiers('forward', 'w', inputSource=inputState.WASD))
     self.tokenGroup.addToken(inputState.watchWithModifiers('left', 'a', inputSource=inputState.WASD))
     self.tokenGroup.addToken(inputState.watchWithModifiers('reverse', 's', inputSource=inputState.WASD))
     self.tokenGroup.addToken(inputState.watchWithModifiers('right', 'd', inputSource=inputState.WASD))
     self.tokenGroup.addToken(inputState.watchWithModifiers('turnLeft', 'q', inputSource=inputState.QE))
     self.tokenGroup.addToken(inputState.watchWithModifiers('turnRight', 'e', inputSource=inputState.QE))
     self.tokenGroup.addToken(inputState.watchWithModifiers('space', 'space', inputSource=inputState.Keyboard))
     self.tokenGroup.addToken(inputState.watch('ctrl', 'lcontrol_down', 'lcontrol-up', inputSource=inputState.Keyboard))
     self.isGrabMovement = False
Beispiel #38
0
    def enable(self):
        if self.isEnabled:
            assert self.notify.debug('already isEnabled')
            return
        
        self.isEnabled = 1

        
        #self.inputStateTokens = []
        ist = self.inputStateTokens
        ist.append(inputState.watch("run", 'runningEvent', "running-on", "running-off"))
        
        ist.append(inputState.watch("forward", "force-forward", "force-forward-stop"))
        
        
        ist.append(inputState.watchWithModifiers("reverse", "mouse4", inputSource=inputState.Mouse))
        
        if self.wantWASD:
            self.istWASD.append(inputState.watch("turnLeft", "mouse-look_left", "mouse-look_left-done"))
            self.istWASD.append(inputState.watch("turnLeft", "force-turnLeft", "force-turnLeft-stop"))

            self.istWASD.append(inputState.watch("turnRight", "mouse-look_right", "mouse-look_right-done"))
            self.istWASD.append(inputState.watch("turnRight", "force-turnRight", "force-turnRight-stop"))
            
            self.istWASD.append(inputState.watchWithModifiers("forward", "w", inputSource=inputState.WASD))
            self.istWASD.append(inputState.watchWithModifiers("reverse", "s", inputSource=inputState.WASD))
            self.setWASDTurn(self.__WASDTurn)
        else:
            self.istNormal.append(inputState.watchWithModifiers("forward", "arrow_up", inputSource=inputState.ArrowKeys))
            self.istNormal.append(inputState.watchWithModifiers("reverse", "arrow_down", inputSource=inputState.ArrowKeys))
            self.istNormal.append(inputState.watchWithModifiers("turnLeft", "arrow_left", inputSource=inputState.ArrowKeys))
            ist.append(inputState.watch("turnLeft", "mouse-look_left", "mouse-look_left-done"))
            ist.append(inputState.watch("turnLeft", "force-turnLeft", "force-turnLeft-stop"))
            
            self.istNormal.append(inputState.watchWithModifiers("turnRight", "arrow_right", inputSource=inputState.ArrowKeys))
            ist.append(inputState.watch("turnRight", "mouse-look_right", "mouse-look_right-done"))
            ist.append(inputState.watch("turnRight", "force-turnRight", "force-turnRight-stop"))

        
        if self.wantWASD:
            self.istWASD.append(inputState.watchWithModifiers("jump", "shift"))
        else:
            self.istNormal.append(inputState.watch("jump", "control", "control-up"))

        
        if self.currentControls:
            self.currentControls.enableAvatarControls()
    def setWASDTurn(self, turn):
        self.__WASDTurn = turn
        if not self.isEnabled:
            return
        keymap = settings.get('keymap', {})
        turnLeftWASDSet = inputState.isSet('turnLeft', inputSource=inputState.WASD)
        turnRightWASDSet = inputState.isSet('turnRight', inputSource=inputState.WASD)
        slideLeftWASDSet = inputState.isSet('slideLeft', inputSource=inputState.WASD)
        slideRightWASDSet = inputState.isSet('slideRight', inputSource=inputState.WASD)
        for token in self.WASDTurnTokens:
            token.release()

        if turn:
            self.WASDTurnTokens = (inputState.watchWithModifiers('turnLeft', keymap.get('MOVE_LEFT', base.MOVE_LEFT), inputSource=inputState.WASD), inputState.watchWithModifiers('turnRight', keymap.get('MOVE_RIGHT', base.MOVE_RIGHT), inputSource=inputState.WASD))
            inputState.set('turnLeft', slideLeftWASDSet, inputSource=inputState.WASD)
            inputState.set('turnRight', slideRightWASDSet, inputSource=inputState.WASD)
            inputState.set('slideLeft', False, inputSource=inputState.WASD)
            inputState.set('slideRight', False, inputSource=inputState.WASD)
        else:
            self.WASDTurnTokens = (inputState.watchWithModifiers('slideLeft', keymap.get('MOVE_LEFT', base.MOVE_LEFT), inputSource=inputState.WASD), inputState.watchWithModifiers('slideRight', keymap.get('MOVE_RIGHT', base.MOVE_RIGHT), inputSource=inputState.WASD))
            inputState.set('slideLeft', turnLeftWASDSet, inputSource=inputState.WASD)
            inputState.set('slideRight', turnRightWASDSet, inputSource=inputState.WASD)
            inputState.set('turnLeft', False, inputSource=inputState.WASD)
            inputState.set('turnRight', False, inputSource=inputState.WASD)
    def enable(self):
        if self.isEnabled:
            assert self.notify.debug("already isEnabled")
            return
        self.isEnabled = 1

        # Let's keep track of what we do on the inputState so that we can undo it later on.
        ist = self.inputStateTokens
        ist.append(inputState.watch("run", "runningEvent", "running-on", "running-off"))
        ist.append(inputState.watch("forward", "force-forward", "force-forward-stop"))
        ist.append(inputState.watchWithModifiers("reverse", "mouse4", inputSource=inputState.Mouse))
        if self.wantWASD:
            self.istWASD.append(inputState.watch("turnLeft", "mouse-look_left", "mouse-look_left-done"))
            self.istWASD.append(inputState.watch("turnLeft", "force-turnLeft", "force-turnLeft-stop"))
            self.istWASD.append(inputState.watch("turnRight", "mouse-look_right", "mouse-look_right-done"))
            self.istWASD.append(inputState.watch("turnRight", "force-turnRight", "force-turnRight-stop"))
            self.istWASD.append(inputState.watchWithModifiers("forward", "w", inputSource=inputState.WASD))
            self.istWASD.append(inputState.watchWithModifiers("reverse", "s", inputSource=inputState.WASD))
            self.setWASDTurn(self.__WASDTurn)
        else:
            self.istNormal.append(
                inputState.watchWithModifiers("forward", "arrow_up", inputSource=inputState.ArrowKeys)
            )
            self.istNormal.append(
                inputState.watchWithModifiers("reverse", "arrow_down", inputSource=inputState.ArrowKeys)
            )
            self.istNormal.append(
                inputState.watchWithModifiers("turnLeft", "arrow_left", inputSource=inputState.ArrowKeys)
            )
            ist.append(inputState.watch("turnLeft", "mouse-look_left", "mouse-look_left-done"))
            ist.append(inputState.watch("turnLeft", "force-turnLeft", "force-turnLeft-stop"))
            self.istNormal.append(
                inputState.watchWithModifiers("turnRight", "arrow_right", inputSource=inputState.ArrowKeys)
            )
            ist.append(inputState.watch("turnRight", "mouse-look_right", "mouse-look_right-done"))
            ist.append(inputState.watch("turnRight", "force-turnRight", "force-turnRight-stop"))

        # Jump controls
        if self.wantWASD:
            jumpKey = config.GetString("WASD-jump-key", "space")
            self.istWASD.append(inputState.watchWithModifiers("jump", jumpKey))
        else:
            self.istNormal.append(inputState.watch("jump", "control", "control-up"))
        if self.currentControls:
            self.currentControls.enableAvatarControls()
Beispiel #41
0
    def init_input(self):
        self.accept('escape', self.doExit)
        self.accept('r', self.doReset)
        self.accept('f1', self.toggleWireframe)
        self.accept('f2', self.toggleTexture)
        self.accept('f3', self.toggleDebug)
        self.accept('f5', self.doScreenshot)

        # 事件管理
        self.accept('space', self.doJump)
        self.accept('mouse1',self.doShoot)
        self.accept('control', self.doCrouch)
        self.accept('1',self.getCurrentPos)

        inputState.watchWithModifiers('back', 's')
        inputState.watchWithModifiers('forward', 'w')
        inputState.watchWithModifiers('turnLeft', 'a')
        inputState.watchWithModifiers('turnRight', 'd')
    def __init__(self):
        ShowBase.__init__(self)
        base.set_background_color(0.1, 0.1, 0.8, 1)
        base.set_frame_rate_meter(True)

        base.cam.set_pos(0, -10, 5)
        base.cam.look_at(0, 0, 0.2)

        # Light
        alight = AmbientLight('ambientLight')
        alight.set_color(LVector4(0.5, 0.5, 0.5, 1))
        alightNP = render.attach_new_node(alight)

        dlight = DirectionalLight('directionalLight')
        dlight.set_direction(LVector3(1, 1, -1))
        dlight.set_color(LVector4(0.7, 0.7, 0.7, 1))
        dlightNP = render.attach_new_node(dlight)

        render.clear_light()
        render.set_light(alightNP)
        render.set_light(dlightNP)

        # Input
        self.accept('escape', self.do_exit)
        self.accept('r', self.do_reset)
        self.accept('f1', base.toggle_wireframe)
        self.accept('f2', base.toggle_texture)
        self.accept('f3', self.toggle_debug)
        self.accept('f5', self.do_screenshot)

        inputState.watchWithModifiers('up', 'w')
        inputState.watchWithModifiers('left', 'a')
        inputState.watchWithModifiers('down', 's')
        inputState.watchWithModifiers('right', 'd')

        # Task
        taskMgr.add(self.update, 'updateWorld')

        # Physics
        self.setup()
    def enable(self):
        if self.isEnabled:
            return

        self.isEnabled = 1
        keymap = settings.get('keymap', {})
        # Keep track of what we do on the inputState so we can undo it later on
        self.inputStateTokens.extend((
            inputState.watch('run', 'runningEvent', 'running-on', 'running-off'),
            inputState.watch('forward', 'force-forward', 'force-forward-stop'),
        ))

        if self.wantWASD:
            self.istWASD.extend((
                inputState.watch('turnLeft', 'mouse-look_left', 'mouse-look_left-done'),
                inputState.watch('turnLeft', 'force-turnLeft', 'force-turnLeft-stop'),
                inputState.watch('turnRight', 'mouse-look_right', 'mouse-look_right-done'),
                inputState.watch('turnRight', 'force-turnRight', 'force-turnRight-stop'),
                inputState.watchWithModifiers('forward', keymap.get('MOVE_UP', base.MOVE_UP), inputSource=inputState.WASD),
                inputState.watchWithModifiers('reverse', keymap.get('MOVE_DOWN', base.MOVE_DOWN), inputSource=inputState.WASD),
                inputState.watchWithModifiers('jump', keymap.get('JUMP', base.JUMP))
            ))

            self.setWASDTurn(True)

        else:
            self.istNormal.extend((
                inputState.watchWithModifiers('forward', 'arrow_up', inputSource=inputState.ArrowKeys),
                inputState.watchWithModifiers('reverse', 'arrow_down', inputSource=inputState.ArrowKeys),
                inputState.watchWithModifiers('turnLeft', 'arrow_left', inputSource=inputState.ArrowKeys),
                inputState.watchWithModifiers('turnRight', 'arrow_right', inputSource=inputState.ArrowKeys),
                inputState.watch('jump', 'control', 'control-up')
            ))
            
            self.istNormal.extend((
                inputState.watch('turnLeft', 'mouse-look_left', 'mouse-look_left-done'),
                inputState.watch('turnLeft', 'force-turnLeft', 'force-turnLeft-stop'),
                inputState.watch('turnRight', 'mouse-look_right', 'mouse-look_right-done'),
                inputState.watch('turnRight', 'force-turnRight', 'force-turnRight-stop')
            ))
            

        if self.currentControls:
            self.currentControls.enableAvatarControls()
  def __init__(self):
    base.setBackgroundColor(0.1, 0.1, 0.8, 1)
    base.setFrameRateMeter(True)

    base.cam.setPos(0, -10, 5)
    base.cam.lookAt(0, 0, 0.2)

    # Light
    alight = AmbientLight('ambientLight')
    alight.setColor(Vec4(0.5, 0.5, 0.5, 1))
    alightNP = render.attachNewNode(alight)

    dlight = DirectionalLight('directionalLight')
    dlight.setDirection(Vec3(1, 1, -1))
    dlight.setColor(Vec4(0.7, 0.7, 0.7, 1))
    dlightNP = render.attachNewNode(dlight)

    render.clearLight()
    render.setLight(alightNP)
    render.setLight(dlightNP)

    # Input
    self.accept('escape', self.doExit)
    self.accept('r', self.doReset)
    self.accept('f1', self.toggleWireframe)
    self.accept('f2', self.toggleTexture)
    self.accept('f3', self.toggleDebug)
    self.accept('f5', self.doScreenshot)

    inputState.watchWithModifiers('up', 'w')
    inputState.watchWithModifiers('left', 'a')
    inputState.watchWithModifiers('down', 's')
    inputState.watchWithModifiers('right', 'd')

    # Task
    taskMgr.add(self.update, 'updateWorld')

    # Physics
    self.setup()
Beispiel #45
0
    def __init__(self):
        base.setBackgroundColor(0.1, 0.1, 0.8, 1)
        base.setFrameRateMeter(True)

        base.cam.setPos(0, -10, 5)
        base.cam.lookAt(0, 0, 0.2)

        # Light
        alight = AmbientLight('ambientLight')
        alight.setColor(Vec4(0.5, 0.5, 0.5, 1))
        alightNP = render.attachNewNode(alight)

        dlight = DirectionalLight('directionalLight')
        dlight.setDirection(Vec3(1, 1, -1))
        dlight.setColor(Vec4(0.7, 0.7, 0.7, 1))
        dlightNP = render.attachNewNode(dlight)

        render.clearLight()
        render.setLight(alightNP)
        render.setLight(dlightNP)

        # Input
        self.accept('escape', self.doExit)
        self.accept('r', self.doReset)
        self.accept('f1', self.toggleWireframe)
        self.accept('f2', self.toggleTexture)
        self.accept('f3', self.toggleDebug)
        self.accept('f5', self.doScreenshot)

        inputState.watchWithModifiers('up', 'w')
        inputState.watchWithModifiers('left', 'a')
        inputState.watchWithModifiers('down', 's')
        inputState.watchWithModifiers('right', 'd')

        # Task
        taskMgr.add(self.update, 'updateWorld')

        # Physics
        self.setup()
Beispiel #46
0
    def setWASDTurn(self, turn):
        turnLeftSet = inputState.isSet("turnLeft")
        turnRightSet = inputState.isSet("turnRight")
        slideLeftSet = inputState.isSet("slideLeft")
        slideRightSet = inputState.isSet("slideRight")

        for token in self.WASDTurnTokens:
            token.release()
        if turn:
            self.WASDTurnTokens = (
                inputState.watchWithModifiers("turnLeft", "a", inputSource=inputState.WASD),
                inputState.watchWithModifiers("turnRight", "d", inputSource=inputState.WASD),
                inputState.watchWithModifiers("slideLeft", "q", inputSource=inputState.WASD),
                inputState.watchWithModifiers("slideRight", "e", inputSource=inputState.WASD),
                )
        else:
            self.WASDTurnTokens = (
                inputState.watchWithModifiers("turnLeft", "q", inputSource=inputState.WASD),
                inputState.watchWithModifiers("turnRight", "e", inputSource=inputState.WASD),
                inputState.watchWithModifiers("slideLeft", "a", inputSource=inputState.WASD),
                inputState.watchWithModifiers("slideRight", "d", inputSource=inputState.WASD),
                )

        """
    def activateKeys(self):
        inputState.watchWithModifiers('boostUp', '1-up')
        inputState.watchWithModifiers('forward', 'w')
        inputState.watchWithModifiers('left', 'a')
        inputState.watchWithModifiers('brake', 's')
        inputState.watchWithModifiers('right', 'd')
        inputState.watchWithModifiers('turnLeft', 'q')
        inputState.watchWithModifiers('turnRight', 'e')

        self.world.setGravity(Vec3(0, 0, -9.81))
Beispiel #48
0
 def __init__(self, _game):
     """InputHandler INIT"""
     
     # Game
     self.game = _game
     
     # Keyboard
     inputState.watchWithModifiers('forward', 'w')
     inputState.watchWithModifiers('left', 'a')
     inputState.watchWithModifiers('reverse', 's')
     inputState.watchWithModifiers('right', 'd')
     inputState.watchWithModifiers('turnLeft', 'q')
     inputState.watchWithModifiers('turnRight', 'e')
     inputState.watchWithModifiers('space', 'space')
     #inputState.watchWithModifiers('ctrl', 'lcontrol_down')
     
     # App exit temp
     base.accept("escape", sys.exit)
     
     # mouse
     self.winXhalf = base.win.getXSize()/2
     self.winYhalf = base.win.getYSize()/2
     
     # Should move the camera stuff to the baseCamera.py
     base.camera.reparentTo(self.game.meotech.engine.GameObjects["player"].bulletBody)
     base.camLens.setFov(90)
     base.camLens.setNear(0.5)
     
     
     self.mouseSpeedX = 5
     self.mouseSpeedY = 0.2
     self.camP = 10
Beispiel #49
0
 def __init__(self):
     base.setBackgroundColor(0.1, 0.1, 0.8, 1)
     base.setFrameRateMeter(True)
     
     base.cam.setPos(0, -20, 4)
     base.cam.lookAt(0, 0, 0)
     
     # Input
     self.accept('escape', self.doExit)
     self.accept('space', self.doJump)
     self.accept('c', self.doCrouch)
     self.accept('c-up', self.stopCrouch)
     
     self.accept('control', self.startFly)
     self.accept('control-up', self.stopFly)
     
     inputState.watchWithModifiers('forward', 'w')
     inputState.watchWithModifiers('left', 'a')
     inputState.watchWithModifiers('reverse', 's')
     inputState.watchWithModifiers('right', 'd')
     inputState.watchWithModifiers('turnLeft', 'q')
     inputState.watchWithModifiers('turnRight', 'e')
     
     inputState.watchWithModifiers('run', 'shift')
     
     inputState.watchWithModifiers('flyUp', 'r')
     inputState.watchWithModifiers('flyDown', 'f')
     
     # Task
     taskMgr.add(self.update, 'updateWorld')
     
     # Physics
     self.setup()
Beispiel #50
0
    def __init__(self):
        ShowBase.__init__(self)
        # base.setBackgroundColor(0.0, 0.0, 0.0, 1)
        # base.setFrameRateMeter(True)

        # 渲染天空盒,添加光照
        sha = Shader.load(
            Shader.SLGLSL, "shaders/skybox_vert.glsl", "shaders/skybox_frag.glsl")

        self.skyTex = loader.loadCubeMap("textures/skybox/Highnoon_#.jpg")

        self.ambientLight = render.attachNewNode(AmbientLight("ambientLight"))
        self.ambientLight.node().setColor((0.2, 0.2, 0.2, 1.0))

        self.sun = render.attachNewNode(DirectionalLight("sun"))
        self.sun.node().setColor((0.8, 0.8, 1.0, 1.0))
        self.sun.node().setDirection(LVector3(1, -1, -3))

        render.setLight(self.ambientLight)
        render.setLight(self.sun)

        self.skybox = self.loader.loadModel("models/skybox")
        self.skybox.reparentTo(self.render)
        self.skybox.setShader(sha)
        self.skybox.setShaderInput("skybox", self.skyTex)
        self.skybox.setAttrib(DepthTestAttrib.make(RenderAttrib.MLessEqual))

        # 处理输入
        self.accept('escape', self.doExit)
        self.accept('r', self.doReset)
        self.accept('f1', self.toggleWireframe)
        self.accept('f2', self.toggleTexture)
        self.accept('f3', self.toggleDebug)

        self.tagOfForward = 0
        self.tagOfReverse = 0
        self.tagOfLeft = 0
        self.tagOfRight = 0
        self.count = 0

        #### 各种tag参数 ####

        # 是否在零摩擦区域内
        self.tagOfZeroRub = 0
        # 用来判断零摩擦运动是否结束
        self.countForCheck = 0  # 用于判断停止的时间间隔(mod 5)
        self.posXBefore = 0
        self.posYBefore = 0
        self.posXNow = 0
        self.posYNow = 0
        #
        self.tagOfSlabStone = 1
        self.tagOfOut = 1
        #### 各种tag参数 ####

        # 接受输入
        inputState.watchWithModifiers('forward', 'w')
        inputState.watchWithModifiers('left', 'a')
        inputState.watchWithModifiers('reverse', 's')
        inputState.watchWithModifiers('right', 'd')
        inputState.watchWithModifiers('transfer', 'e')
        inputState.watchWithModifiers('slabstone', 'z')

        # Task
        taskMgr.add(self.update, 'updateWorld')

        # 初始化
        self.setup()
    def enable(self):
        assert self.notify.debugCall(id(self))

        if self.isEnabled:
            assert self.notify.debug('already isEnabled')
            return
        
        self.isEnabled = 1

        # keep track of what we do on the inputState so we can undo it later on
        #self.inputStateTokens = []
        ist = self.inputStateTokens
        ist.append(inputState.watch("run", 'runningEvent', "running-on", "running-off"))
        
        ist.append(inputState.watchWithModifiers("forward", "arrow_up", inputSource=inputState.ArrowKeys))
        ist.append(inputState.watch("forward", "force-forward", "force-forward-stop"))
        
        ist.append(inputState.watchWithModifiers("reverse", "arrow_down", inputSource=inputState.ArrowKeys))
        ist.append(inputState.watchWithModifiers("reverse", "mouse4", inputSource=inputState.Mouse))
        
        if self.wantWASD:
            ist.append(inputState.watchWithModifiers("turnLeft", "arrow_left", inputSource=inputState.ArrowKeys))
            ist.append(inputState.watch("turnLeft", "mouse-look_left", "mouse-look_left-done"))
            ist.append(inputState.watch("turnLeft", "force-turnLeft", "force-turnLeft-stop"))
            
            ist.append(inputState.watchWithModifiers("turnRight", "arrow_right", inputSource=inputState.ArrowKeys))
            ist.append(inputState.watch("turnRight", "mouse-look_right", "mouse-look_right-done"))
            ist.append(inputState.watch("turnRight", "force-turnRight", "force-turnRight-stop"))

            ist.append(inputState.watchWithModifiers("forward", "w", inputSource=inputState.WASD))
            ist.append(inputState.watchWithModifiers("reverse", "s", inputSource=inputState.WASD))

            ist.append(inputState.watchWithModifiers("slideLeft", "q", inputSource=inputState.QE))
            ist.append(inputState.watchWithModifiers("slideRight", "e", inputSource=inputState.QE))

            self.setWASDTurn(self.__WASDTurn)
        else:
            ist.append(inputState.watchWithModifiers("turnLeft", "arrow_left", inputSource=inputState.ArrowKeys))
            ist.append(inputState.watch("turnLeft", "mouse-look_left", "mouse-look_left-done"))
            ist.append(inputState.watch("turnLeft", "force-turnLeft", "force-turnLeft-stop"))
            
            ist.append(inputState.watchWithModifiers("turnRight", "arrow_right", inputSource=inputState.ArrowKeys))
            ist.append(inputState.watch("turnRight", "mouse-look_right", "mouse-look_right-done"))
            ist.append(inputState.watch("turnRight", "force-turnRight", "force-turnRight-stop"))

        # Jump controls
        if self.wantWASD:
            ist.append(inputState.watchWithModifiers("jump", "space"))
        else:
            ist.append(inputState.watch("jump", "control", "control-up"))
        
        if self.currentControls:
            self.currentControls.enableAvatarControls()
Beispiel #52
0
    def __init__(self, _game):
        
        self.game = _game
        
        # Reset Player
        self.accept('r', self.msgPlayerReset)
        
        ## MOVEMENT INPUTS ## 
        inputState.watchWithModifiers('up', 'w')
        inputState.watchWithModifiers('down', 's')
        inputState.watchWithModifiers('left', 'a')
        inputState.watchWithModifiers('right', 'd')
        inputState.watchWithModifiers('space', 'space')
        inputState.watchWithModifiers('control', 'control')
        inputState.watchWithModifiers('boost', 'lshift')

        # Camera
        self.accept('c', self.evtGetCameraPos)

        # Mouse
        #self.accept("mouse1-up", self.setMouseHold, [False])
        self.accept("mouse1", self.evtLeftClick)
        self.accept("mouse3", self.evtRightClick, [True])
        self.accept("mouse3-up", self.evtRightClick, [False])
        #self.accept("mouse1", self.setMouseHold, [True])
        self.mouseBtnUp = False
        # Wheel
        self.accept("wheel_up", self.evtMouseWheel, [True])
        self.accept("wheel_down", self.evtMouseWheel, [False])
        self.accept("1", self.evtPlaceDevice)
        

        ## Physic Objects list
        self.physicObjects = None
        self.physicSensors = None

        # should populate this automatically
        self.avoidObjects = []

        # Move Check
        self.rightMDown = False
Beispiel #53
0
    def __init__(self):
        base.setBackgroundColor(0.1, 0.1, 0.8, 1)
        base.setFrameRateMeter(True)

        base.cam.setPos(0, -20, 4)
        base.cam.lookAt(0, 0, 0)

        # Light
        alight = AmbientLight("ambientLight")
        alight.setColor(Vec4(0.5, 0.5, 0.5, 1))
        alightNP = render.attachNewNode(alight)

        dlight = DirectionalLight("directionalLight")
        dlight.setDirection(Vec3(1, 1, -1))
        dlight.setColor(Vec4(0.7, 0.7, 0.7, 1))
        dlightNP = render.attachNewNode(dlight)

        render.clearLight()
        render.setLight(alightNP)
        render.setLight(dlightNP)

        # Input
        self.accept("escape", self.doExit)
        self.accept("r", self.doReset)
        self.accept("f1", self.toggleWireframe)
        self.accept("f2", self.toggleTexture)
        self.accept("f3", self.toggleDebug)
        self.accept("f5", self.doScreenshot)

        # self.accept('space', self.doJump)
        # self.accept('c', self.doCrouch)

        inputState.watchWithModifiers("forward", "w")
        inputState.watchWithModifiers("left", "a")
        inputState.watchWithModifiers("reverse", "s")
        inputState.watchWithModifiers("right", "d")
        inputState.watchWithModifiers("turnLeft", "q")
        inputState.watchWithModifiers("turnRight", "e")

        # Task
        taskMgr.add(self.update, "updateWorld")

        # Physics
        self.setup()
  def __init__(self):
    self.imageObject = OnscreenImage(image = 'models/splashscreen.png', pos=(0,0,0), scale=(1.4,1,1))
    preloader = Preloader()
    self.musicLoop = loader.loadSfx("music/loop/EndlessBliss.mp3")
    self.snowmansHit = loader.loadSfx("music/effects/snowball_hit.wav")
    self.candleThrow = loader.loadSfx("music/effects/snowball_throw.wav")
    self.presentHit = loader.loadSfx("music/effects/present_hit.wav")
    self.loseSound = loader.loadSfx("music/effects/Failure-WahWah.mp3")
    self.winSound = loader.loadSfx("music/effects/Ta Da-SoundBible.com-1884170640.mp3")
    self.nextLevelSound = loader.loadSfx("music/effects/button-17.wav")
    self.loseScreen = OnscreenImage(image = 'models/losescreen.png', pos=(0,0,0), scale=(1.4,1,1))
    self.loseScreen.hide()
    self.winScreen = OnscreenImage(image = 'models/winscreen.png', pos=(0,0,0), scale=(1.4,1,1))
    self.winScreen.hide()
    self.helpScreen = OnscreenImage(image = 'models/helpscreen.jpg', pos=(0,0,0.1), scale=(1,1,0.8))
    self.helpScreen.hide()
    self.backBtn = DirectButton(text=("Back"), scale = 0.1,  pos = (0,0,-0.8), command = self.doBack)
    self.retryBtn = DirectButton(text="Retry", scale = 0.1, pos = (0,0,0), command = self.doRetry)
    self.retryBtn.hide()
    self.menuBtn = DirectButton(text="Main Menu", scale = 0.1, pos = (0,0,0), command = self.doBack)
    self.menuBtn.hide()
    self.backBtn.hide()
    base.setBackgroundColor(0.1, 0.1, 0.8, 1)
    #base.setFrameRateMeter(True)
    
    # Position the camera
    base.cam.setPos(0, 30, 20)
    base.cam.lookAt(0, 30, 0)

    # Light
    alight = AmbientLight('ambientLight')
    alight.setColor(Vec4(0.5, 0.5, 0.5, 1))
    alightNP = render.attachNewNode(alight)

    dlight = DirectionalLight('directionalLight')
    dlight.setDirection(Vec3(1, 1, -1))
    dlight.setColor(Vec4(0.7, 0.7, 0.7, 1))
    dlightNP = render.attachNewNode(dlight)

    render.clearLight()
    render.setLight(alightNP)
    render.setLight(dlightNP)

    # Input
    self.accept('escape', self.doExit)
    self.accept('r', self.doReset)
    self.accept('f1', self.toggleWireframe)
    self.accept('f2', self.toggleTexture)
    self.accept('f3', self.toggleDebug)
    self.accept('f5', self.doScreenshot)
    self.accept('f', self.doShoot, [True])
    self.accept('p', self.doPause)

    inputState.watchWithModifiers('forward', 'w')
    inputState.watchWithModifiers('left', 'a')
    inputState.watchWithModifiers('reverse', 's')
    inputState.watchWithModifiers('right', 'd')
    inputState.watchWithModifiers('turnLeft', 'q')
    inputState.watchWithModifiers('turnRight', 'e')
    
    inputState.watchWithModifiers('moveLineUp', 'i')
    inputState.watchWithModifiers('moveLineDown','k')
    inputState.watchWithModifiers('moveLineRight','l')
    inputState.watchWithModifiers('moveLineLeft','j')
    
    self.font = loader.loadFont('models/SHOWG.TTF')
    self.font.setPixelsPerUnit(60)
    self.attemptText = OnscreenText(text='', pos = (0.9,0.8), scale = 0.07, font = self.font)
    self.levelText = OnscreenText(text='', pos=(-0.9,0.9), scale = 0.07, font = self.font )
    self.scoreText = OnscreenText(text='', pos = (0.9,0.9), scale = 0.07, font = self.font)
    self.text = OnscreenText(text = '', 
                              pos = (0, 0), scale = 0.07, font = self.font)
    self.pauseText = OnscreenText(text='P: Pause', pos= (0.9,0.7), scale = 0.05, font = self.font)
    self.pauseText.hide()
    # Task
    taskMgr.add(self.update, 'updateWorld')

    # Physics
    self.setup()
Beispiel #55
0
    def __init__(self):

        self.loading = LoadingScreen()

        base.setFrameRateMeter(True)
        #input states
        inputState.watchWithModifiers('forward', 'w')
        inputState.watchWithModifiers('left', 'a')
        inputState.watchWithModifiers('brake', 's')
        inputState.watchWithModifiers('right', 'd')
        inputState.watchWithModifiers('turnLeft', 'q')
        inputState.watchWithModifiers('turnRight', 'e')

        self.keyMap = {"hello": 0, "left": 0, "right": 0, "forward": 0, "backward": 0, "cam-left": 0, "cam-right": 0,
                       "chat0": 0, "powerup": 0, "reset": 0}
        base.win.setClearColor(Vec4(0, 0, 0, 1))

        # Network Setup
        self.cManager = ConnectionManager(self)
        self.startConnection()
        #self.cManager.sendRequest(Constants.CMSG_LOGIN, ["username", "password"])
        # chat box
        # self.chatbox = Chat(self.cManager, self)


        # Set up the environment
        #
        self.initializeBulletWorld(False)

        #self.createEnvironment()
        Track(self.bulletWorld)

        # Create the main character, Ralph

        self.mainCharRef = Vehicle(self.bulletWorld, (0, 25, 16, 0, 0, 0), self.login)
        #self.mainCharRef = Character(self, self.bulletWorld, 0, "Me")
        self.mainChar = self.mainCharRef.chassisNP
        #self.mainChar.setPos(0, 25, 16)

#         self.characters.append(self.mainCharRef)

#         self.TestChar = Character(self, self.bulletWorld, 0, "test")
#         self.TestChar.actor.setPos(0, 0, 0)

        self.previousPos = self.mainChar.getPos()
        taskMgr.doMethodLater(.1, self.updateMove, 'updateMove')

        # Set Dashboard
        self.dashboard = Dashboard(self.mainCharRef, taskMgr)


        self.floater = NodePath(PandaNode("floater"))
        self.floater.reparentTo(render)

        # Accept the control keys for movement and rotation
        self.accept("escape", self.doExit)
        self.accept("a", self.setKey, ["left", 1])
        self.accept("d", self.setKey, ["right", 1])
        self.accept("w", self.setKey, ["forward", 1])
        self.accept("s", self.setKey, ["backward", 1])
        self.accept("arrow_left", self.setKey, ["cam-left", 1])
        self.accept("arrow_right", self.setKey, ["cam-right", 1])
        self.accept("a-up", self.setKey, ["left", 0])
        self.accept("d-up", self.setKey, ["right", 0])
        self.accept("w-up", self.setKey, ["forward", 0])
        self.accept("s-up", self.setKey, ["backward", 0])
        self.accept("arrow_left-up", self.setKey, ["cam-left", 0])
        self.accept("arrow_right-up", self.setKey, ["cam-right", 0])
        self.accept("h", self.setKey, ["hello", 1])
        self.accept("h-up", self.setKey, ["hello", 0])
        self.accept("0", self.setKey, ["chat0", 1])
        self.accept("0-up", self.setKey, ["chat0", 0])
        self.accept("1", self.setKey,["powerup", 1])
        self.accept("1-up", self.setKey,["powerup", 0])
        self.accept("2", self.setKey,["powerup", 2])
        self.accept("2-up", self.setKey,["powerup", 0])
        self.accept("3", self.setKey,["powerup", 3])
        self.accept("3-up", self.setKey,["powerup", 0])
        self.accept("r", self.doReset)
        self.accept("p", self.setTime)

        #self.loading.finish()
        #taskMgr.doMethodLater(5, self.move, "moveTask")

        # Game state variables
        self.isMoving = False

        # Sky Dome
        self.sky = SkyDome()

        # Set up the camera
        self.camera = Camera(self.mainChar, self.bulletWorld)
        #base.disableMouse()
        #base.camera.setPos(self.mainChar.getX(), self.mainChar.getY() + 10, self.mainChar.getZ() + 2)

        # Create some lighting
        ambientLight = AmbientLight("ambientLight")
        ambientLight.setColor(Vec4(.3, .3, .3, 1))
        directionalLight = DirectionalLight("directionalLight")
        directionalLight.setDirection(Vec3(-5, -5, -5))
        directionalLight.setColor(Vec4(1, 1, 1, 1))
        directionalLight.setSpecularColor(Vec4(1, 1, 1, 1))
        directionalLight2 = DirectionalLight("directionalLight2")
        directionalLight2.setDirection(Vec3(5, 5, -5))
        directionalLight2.setColor(Vec4(1, 1, 1, 1))
        directionalLight2.setSpecularColor(Vec4(1, 1, 1, 1))
        render.setLight(render.attachNewNode(ambientLight))
        render.setLight(render.attachNewNode(directionalLight))
        render.setLight(render.attachNewNode(directionalLight2))

        # Game initialisation
        self.gameState = self.gameStateDict["Login"]
        self.responseValue = -1

        self.cManager.sendRequest(Constants.CMSG_LOGIN,[self.login,"1234"])
        taskMgr.add(self.enterGame,"EnterGame")

    # Create Powerups
        self.createPowerups()
        taskMgr.add(self.powerups.checkPowerPickup, "checkPowerupTask")
        taskMgr.add(self.usePowerup, "usePowerUp")
Beispiel #56
0
	def __init__(self):
		ShowBase.__init__(self)
		
		#Setup
		scene = BulletWorld()
		scene.setGravity(Vec3(0, 0, -9.81))
		base.setBackgroundColor(0.6,0.9,0.9)
		fog = Fog("The Fog")
		fog.setColor(0.9,0.9,1.0)
		fog.setExpDensity(0.003)
		render.setFog(fog)
		#Lighting
		
		#Sun light
		sun = DirectionalLight("The Sun")
		sun_np = render.attachNewNode(sun)
		sun_np.setHpr(0,-60,0)
		render.setLight(sun_np)
		
		#Ambient light
		amb = AmbientLight("The Ambient Light")
		amb.setColor(VBase4(0.39,0.39,0.39, 1))
		amb_np = render.attachNewNode(amb)
		render.setLight(amb_np)
		
		#Variables
		self.gear = 0
		
		self.start = 0
		
		self.Pbrake = 0
		
		self.terrain_var = 1
		
		self.time = 0
		
		self.headlight_var = 0
		
		self.RPM = 0
		
		self.clutch = 0
		
		self.carmaxspeed = 100 #KPH
		
		self.carmaxreversespeed = -40 #KPH
		
		self.steering = 0
		
		
		#Functions
		def V1():
			camera.setPos(0.25,-1.2,0.5)
			camera.setHpr(0,-13,0)
			
		def V2():
			camera.setPos(0,-15,3)
			camera.setHpr(0,-10,0)
			
		def V3():
			camera.setPos(0,0,9)
			camera.setHpr(0,-90,0)
			
		def up():
			self.gear = self.gear -1
			if self.gear < -1:
				self.gear = -1
				
		def down():
			self.gear = self.gear +1
			if self.gear > 1:
				self.gear = 1
				
		def start_function():
			self.start = 1
			self.start_sound.play()
			self.engine_idle_sound.play()
			self.RPM = 1000
			
		def stop_function():
			self.start = 0
			self.engine_idle_sound.stop()
				
		def parkingbrake():
			self.Pbrake = (self.Pbrake + 1) % 2
			
		def rotate():
			Car_np.setHpr(0, 0, 0)
			
		def horn():
			self.horn_sound.play()
			
		def set_time():
			if self.time == -1:
				sun.setColor(VBase4(0.4, 0.3, 0.3, 1))
				base.setBackgroundColor(0.8,0.7,0.7)
			if self.time == 0:
				sun.setColor(VBase4(0.7, 0.7, 0.7, 1))
				base.setBackgroundColor(0.6,0.9,0.9)
			if self.time == 1:
				sun.setColor(VBase4(0.2, 0.2, 0.2, 1))
				base.setBackgroundColor(0.55,0.5,0.5)
			if self.time == 2:
				sun.setColor(VBase4(0.02, 0.02, 0.05, 1))
				base.setBackgroundColor(0.3,0.3,0.3)
				
			if self.time == -2:
				self.time = -1
			if self.time == 3:
				self.time = 2
			
		def time_forward():
			self.time = self.time + 1
			
		def time_backward():
			self.time = self.time -1
			
		def set_terrain():
			if self.terrain_var == 1:
				self.ground_model.setTexture(self.ground_tex, 1)
				self.ground_model.setScale(3)
			if self.terrain_var == 2:
				self.ground_model.setTexture(self.ground_tex2, 1)
				self.ground_model.setScale(3)
			if self.terrain_var == 3:
				self.ground_model.setTexture(self.ground_tex3, 1)
				self.ground_model.setScale(4)
				
			if self.terrain_var == 4:
				self.terrain_var = 1
			if self.terrain_var == 0:
				self.terrain_var = 3
			
		def next_terrain():
			self.terrain_var = self.terrain_var + 1
			
		def previous_terrain():
			self.terrain_var = self.terrain_var - 1
			
		def show_menu():
			self.menu_win.show()
			self.a1.show()
			self.a2.show()
			self.a3.show()
			self.a4.show()
			self.t1.show()
			self.t2.show()
			self.ok.show()
			self.exit_button.show()
			
		def hide_menu():
			self.menu_win.hide()
			self.a1.hide()
			self.a2.hide()
			self.a3.hide()
			self.a4.hide()
			self.ok.hide()
			self.t1.hide()
			self.t2.hide()
			self.exit_button.hide()
		
		def Menu():
			self.menu_win = OnscreenImage(image = "Textures/menu.png", pos = (0.9,0,0), scale = (0.5))
			self.menu_win.setTransparency(TransparencyAttrib.MAlpha)
			
			#The Arrow Buttons
			self.a1 = DirectButton(text = "<", scale = 0.2, pos = (0.55,0,0.25), command = previous_terrain)
			self.a2 = DirectButton(text = ">", scale = 0.2, pos = (1.15,0,0.25), command = next_terrain)
			self.a3 = DirectButton(text = "<", scale = 0.2, pos = (0.55,0,0.0), command = time_backward)
			self.a4 = DirectButton(text = ">", scale = 0.2, pos = (1.15,0,0.0), command = time_forward)
			
			#The Text
			self.t1 = OnscreenText(text = "Terrain", pos = (0.85,0.25,0), scale = 0.1, fg = (0.4,0.4,0.5,1))
			self.t2 = OnscreenText(text = "Time", pos = (0.85,0,0), scale = 0.1, fg = (0.4,0.4,0.5,1))
			
			#The Buttons
			self.ok = DirectButton(text = "Okay", scale = 0.11, pos = (0.87,0,-0.25), command = hide_menu)
			self.exit_button = DirectButton(text = "Quit", scale = 0.11, pos = (0.87,0,-0.42), command = sys.exit)
			
		Menu()
		
		
		def take_screenshot():
			base.screenshot("Screenshot")
			
		def set_headlights():
			if self.headlight_var == 1:
				Headlight1.setColor(VBase4(9.0,8.9,8.9,1))
				Headlight2.setColor(VBase4(9.0,8.9,8.9,1))
			if self.headlight_var == 0:
				Headlight1.setColor(VBase4(0,0,0,1))
				Headlight2.setColor(VBase4(0,0,0,1))
			
		def headlights():
			self.headlight_var = (self.headlight_var + 1) % 2
			
		def update_rpm():
			
			#Simulate RPM
			if self.start == 1:
				if self.gear == 0:
					self.RPM = self.RPM - self.RPM / 400
				else:
					self.RPM = self.RPM + self.carspeed / 9
					self.RPM = self.RPM - self.RPM / 200
			
			#Reset RPM to 0 when engine is off
			if self.start == 0:
				if self.RPM > 0.0:
					self.RPM = self.RPM - 40
				if self.RPM < 10:
					self.RPM = 0.0
								
			#Idle RPM power
			if self.start == 1:
				if self.RPM < 650:
					self.RPM = self.RPM + 4
				if self.RPM < 600:
					self.clutch = 1
				else:
					self.clutch = 0
					
			#RPM limit		
			if self.RPM > 6000:
				self.RPM = 6000
				

		#Controls 
		inputState.watchWithModifiers("F", "arrow_up")
		inputState.watchWithModifiers("B", "arrow_down")
		inputState.watchWithModifiers("L", "arrow_left")
		inputState.watchWithModifiers("R", "arrow_right")
		
		do = DirectObject()
		
		do.accept("escape", show_menu)
		do.accept("1", V1)
		do.accept("2", V2)
		do.accept("3", V3)
		do.accept("page_up", up)
		do.accept("page_down", down)
		do.accept("x-repeat", start_function)
		do.accept("x", stop_function)
		do.accept("p", parkingbrake)
		do.accept("backspace", rotate)
		do.accept("enter", horn)
		do.accept("f12", take_screenshot)
		do.accept("h", headlights)
		
		#The ground
		self.ground = BulletPlaneShape(Vec3(0, 0, 1,), 1)
		self.ground_node = BulletRigidBodyNode("The ground")
		self.ground_node.addShape(self.ground)
		self.ground_np = render.attachNewNode(self.ground_node)
		self.ground_np.setPos(0, 0, -2)
		scene.attachRigidBody(self.ground_node)
		
		self.ground_model = loader.loadModel("Models/plane.egg")
		self.ground_model.reparentTo(render)
		self.ground_model.setPos(0,0,-1)
		self.ground_model.setScale(3)
		self.ground_tex = loader.loadTexture("Textures/ground.png")
		self.ground_tex2 = loader.loadTexture("Textures/ground2.png")
		self.ground_tex3 = loader.loadTexture("Textures/ground3.png")
		self.ground_model.setTexture(self.ground_tex, 1)
		
		#The car
		Car_shape = BulletBoxShape(Vec3(1, 2.0, 1.0))
		Car_node = BulletRigidBodyNode("The Car")
		Car_node.setMass(1200.0)
		Car_node.addShape(Car_shape)
		Car_np = render.attachNewNode(Car_node)
		Car_np.setPos(0,0,3)
		Car_np.setHpr(0,0,0)
		Car_np.node().setDeactivationEnabled(False)
		scene.attachRigidBody(Car_node)
		
		Car_model = loader.loadModel("Models/Car.egg")
		Car_model.reparentTo(Car_np)
		Car_tex = loader.loadTexture("Textures/Car1.png")
		Car_model.setTexture(Car_tex, 1)
		
		self.Car_sim = BulletVehicle(scene, Car_np.node())
		self.Car_sim.setCoordinateSystem(ZUp)
		scene.attachVehicle(self.Car_sim)
		
		#The inside of the car
		Car_int = loader.loadModel("Models/inside.egg")
		Car_int.reparentTo(Car_np)
		Car_int_tex = loader.loadTexture("Textures/inside.png")
		Car_int.setTexture(Car_int_tex, 1)
		Car_int.setTransparency(TransparencyAttrib.MAlpha)
		
		#The steering wheel
		Sw = loader.loadModel("Models/Steering wheel.egg")
		Sw.reparentTo(Car_np)
		Sw.setPos(0.25,0,-0.025)
		
		#The first headlight
		Headlight1 = Spotlight("Headlight1")
		lens = PerspectiveLens()
		lens.setFov(180)
		Headlight1.setLens(lens)
		Headlight1np = render.attachNewNode(Headlight1)
		Headlight1np.reparentTo(Car_np)
		Headlight1np.setPos(-0.8,2.5,-0.5)
		Headlight1np.setP(-15)
		render.setLight(Headlight1np)
		
		#The second headlight
		Headlight2 = Spotlight("Headlight2")
		Headlight2.setLens(lens)
		Headlight2np = render.attachNewNode(Headlight2)
		Headlight2np.reparentTo(Car_np)
		Headlight2np.setPos(0.8,2.5,-0.5)
		Headlight2np.setP(-15)
		render.setLight(Headlight2np)
		
		#Sounds
		self.horn_sound = loader.loadSfx("Sounds/horn.ogg")
		self.start_sound = loader.loadSfx("Sounds/enginestart.ogg")
		self.engine_idle_sound = loader.loadSfx("Sounds/engineidle.ogg")
		self.engine_idle_sound.setLoop(True)
		self.accelerate_sound = loader.loadSfx("Sounds/enginethrottle.ogg")
				
		#Camera
		base.disableMouse()
		camera.reparentTo(Car_np)
		camera.setPos(0,-15,3)
		camera.setHpr(0,-10,0)
		
		#Wheel function
		def Wheel(pos, np, r, f):
			w = self.Car_sim.createWheel()
			w.setNode(np.node())
			w.setChassisConnectionPointCs(pos)
			w.setFrontWheel(f)
			w.setWheelDirectionCs(Vec3(0, 0, -1))
			w.setWheelAxleCs(Vec3(1, 0, 0))
			w.setWheelRadius(r)
			w.setMaxSuspensionTravelCm(40)
			w.setSuspensionStiffness(120)
			w.setWheelsDampingRelaxation(2.3)
			w.setWheelsDampingCompression(4.4)
			w.setFrictionSlip(50)
			w.setRollInfluence(0.1)
		
		#Wheels	
		w1_np = loader.loadModel("Models/Lwheel")
		w1_np.reparentTo(render)
		w1_np.setColorScale(0,6)
		Wheel(Point3(-1,1,-0.6), w1_np, 0.4, False)
		
		w2_np = loader.loadModel("Models/Rwheel")
		w2_np.reparentTo(render)
		w2_np.setColorScale(0,6)
		Wheel(Point3(-1.1,-1.2,-0.6), w2_np, 0.4, True)
		
		w3_np = loader.loadModel("Models/Lwheel")
		w3_np.reparentTo(render)
		w3_np.setColorScale(0,6)
		Wheel(Point3(1.1,-1,-0.6), w3_np, 0.4, True)
		
		w4_np = loader.loadModel("Models/Rwheel")
		w4_np.reparentTo(render)
		w4_np.setColorScale(0,6)
		Wheel(Point3(1,1,-0.6), w4_np, 0.4, False)
		

		
		#The engine and steering
		def processInput(dt):
			
			#Vehicle properties
			self.steeringClamp = 35.0
			self.steeringIncrement = 70
			engineForce = 0.0
			brakeForce = 0.0
			
			
			#Get the vehicle's current speed
			self.carspeed = self.Car_sim.getCurrentSpeedKmHour()
			
			
			#Engage clutch when in gear 0
			if self.gear == 0:
				self.clutch = 1
			
			
			#Slow the steering when at higher speeds
			self.steeringIncrement = self.steeringIncrement - self.carspeed / 1.5
			
			
			#Reset the steering
			if not inputState.isSet("L") and not inputState.isSet("R"):
				
				if self.steering < 0.00:
					self.steering = self.steering + 0.6
				if self.steering > 0.00:
					self.steering = self.steering - 0.6
					
				if self.steering < 1.0 and self.steering > -1.0:
					self.steering = 0
			
			
			#Slow the car down while it's moving
			if self.clutch == 0:
				brakeForce = brakeForce + self.carspeed / 5
			else:
				brakeForce = brakeForce + self.carspeed / 15
		
			
			#Forward
			if self.start == 1:
				if inputState.isSet("F"):
					self.RPM = self.RPM + 35
					self.accelerate_sound.play()
				if self.clutch == 0:
					
					if self.gear == -1:
						if self.carspeed > self.carmaxreversespeed:	
							engineForce = -self.RPM / 3
							
					if self.gear == 1:
						if self.carspeed < self.carmaxspeed:
							engineForce = self.RPM / 1

			
			#Brake	
			if inputState.isSet("B"):
				engineForce = 0.0
				brakeForce = 12.0
				if self.gear != 0 and self.clutch == 0:
					self.RPM = self.RPM - 20
				
			#Left	
			if inputState.isSet("L"):
				if self.steering < 0.0:
					#This makes the steering reset at the correct speed when turning from right to left
					self.steering += dt * self.steeringIncrement + 0.6
					self.steering = min(self.steering, self.steeringClamp)
				else:
					#Normal steering
					self.steering += dt * self.steeringIncrement
					self.steering = min(self.steering, self.steeringClamp)
			
			#Right	
			if inputState.isSet("R"):
				if self.steering > 0.0:
					#This makes the steering reset at the correct speed when turning from left to right
					self.steering -= dt * self.steeringIncrement + 0.6
					self.steering = max(self.steering, -self.steeringClamp)
				else:
					#Normal steering
					self.steering -= dt * self.steeringIncrement
					self.steering = max(self.steering, -self.steeringClamp)
			
			#Park
			if self.Pbrake == 1:
				brakeForce = 10.0
				if self.gear != 0 and self. clutch == 0:
					self.RPM = self.RPM - 20
				
				
			#Apply forces to wheels	
			self.Car_sim.applyEngineForce(engineForce, 0);
			self.Car_sim.applyEngineForce(engineForce, 3);
			self.Car_sim.setBrake(brakeForce, 1);
			self.Car_sim.setBrake(brakeForce, 2);
			self.Car_sim.setSteeringValue(self.steering, 0);
			self.Car_sim.setSteeringValue(self.steering, 3);
			
			#Steering wheel
			Sw.setHpr(0,0,-self.steering*10)
		
		
		#The HUD
		self.gear_hud = OnscreenImage(image = "Textures/gear_hud.png", pos = (-1,0,-0.85), scale = (0.2))
		self.gear_hud.setTransparency(TransparencyAttrib.MAlpha)
		
		self.gear2_hud = OnscreenImage(image = "Textures/gear2_hud.png", pos = (-1,0,-0.85), scale = (0.2))
		self.gear2_hud.setTransparency(TransparencyAttrib.MAlpha)
		
		self.starter = OnscreenImage(image = "Textures/starter.png", pos = (-1.2,0,-0.85), scale = (0.15))
		self.starter.setTransparency(TransparencyAttrib.MAlpha)
		
		self.park = OnscreenImage(image = "Textures/pbrake.png", pos = (-0.8,0,-0.85), scale = (0.1))
		self.park.setTransparency(TransparencyAttrib.MAlpha)
		
		self.rev_counter = OnscreenImage(image = "Textures/dial.png", pos = (-1.6, 0.0, -0.70), scale = (0.6,0.6,0.4))
		self.rev_counter.setTransparency(TransparencyAttrib.MAlpha)
		
		self.rev_needle = OnscreenImage(image = "Textures/needle.png", pos = (-1.6, 0.0, -0.70), scale = (0.5))
		self.rev_needle.setTransparency(TransparencyAttrib.MAlpha)
		
		self.rev_text = OnscreenText(text = " ", pos = (-1.6, -0.90, 0), scale = 0.05)
		
		self.speedometer = OnscreenImage(image = "Textures/dial.png", pos = (-1.68, 0.0, -0.10), scale = (0.7,0.7,0.5))
		self.speedometer.setTransparency(TransparencyAttrib.MAlpha)
		
		self.speedometer_needle = OnscreenImage(image = "Textures/needle.png", pos = (-1.68, 0.0, -0.10), scale = (0.5))
		self.speedometer_needle.setTransparency(TransparencyAttrib.MAlpha)
		
		self.speedometer_text = OnscreenText(text = " ", pos = (-1.68, -0.35, 0), scale = 0.05)
		
		
		#Update the HUD
		def Update_HUD():
			
			#Move gear selector
			if self.gear == -1:
				self.gear2_hud.setPos(-1,0,-0.785)
			if self.gear == 0:
				self.gear2_hud.setPos(-1,0,-0.85)
			if self.gear == 1:
				self.gear2_hud.setPos(-1,0,-0.91)
				
			#Rotate starter
			if self.start == 0:
				self.starter.setHpr(0,0,0)
			else:
				self.starter.setHpr(0,0,45)	
				
			#Update the parking brake light
			if self.Pbrake == 1:
				self.park.setImage("Textures/pbrake2.png")
				self.park.setTransparency(TransparencyAttrib.MAlpha)
			else:
				self.park.setImage("Textures/pbrake.png")
				self.park.setTransparency(TransparencyAttrib.MAlpha)	
				
			#Update the rev counter
			self.rev_needle.setR(self.RPM/22)	
			rev_string = str(self.RPM)[:4]
			self.rev_text.setText(rev_string+" RPM")
			
			#Update the speedometer
			if self.carspeed > 0.0:
				self.speedometer_needle.setR(self.carspeed*2.5)
			if self.carspeed < 0.0:
				self.speedometer_needle.setR(-self.carspeed*2.5)
			speed_string = str(self.carspeed)[:3]
			self.speedometer_text.setText(speed_string+" KPH")
					
					
						
		#Update the program
		def update(task):
			dt = globalClock.getDt() 
			processInput(dt)
			Update_HUD()
			set_time()
			set_terrain()
			set_headlights()
			update_rpm()
			scene.doPhysics(dt, 5, 1.0/180.0)
			return task.cont
			
		taskMgr.add(update, "Update")
Beispiel #57
0
    def __init__(self):
        ShowBase.__init__(self)

        # Input
        self.accept('escape', self.doExit)
        self.accept('f3', self.toggleDebug)


        inputState.watchWithModifiers('forward', 'w')
        inputState.watchWithModifiers('reverse', 's')
        inputState.watchWithModifiers('turnLeft', 'a')
        inputState.watchWithModifiers('turnRight', 'd')

        # Post the instructions
        self.title = addTitle("Infinite Loop: A Robot's Nightmare")
        self.inst1 = addInstructions(0.95, "[ESC]: Quit")
        self.inst2 = addInstructions(0.90, "[W]: Run Forward")
        self.inst3 = addInstructions(0.85, "[A]: Turn Left")
        self.inst4 = addInstructions(0.80, "[S]: Walk Backwards")
        self.inst5 = addInstructions(0.75, "[D]: Turn Right")
        self.inst6 = addInstructions(0.70, "[SPACE]: Jump")

        # Game state variables
        self.lettersRemaining = 5
        self.letters = []
        self.collectedLetters = []
        self.health = 100
        self.enemies = []
        self.movingPlatforms = []
        self.isTakingDamage = False
        self.start = True
        self.worldCondition = False
        self.onLevelTwo = False
        self.menuOn = True

        # Number of collectibles
        self.numObjects = addNumObj(
            "Find letters B R E A K to escape\nLetters Remaining: " + str(self.lettersRemaining))

        # Health Bar
        self.bar = DirectWaitBar(text="H E A L T H",
                                 value=100,  # start with full health
                                 pos=(0, .4, 0.93),  # position healthbar to top center
                                 scale=(1.3, 2.5, 2.5),
                                 barColor=(0.97, 0, 0, 1),
                                 frameSize=(-0.3, 0.3, 0, 0.025),
                                 text_mayChange=1,
                                 text_shadow=(0, 0, 0, 0),
                                 text_fg=(0.9, 0.9, 0.9, 1),
                                 text_scale=0.030,
                                 text_pos=(0, 0.005, 0))
        self.bar.setBin("fixed", 0)  # health bar gets drawn in last scene
        self.bar.setDepthWrite(False)  # turns of depth writing so it doesn't interfere with itself
        self.bar.setLightOff()  # fixes the color on the bar itself


        base.disableMouse()

        # Go through gamesetup sequence
        self.setup()

        # Add update task to task manager
        taskMgr.add(self.update, 'updateWorld')
        taskMgr.add(self.updateWinLose, 'winLose')
        taskMgr.add(self.startMenu, 'startMenu')

        # Create a floater object
        self.floater = NodePath(PandaNode("floater"))
        self.floater.reparentTo(render)