Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- # Define colors
- BLACK = (0, 0, 0)
- WHITE = (255, 255, 255)
- RED = (255, 0, 0)
- # Set the width and height of the screen
- WIDTH = 600
- HEIGHT = 400
- # Initialize Pygame
- pygame.init()
- # Set the font for displaying text
- font = pygame.font.SysFont(None, 48)
- # Create the screen
- screen = pygame.display.set_mode((WIDTH, HEIGHT))
- # Set the title of the game window
- pygame.display.set_caption("Clicker Aim Trainer")
- # Create a clock to control the game's frame rate
- clock = pygame.time.Clock()
- # Set the initial score and target position
- score = 0
- target_pos = (0, 0)
- # Define a function to generate a new target
- def new_target():
- global target_pos
- target_pos = (random.randint(50, WIDTH - 50), random.randint(50, HEIGHT - 50))
- # Define a function to display the score
- def display_score():
- score_text = font.render(f"Score: {score}", True, WHITE)
- screen.blit(score_text, (10, 10))
- # Define a function to draw the target
- def draw_target():
- pygame.draw.circle(screen, RED, target_pos, 25)
- # Define a function to handle mouse clicks
- def handle_click(pos):
- global score
- if abs(pos[0] - target_pos[0]) <= 25 and abs(pos[1] - target_pos[1]) <= 25:
- score += 1
- new_target()
- # Set up the game loop
- done = False
- while not done:
- # Handle events
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- done = True
- elif event.type == pygame.MOUSEBUTTONDOWN:
- handle_click(pygame.mouse.get_pos())
- # Fill the screen with black
- screen.fill(BLACK)
- # Generate a new target if necessary
- if target_pos == (0, 0):
- new_target()
- # Draw the target and display the score
- draw_target()
- display_score()
- # Update the screen
- pygame.display.flip()
- # Limit the game's frame rate
- clock.tick(60)
- # Quit Pygame
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement