-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlappyBird.py
More file actions
41 lines (34 loc) · 1.02 KB
/
FlappyBird.py
File metadata and controls
41 lines (34 loc) · 1.02 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
import pygame
import sys
# Game variables
gravity = 0.25
bird_movement = 0
bg_surface = pygame.Surface((288, 512))
bg_surface.fill((135, 206, 235))
# Bird properties
bird_surface = pygame.Surface((28, 28))
bird_surface.fill((255, 255, 255))
bird_rect = bird_surface.get_rect(center=(50, 256))
# Pipe properties
pipe_surface = pygame.Surface((40, 512))
pipe_surface.fill((0, 0, 0))
pipe_rect = pipe_surface.get_rect(center=(288, 256))
# Game loop
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
bird_movement = 0
bird_movement -= 6
# Move the bird
bird_movement += gravity
bird_rect.centery += bird_movement
# Draw everything
screen = pygame.display.set_mode((288, 512))
screen.blit(bg_surface, (0, 0))
screen.blit(bird_surface, bird_rect)
screen.blit(pipe_surface, pipe_rect)
pygame.display.flip()