本文整理汇总了Python中statemachine.StateMachine.pop方法的典型用法代码示例。如果您正苦于以下问题:Python StateMachine.pop方法的具体用法?Python StateMachine.pop怎么用?Python StateMachine.pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类statemachine.StateMachine
的用法示例。
在下文中一共展示了StateMachine.pop方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GameEngine
# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import pop [as 别名]
class GameEngine(object):
"""
De grafische weergave van het scherm. Handelt de states.
"""
def __init__(self):
self.screen = pygame.display.get_surface()
self.gamestate = StateMachine()
self.data = None
self.video = Video()
self.audio = Audio(self)
self.running = False
self.all_maps_loaded = False
self.force_bg_music = False
self.clock = pygame.time.Clock()
self.playtime = 0.0
self.dt = 0.0
self.key_timer = 0.0
self.state_timer = 0.0
self.debugfont = pygame.font.SysFont(DEBUGFONT, DEBUGFONTSIZE)
self.key_input = None
self.mouse_input = None
self.show_debug = False
self.debug_mode = True
self.fps = FPS
threading.Thread(target=self.load_all_maps).start()
def load_all_maps(self):
"""..."""
map_path = 'resources/maps/'
Console.load_all_maps()
try:
# noinspection PyTypeChecker
for map_name in MapTitle:
map_name.value.append(pytmx.load_pygame(map_path + map_name.name + '.tmx'))
except pygame.error:
# bij het sluiten van het spel voordat alle kaarten geladen zijn.
pass
self.all_maps_loaded = True
Console.maps_loaded()
def on_enter(self):
"""
Voordat de loop van start gaat.
"""
self.running = True
push_object = screens.menu.create_menu(GameState.MainMenu, self)
self.gamestate.push(push_object)
def main_loop(self):
"""
Start de game loop.
"""
while self.running:
# limit the redraw speed to 60 frames per second
self.dt = self.clock.tick(self.fps)/1000.0
self.playtime += self.dt
if not self.gamestate.is_empty():
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running = False
self.single_input(event)
self.multi_input()
self.update()
self.render()
pygame.display.flip()
# pop() het laadscherm wanneer dat kan.
if not self.gamestate.is_empty():
if self.gamestate.peek().name == GameState.LoadScreen:
if self.all_maps_loaded:
self.gamestate.pop()
# als de stack leeg is, push Overworld. Dit vanwege geluid en kaarten laden.
if self.gamestate.is_empty():
if self.all_maps_loaded:
self.gamestate.push(Overworld(self))
def single_input(self, event):
"""
Handelt de muis en keyboard input af.
:param event: pygame.event.get()
"""
if event.type == pygame.MOUSEMOTION:
pygame.mouse.set_visible(True)
# if event.type == pygame.MOUSEBUTTONDOWN: # todo, tijdelijk staan ze uit
# Console.mouse_down(event.pos, event.button)
if event.type == pygame.KEYDOWN:
# Console.keyboard_down(event.key, event.unicode)
pygame.mouse.set_visible(False)
if self.debug_mode:
if event.key == Keys.Debug.value:
# simple boolean swith
#.........这里部分代码省略.........