import pygame import random import math # Initialize Pygame pygame.init() # Set up the screen screen_width = 800 screen_height = 600 screen = pygame.display.set_mode((screen_width, screen_height)) pygame.display.set_caption("Aim Trainer") # Colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (255, 0, 0) GREEN = (0, 255, 0) # Target properties target_radius = 20 target_color = RED target_hit_color = GREEN targets = [] num_targets = 10 # Fonts font = pygame.font.Font(None, 36) # Function to generate random targets def generate_targets(num_targets): targets.clear() for _ in range(num_targets): x = random.randint(target_radius, screen_width - target_radius) y = random.randint(target_radius, screen_height - target_radius) targets.append((x, y)) # Function to check if a click hits a target def hit_target(mouse_pos, target_pos): distance = math.sqrt((mouse_pos[0] - target_pos[0])**2 + (mouse_pos[1] - target_pos[1])**2) return distance <= target_radius # Main game loop generate_targets(num_targets) running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.MOUSEBUTTONDOWN: mouse_pos = pygame.mouse.get_pos() for target in targets: if hit_target(mouse_pos, target): target_color = target_hit_color targets.remove(target) generate_targets(1) # Generate a new target break # Draw everything screen.fill(WHITE) for target in targets: pygame.draw.circle(screen, target_color, target, target_radius) target_color = RED # Draw score score_text = font.render("Targets Remaining: " + str(len(targets)), True, BLACK) screen.blit(score_text, (10, 10)) pygame.display.flip() # Quit Pygame pygame.quit()