-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
63 lines (46 loc) · 1.19 KB
/
game.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
import pygame
import sys
from pygame.locals import *
# Initialize Pygame
pygame.init()
# Set up display
width, height = 600, 600
window = pygame.display.set_mode((width, height))
pygame.display.set_caption('Flappy Game')
window.fill((255, 255, 255))
# Set up the clock for a decent framerate
clock = pygame.time.Clock()
# Main game loop
running = True
#image
bird = pygame.image.load('bird.gif')
x = 300
y = 300
while running:
try:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Fill the window with a color (RGB)
# Update the display
pygame.display.flip()
# Cap the frame rate
clock.tick(60)
for i in pygame.event.get():
if i.type == QUIT:
pygame.quit()
sys.exit()
if i.type == KEYDOWN:
if i.key == K_UP:
y -= 10
window.blit(bird, (x, y))
pygame.display.update()
except Exception as e:
print(f"An error occurred: {e}")
break
except KeyboardInterrupt:
print(f"Keyboard interrupt detected.")
break
# Quit Pygame
pygame.quit()
sys.exit()