import pygame # Define some colors BLACK = (0, 0, 0) WHITE = (255, 255, 255) GREEN = (0, 255, 0) RED = (255, 0, 0) BLUE = (0, 0, 255) # Define some constants WIDTH = 800 HEIGHT = 600 FPS = 60 GRAVITY = 0.5 # Define some variables x = WIDTH / 2 y = HEIGHT / 2 vx = 0 vy = 0 # Define some functions def draw_dot(x, y): pygame.draw.circle(window, BLACK, (int(x), int(y)), 10) def move_dot(x, y, vx, vy): x += vx y += vy return x, y def apply_gravity(vy): vy += GRAVITY return vy def jump(vy): vy = -10 return vy # Initialize pygame pygame.init() # Create a window # Create a clock clock = pygame.time.Clock() # Create a window window = pygame.display.set_mode((WIDTH, HEIGHT)) # Set window title pygame.display.set_caption("My Game") # Game loop running = True # Set the frame rate clock.tick(FPS) while running: # Process events for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_a: vx = -5 if event.key == pygame.K_d: vx = 5 if event.key == pygame.K_SPACE: vy = jump(vy) if event.type == pygame.KEYUP: if event.key == pygame.K_a: vx = 0 if event.key == pygame.K_d: vx = 0 running = False x, y = move_dot(x, y, vx, vy) vy = apply_gravity(vy) # Render # Clear the screen # Draw the dot draw_dot(x, y) # Update the display # Update # Render window.fill((255, 255, 255)) pygame.display.update() # Close window on quit pygame.quit()