本文整理汇总了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)