import pygame import random import sys # Initialize Pygame pygame.init() # Set up the game window WIDTH, HEIGHT = 800, 600 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Aim Trainer") # Define colors WHITE = (255, 255, 255) RED = (255, 0, 0) # Define target class class Target(pygame.sprite.Sprite): def __init__(self): super().__init__() self.image = pygame.Surface((50, 50)) self.image.fill(RED) self.rect = self.image.get_rect() self.rect.center = (random.randint(50, WIDTH - 50), random.randint(50, HEIGHT - 50)) # Create sprite group all_sprites = pygame.sprite.Group() # Create targets targets = pygame.sprite.Group() for _ in range(5): # Create 5 targets target = Target() all_sprites.add(target) targets.add(target) # Main game loop running = True clock = pygame.time.Clock() score = 0 while running: # Handle events for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.MOUSEBUTTONDOWN: # Check if the click hit any targets for target in targets: if target.rect.collidepoint(event.pos): targets.remove(target) all_sprites.remove(target) score += 1 # If all targets have been clicked, reset them if len(targets) == 0: for _ in range(5): # Create 5 new targets target = Target() all_sprites.add(target) targets.add(target) # Update all_sprites.update() # Draw screen.fill(WHITE) all_sprites.draw(screen) # Display score font = pygame.font.SysFont(None, 36) score_text = font.render("Score: " + str(score), True, RED) screen.blit(score_text, (20, 20)) pygame.display.flip() # Cap the frame rate clock.tick(60) pygame.quit() sys.exit()