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


Python Stopwatch.tick方法代碼示例

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


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

示例1: Game

# 需要導入模塊: from stopwatch import Stopwatch [as 別名]
# 或者: from stopwatch.Stopwatch import tick [as 別名]

#.........這裏部分代碼省略.........
        if cannon.direction > 0:
            ball.x = cannon.x + cannon.width + ball.realR
        else:
            ball.x = cannon.x - ball.realR

    def timerFiredPlay(self):
        if (self.ball.x < self.maps.left
                or self.ball.x > self.maps.left + self.maps.width or
                self.ball.y < self.maps.top
                or self.ball.y > self.maps.top + self.maps.height):
            # Ball off map
            self.killBall()

        collided = pygame.sprite.spritecollide(self.ball, self.terrain, False,
            Terrain.collidedFn)
        if len(collided) > 0:
            elements = Terrain.manageCollision(self.ball, collided)
            for element, direction in elements:
                result = element.interactFromDir(self.ball, direction)
                if result == "score":
                    self.score += element.points
                elif result == "win":
                    self.nextLevel()
                elif result == "fly":
                    self.ballFly(self.ball, element)
                elif result == "kill":
                    self.killBall()

        self.ball.update(self.isKeyPressed)

    def timerFired(self, dt):
        if self.mode == "play":
            self.timerFiredPlay()
            self.stopwatch.tick(dt)

    def drawMenu(self, screen):
        titleTop = 70
        titleLeft = 60
        x = drawText(screen, titleLeft, titleTop,
            text="Bouncy Bouncy ", font=self.font.title, anchor="nw")
        space = 8
        drawText(screen, x + space, titleTop, text="Revamped",
            font=self.font.titleEmph, anchor="nw")
        self.mainMenu.draw(screen, self.font.text)

    def drawGame(self, screen):
        self.terrain.draw(screen)
        self.ball.draw(screen)
        pos = 30
        drawText(screen, self.margin, pos,
            text="Level %s" % self.level, font=self.font.text, anchor="nw")
        pos = 80
        drawText(screen, self.margin, pos,
            text="Score: %d" % self.score, font=self.font.text, anchor="nw")
        pos = 110
        drawText(screen, self.margin, pos, text="Highscore:",
            font=self.font.text, anchor="nw")
        pos = 130
        drawText(screen, self.margin, pos, text=self.highscoreText,
            font=self.font.text, anchor="nw")
        self.drawGameTime(screen)

    def drawGameTime(self, screen):
        pos = 180
        drawText(screen, self.margin, pos,
            text=str(self.stopwatch), font=self.font.text, anchor="nw")
開發者ID:daniel-wen,項目名稱:bouncier,代碼行數:70,代碼來源:main.py


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