import pygame import sys # Initialize Pygame pygame.init() # Set up the screen screen_width = 400 screen_height = 300 screen = pygame.display.set_mode((screen_width, screen_height)) pygame.display.set_caption("Simple Pygame Example") # Set up colors RED = (255, 0, 0) # Set up the square square_size = 50 square_x = (screen_width - square_size) // 2 square_y = (screen_height - square_size) // 2 # Main game loop running = True while running: # Handle events for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: square_x += 10 # Clear the screen screen.fill((0, 0, 0)) # Draw the square pygame.draw.rect(screen, RED, (square_x, square_y, square_size, square_size)) # Update the display pygame.display.flip() # Quit Pygame pygame.quit() sys.exit()