game.py 文件源码

python
阅读 47 收藏 0 点赞 0 评论 0

项目:Flappy 作者: lucaspbordignon 项目源码 文件源码
def play(self):
        """Initialize the software."""
        self.load_score_images()
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    return 0
                if not self.pipes_stop:
                    if event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_UP:
                            self.y_increase = -5

            # Initialize the bird and the background.
            self.screen.blit(self.background_img, (0, 0))

            self.y_increase += 0.25  # Simulates gravity acceleration

            self.pipes()  # Update pipes

            # Count the score.
            self.score()

            if self.bird_dies():
                # Bird dies
                self.bird()
                self.gameover()
                pygame.display.flip()
                return 1
                self.y_increase = 0
                self.pipes_stop = True
            else:
                self.pipes_stop = False

            self.bird()
            self.y_bird += self.y_increase

            # Update the screen.
            pygame.display.flip()
            self.clock.tick(60)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号