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


Python Timer.toggle_pause方法代碼示例

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


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

示例1: MainGame

# 需要導入模塊: import Timer [as 別名]
# 或者: from Timer import toggle_pause [as 別名]

#.........這裏部分代碼省略.........
                for i in self.winning_frogs:
                    if i.rect.colliderect(r):
                        unoccupied = False 


            # Place the fly and tell draw() to draw it
            self.fly.rect.left = r.left + 2
            self.fly.rect.top  = r.top + 2
            self.fly_shown = True 

        # Hide the fly 6 seconds after being shown
        elif self.fly_timer.get_seconds() == 0 and self.fly_shown:
            self.fly_shown = False 
            self.fly_appear_timer.reset()


    # Checks if the game is over,
    # Changes the timer,
    # Toggles the fly
    # Handles other logic
    def play(self):

        if not self.fly_appear_timer.is_started():
            self.fly_appear_timer.start()

        # End the game if the player is out of lives
        if self.lives == 0:
            self.message = "Game over. You need more practice."
            self.messageSurface = self.font.render(self.message, True, (255, 255, 255))
            self.game_over = True 
            if self.game_over_time == 0:
                self.game_over_time = pygame.time.get_ticks()
            
            self.timer.toggle_pause()

        # End the game if the level limit has been reached
        if self.level >= MAX_LEVELS:
            self.game_over = True 
            self.message = "For more levels, send $10 to [email protected]"
            self.messageSurface = self.font.render(self.message, True, (255, 255, 255))

            if self.game_over_time == 0:
                self.game_over_time = pygame.time.get_ticks()

        self.timeSinceNew = self.timer.get_seconds()

        # Check if the timer ran out
        if self.timeSinceNew == 0:
            # frog will die, new one spawn
            self.killFrog()
            self.timer.reset()
            pass 

        if len(self.frogs) > 0:
            # Play the frog's animation if it's jumping
            if self.frogs[0].jumping or self.frogs[0].died_by_water:
                self.frogs[0].update(pygame.time.get_ticks())

                if self.frogs[0].current_clip == self.frogs[0].max_frames - 1:
                    # self.frogs[0].reset_jump_flags()
                    self.frogs[0].jumping = False 

        self.moveObjects()
        self.placePowerups()

    # Helper function.
開發者ID:nickihilker,項目名稱:frogger-1,代碼行數:70,代碼來源:MainGame.py


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