-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbirdie.py
81 lines (60 loc) · 1.77 KB
/
birdie.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import pygame
import game
ANIMATION_SPEED = 5
JUMP_SPEED = 12
score = 0
pygame.init()
pygame.font.init()
my_font = pygame.font.SysFont('Comic Sans MS', 30)
display_width = 800
display_height = 600
gameDisplay = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption('THE BIRDIE')
black = (0, 0, 0)
white = (255, 255, 255)
bird = game.Bird()
background = game.Background()
obstacles = game.init_obstacles()
background.init()
clock = pygame.time.Clock()
crashed = False
x = (display_width * 0.45)
y = (display_height * 0.8)
bird.x = 300
bird.y = 0
index = 0
while not crashed:
for event in pygame.event.get():
if event.type == pygame.QUIT:
crashed = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
bird.vertical_speed = JUMP_SPEED
gameDisplay.fill(white)
background.display(gameDisplay)
if index == ANIMATION_SPEED:
bird.update()
index = 0
bird.display(gameDisplay)
for obstacle in obstacles:
if bird.x == obstacle.x:
score += 1
obstacle.display(gameDisplay)
text_surface = my_font.render(str(score), False, (0, 0, 0))
gameDisplay.blit(text_surface, (750, 0))
crashed = bird.check_if_crashed(obstacles)
pygame.display.update()
clock.tick(60)
index += 1
text_surface = my_font.render("GAME OVER", False, (0, 0, 0))
gameDisplay.blit(text_surface, (300, 300))
pygame.display.update()
new_game = False
while not new_game:
for event in pygame.event.get():
if event.type == pygame.QUIT:
new_game = True
if event.type == pygame.KEYDOWN:
new_game = True
pygame.quit()
quit()