import pygame import sys # Initialize Pygame pygame.init() # Screen setup WIDTH, HEIGHT = 800, 600 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Coin Collector") # Fonts and colors font = pygame.font.SysFont(None, 48) WHITE = (255, 255, 255) BLACK = (0, 0, 0) # Coin variables coin_count = 0 coin_radius = 15 coin_color = (255, 223, 0) # Gold-like color # Sample coin positions coins = [pygame.Rect(100, 100, 30, 30), pygame.Rect(300, 200, 30, 30), pygame.Rect(500, 300, 30, 30)] # Player setup player = pygame.Rect(50, 50, 40, 40) player_color = (0, 128, 255) speed = 5 clock = pygame.time.Clock() # Game loop running = True while running: screen.fill(BLACK) # Handle events for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Movement controls keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: player.x -= speed if keys[pygame.K_RIGHT]: player.x += speed if keys[pygame.K_UP]: player.y -= speed if keys[pygame.K_DOWN]: player.y += speed # Draw and collect coins for coin in coins[:]: pygame.draw.ellipse(screen, coin_color, coin) if player.colliderect(coin): coins.remove(coin) coin_count += 1 # Draw player pygame.draw.rect(screen, player_color, player) # Render coin count at the top text = font.render(f"Coins: {coin_count}", True, WHITE) screen.blit(text, (10, 10)) pygame.display.flip() clock.tick(60) pygame.quit() sys.exit()