import pygame
import random
import sys
# Initialize Pygame
[Link]()
# Screen dimensions
WIDTH, HEIGHT = 800, 600
screen = [Link].set_mode((WIDTH, HEIGHT))
[Link].set_caption("Catch the Falling Objects")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
# Clock
clock = [Link]()
FPS = 60
# Player settings
player_width, player_height = 100, 20
player_x = WIDTH // 2 - player_width // 2
player_y = HEIGHT - player_height - 10
player_speed = 10
# Falling object settings
object_width, object_height = 30, 30
object_x = [Link](0, WIDTH - object_width)
object_y = -object_height
object_speed = 5
# Score
score = 0
font = [Link](None, 36)
# Game loop
def main():
global player_x, object_x, object_y, object_speed, score
running = True
while running:
[Link](BLACK)
# Event handling
for event in [Link]():
if [Link] == [Link]:
running = False
# Player movement
keys = [Link].get_pressed()
if keys[pygame.K_LEFT] and player_x > 0:
player_x -= player_speed
if keys[pygame.K_RIGHT] and player_x < WIDTH - player_width:
player_x += player_speed
# Update object position
object_y += object_speed
# Check for collision
if (
object_y + object_height > player_y
and object_x + object_width > player_x
and object_x < player_x + player_width
):
score += 1
object_y = -object_height
object_x = [Link](0, WIDTH - object_width)
object_speed += 0.5 # Increase difficulty
# Reset object if it falls off screen
if object_y > HEIGHT:
object_y = -object_height
object_x = [Link](0, WIDTH - object_width)
# Draw player
[Link](screen, BLUE, (player_x, player_y, player_width,
player_height))
# Draw falling object
[Link](screen, RED, (object_x, object_y, object_width,
object_height))
# Draw score
score_text = [Link](f"Score: {score}", True, WHITE)
[Link](score_text, (10, 10))
# Update display
[Link]()
# Cap the frame rate
[Link](FPS)
[Link]()
[Link]()
# Run the game
if __name__ == "__main__":
main()