當前位置: 首頁>>代碼示例>>Python>>正文


Python GameState.onEnter方法代碼示例

本文整理匯總了Python中GameState.onEnter方法的典型用法代碼示例。如果您正苦於以下問題:Python GameState.onEnter方法的具體用法?Python GameState.onEnter怎麽用?Python GameState.onEnter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在GameState的用法示例。


在下文中一共展示了GameState.onEnter方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: StateMachine

# 需要導入模塊: import GameState [as 別名]
# 或者: from GameState import onEnter [as 別名]
class StateMachine(State, Receiver, InputHandler):

    __states = {}
    # _startState = StartState()
    # _creditState = CreditsState()
    # _gameState = GameState()
    # _charSelectState = CharSelectState()

    def __init__(self, type, aBatch, aBackground, aForeGround, aWindow, aMessenger):
        self._type = type
        self._startState = StartState(aBatch, aBackground, aForeGround, aWindow, type, aMessenger)
        self._creditState = CreditsState(aBatch, aBackground, aForeGround, aWindow, type, aMessenger)
        self._gameState = GameState(aBatch, aBackground, aForeGround, aWindow, type, aMessenger)
        self._charSelectState = CharSelectState(aBatch, aBackground, aForeGround, aWindow, type, aMessenger)
        self._charSettings = SettingsState(aBatch, aBackground, aForeGround, aWindow, type, aMessenger)
        self.__states = {self._startState, self._creditState, self._gameState, self._charSelectState, self._charSettings}

    def onEnter(self):
        pass

    def onExit(self):
        pass

    def onReceive(self, message):
        if message.msg == States.Start:
            self.setNotActive()
            self._startState.onEnter()
        elif message.msg == States.Credits:
            self.setNotActive()
            self._creditState.onEnter()
        elif message.msg == States.Game:
            self.setNotActive()
            self._gameState.onEnter()
        elif message.msg == States.CharSelect:
            self.setNotActive()
            self._charSelectState.onEnter()
        elif message.msg == States.Settings:
            self.setNotActive()
            self._charSettings.onEnter()

    def setNotActive(self):
        for state in self.__states:
            if state.isActive:
                state.onExit()
                state._active = False

    def handleKeyPress(self, symbol, modifiers):
        for state in self.__states:
            if state.isActive:
                state.handleKeyPress(symbol, modifiers)

    def handleKeyRelease(self, symbol, modifiers):
        for state in self.__states:
            if state.isActive:
                state.handleKeyRelease(symbol, modifiers)
開發者ID:MartinM-B,項目名稱:BeU,代碼行數:57,代碼來源:StateMachine.py


注:本文中的GameState.onEnter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。