-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinal_game.py
More file actions
53 lines (40 loc) · 1.46 KB
/
final_game.py
File metadata and controls
53 lines (40 loc) · 1.46 KB
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
import pygame
from game_lib import Bird, PipeManager, check_collision, init_display
def main():
screen = init_display()
pygame.display.set_caption("Assembly Engine Flappy Bird")
clock = pygame.time.Clock()
bird = Bird(50, 300)
pipe_manager = PipeManager(400)
running = True
game_over = False
while running:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and not game_over:
bird.jump()
if event.key == pygame.K_r and game_over:
# Reset
bird = Bird(50, 300)
pipe_manager = PipeManager(400)
game_over = False
screen.fill((135, 206, 235)) # Sky blue
if not game_over:
bird.move()
pipe_manager.update()
if check_collision(bird, pipe_manager):
game_over = True
bird.draw(screen)
pipe_manager.draw(screen)
if game_over:
# Draw Game Over text
font = pygame.font.SysFont('Arial', 30)
text = font.render("GAME OVER - Press R", True, (255, 0, 0))
screen.blit(text, (50, 250))
pygame.display.flip()
pygame.quit()
if __name__ == "__main__":
main()