| 56 | |
| 57 | |
| 58 | def main(): |
| 59 | clock = pygame.time.Clock() |
| 60 | bird = Bird() |
| 61 | pipes = [Pipe()] |
| 62 | score = 0 |
| 63 | |
| 64 | running = True |
| 65 | while running: |
| 66 | for event in pygame.event.get(): |
| 67 | if event.type == pygame.QUIT: |
| 68 | running = False |
| 69 | if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE: |
| 70 | bird.flap() |
| 71 | |
| 72 | bird.update() |
| 73 | for pipe in pipes: |
| 74 | pipe.update() |
| 75 | if pipe.x + pipe.image.get_width() < 0: |
| 76 | pipes.remove(pipe) |
| 77 | pipes.append(Pipe()) |
| 78 | score += 1 |
| 79 | |
| 80 | screen.blit(background_image, (0, 0)) |
| 81 | bird.draw(screen) |
| 82 | for pipe in pipes: |
| 83 | pipe.draw(screen) |
| 84 | |
| 85 | pygame.display.update() |
| 86 | clock.tick(30) |
| 87 | |
| 88 | pygame.quit() |
| 89 | |
| 90 | |
| 91 | if __name__ == "__main__": |