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


Python StateMachine.push方法代碼示例

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


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

示例1: GameEngine

# 需要導入模塊: from statemachine import StateMachine [as 別名]
# 或者: from statemachine.StateMachine import push [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
#.........這裏部分代碼省略.........
開發者ID:thomas64,項目名稱:pyRPG2,代碼行數:103,代碼來源:engine.py


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