-
Notifications
You must be signed in to change notification settings - Fork 0
/
play.py
65 lines (52 loc) · 1.73 KB
/
play.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pygame
import sys
from config import WINDOW_SIZE, FPS
from game import Game
from objects.failedscreen import FailedScreen
from objects.background import BACKGROUND_COLOR, Background
from objects.bird import Bird
from objects.pipe import Pipe
from objects.scoreboard import ScoreBoard
pygame.init()
pygame.display.set_caption('flappy Bird Play')
screen = pygame.display.set_mode(WINDOW_SIZE)
clock = pygame.time.Clock()
game = Game(WINDOW_SIZE)
pipes = []
# pipes = [Pipe((0, 0), (60, 100))]
bird = Bird(game.bird_position)
background = Background(WINDOW_SIZE)
failed = None
scoreboard = ScoreBoard(WINDOW_SIZE, 0)
def getUpperPipe(p, game: Game):
pos = p.upperPosition
return Pipe((pos[0] - game.camera_rect[0], pos[1]), p.upperSize, False)
def getLowerPipe(p, game: Game):
pos = p.lowerPosition
return Pipe((pos[0] - game.camera_rect[0], pos[1]), p.lowerSize, True)
while True:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
game.click()
game.update()
bird.update(game)
background.update(game)
scoreboard.update(game)
pipes = [getUpperPipe(p, game) for p in game.pipes] + [getLowerPipe(p, game) for p in game.pipes]
screen.fill(BACKGROUND_COLOR)
for p in pipes:
screen.blit(p.image, p.position)
background.draw(screen)
screen.blit(bird.image, bird.position)
screen.blit(scoreboard.image, scoreboard.position)
if game.dead:
if failed == None:
failed = FailedScreen(WINDOW_SIZE, game.score, game.best_score)
screen.blit(failed.image, failed.position)
else:
failed = None
pygame.display.flip()
pygame.quit()