本文整理匯總了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)