# Game Title: CATCH THE FALLING BALL GAME # Instructions: # 1. Use the LEFT arrow key to move left. # 2. Use the RIGHT arrow key to move right. # 3. Catch the falling ball with the turtle to earn points. # 4. If you miss the ball, the game is over. import turtle import random import time screen = turtle.Screen() screen.bgcolor("blue") screen.setup(width=480, height=600) # Player player = turtle.Turtle() player.shape("turtle") player.color("green") player.penup() player.goto(0, -250) # Ball ball = turtle.Turtle() ball.shape("circle") ball.color("black") ball.penup() ball.goto(random.randint(-200, 200), 280) # Adjust range so ball stays inside screen # Score display score = 0 score_display = turtle.Turtle() score_display.hideturtle() score_display.penup() score_display.goto(0, 260) score_display.write("Score: {}".format(score), align="center", font=("Times New Roman", 20, "bold")) def update_score(): score_display.clear() score_display.goto(0, 260) score_display.write("Score: {}".format(score), align="center", font=("Times New Roman", 25, "bold")) # Player movement def move_left(): x = player.xcor() if x > -220: player.setx(x - 30) def move_right(): x = player.xcor() if x < 220: player.setx(x + 30) # Key bindings screen.listen() screen.onkey(move_left, "Left") screen.onkey(move_right, "Right") game_on = True fall_speed = 4 while game_on: y = ball.ycor() y -= fall_speed ball.sety(y) if y < -280: score_display.clear() score_display.goto(0, 0) score_display.write("GAME OVER!\nFinal Score: {}".format(score), align="center", font=("Calibri", 20, "bold")) game_on = False if player.distance(ball) < 30 and y < -220: score += 1 update_score() ball.goto(random.randint(-200, 200), 280) time.sleep(0.01)