import pygame import sys import time # Initialize Pygame pygame.init() # Set up the screen WIDTH, HEIGHT = 800, 600 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Acceleration Box with Centered Ring") # Colors WHITE = (255, 255, 255) RED = (255, 0, 0) BLUE = (0, 0, 255) # Player attributes player_size = 50 player_pos = [WIDTH // 2, HEIGHT // 2] player_speed = [0, 0] acceleration = 0.5 friction = 0.1 # Ring attributes ring_radius = 100 ring_thickness = 10 # Main game loop running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Movement control keys = pygame.key.get_pressed() if keys[pygame.K_a]: player_speed[0] -= acceleration if keys[pygame.K_d]: player_speed[0] += acceleration if keys[pygame.K_w]: player_speed[1] -= acceleration if keys[pygame.K_s]: player_speed[1] += acceleration # Apply friction player_speed[0] *= (1 - friction) player_speed[1] *= (1 - friction) # Update player position player_pos[0] += player_speed[0] player_pos[1] += player_speed[1] # Draw everything screen.fill(WHITE) # Draw player box pygame.draw.rect(screen, RED, (player_pos[0], player_pos[1], player_size, player_size)) # Calculate ring position ring_center = (player_pos[0] + player_size // 2, player_pos[1] + player_size // 2) # Draw ring pygame.draw.circle(screen, BLUE, ring_center, ring_radius, ring_thickness) pygame.display.update() # Frame rate pygame.time.Clock().tick(60) # Quit Pygame pygame.quit() sys.exit()