import pygame import sys # Initialize Pygame pygame.init() # Set up display width, height = 800, 600 window = pygame.display.set_mode((width, height)) pygame.display.set_caption("Stick Man Playing Basketball") # Colors white = (255, 255, 255) black = (0, 0, 0) green = (0, 255, 0) red = (255, 0, 0) orange = (255, 165, 0) # Function to draw the stick man def draw_stick_man(surface, x, y): # Head pygame.draw.circle(surface, black, (x, y - 50), 20, 2) # Body pygame.draw.line(surface, black, (x, y - 30), (x, y + 40), 2) # Arms pygame.draw.line(surface, black, (x - 30, y), (x + 30, y), 2) # Legs pygame.draw.line(surface, black, (x, y + 40), (x - 20, y + 80), 2) pygame.draw.line(surface, black, (x, y + 40), (x + 20, y + 80), 2) # Function to draw the watermelon slice def draw_watermelon_slice(surface, x, y): pygame.draw.polygon(surface, green, [(x - 20, y), (x + 20, y), (x, y - 20)]) pygame.draw.polygon(surface, red, [(x - 18, y), (x + 18, y), (x, y - 18)]) # Function to draw the basketball def draw_basketball(surface, x, y): pygame.draw.circle(surface, orange, (x, y), 15) # Adding lines to make it look like a basketball pygame.draw.line(surface, black, (x - 15, y), (x + 15, y), 2) pygame.draw.line(surface, black, (x, y - 15), (x, y + 15), 2) pygame.draw.arc(surface, black, (x - 15, y - 15, 30, 30), 0, 3.14, 2) pygame.draw.arc(surface, black, (x - 15, y - 15, 30, 30), 3.14, 6.28, 2) # Game loop running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Fill the background window.fill(white) # Draw stick man at the center of the screen holding a watermelon slice stick_man_x, stick_man_y = width // 2, height // 2 draw_stick_man(window, stick_man_x, stick_man_y) draw_watermelon_slice(window, stick_man_x + 30, stick_man_y) # Draw basketball near the feet of the stick man draw_basketball(window, stick_man_x, stick_man_y + 100) # Update the display pygame.display.flip() # Quit Pygame pygame.quit() sys.exit()