import random
bird_y = 200
bird_y_speed = 0
playing_area_width = 300
playing_area_height = 388
pipe_space_height = 100
pipe_space_y_min = 54
pipe_space_y = random.randint(
pipe_space_y_min,
playing_area_height - pipe_space_height - pipe_space_y_min
)
def update(dt):
global bird_y
global bird_y_speed
bird_y_speed += 516 * dt
bird_y += bird_y_speed * dt
def on_key_down():
global bird_y_speed
if bird_y > 0:
bird_y_speed = -165
global pipe_space_y
pipe_space_y = random.randint(
pipe_space_y_min,
playing_area_height - pipe_space_height - pipe_space_y_min
)
def draw():
screen.fill((0, 0, 0))
screen.draw.filled_rect(
Rect(
(0, 0),
(playing_area_width, playing_area_height)
),
color=(35, 92, 118)
)
screen.draw.filled_rect(
Rect(
(62, bird_y),
(30, 25)
),
color=(224, 214, 68)
)
pipe_width = 54
screen.draw.filled_rect(
Rect(
(playing_area_width, 0),
(pipe_width, pipe_space_y)
),
color=(94, 201, 72)
)
screen.draw.filled_rect(
Rect(
(playing_area_width, pipe_space_y + pipe_space_height),
(pipe_width, playing_area_height - pipe_space_y - pipe_space_height)
),
color=(94, 201, 72)
)