STEP Seven – A
— Add this code after the Collision Detection function and before Running = True
# START SCREEN
startFont = pygame.font.Font('freesansbold.ttf', 32)
def start():
# displays: "press space bar to start)
display = startFont.render(f"PRESS SPACE BAR TO START", True, (255, 255, 255))
SCREEN.blit(display, (20, 200))
pygame.display.update()
# GAME OVER SCREEN
game_over_font1 = pygame.font.Font('freesansbold.ttf', 64)
game_over_font2 = pygame.font.Font('freesansbold.ttf', 32)
def game_over():
# "game over"
display1 = game_over_font1.render(f"GAME OVER", True, (200,35,35))
SCREEN.blit(display1, (50, 300))
# shows your current score and your max score
display2 = game_over_font2.render(f"SCORE: {score}", True, (255, 255, 255))
SCREEN.blit(display2, (50, 400))
STEP Seven – B
# we will be sent into this while loop at the beginning and ending of each game
while waiting:
if collision:
# If collision is True (from the second time onwards) we will see both the end screen and the start screen
game_over()
start()
else:
# This refers to the first time the player is starting the game
start()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
# If we press the space bar we will exit out of the waiting while loop and start to play the game
# we will also reset some of the variables such as the score and the bird's Y position and the obstacle's starting position
score = 0
bird_y = 300
obstacle_x = 500
# to exit out of the while loop
waiting = False
STEP Seven – C
— Add this between resetting Obstacle Height and displaying the obstacle
score += 1
STEP Seven – D
— Alter the code in the if collision block
from
running = False
to
waiting = True