Untitled
unknown
python
2 years ago
1.1 kB
3
Indexable
import pygame import random # Initialize Pygame pygame.init() # Set up the screen screen_width = 800 screen_height = 600 screen = pygame.display.set_mode((screen_width, screen_height)) pygame.display.set_caption("Racing Game") # Load images car_image = pygame.image.load("car.png") car_width, car_height = car_image.get_rect().size # Set car position car_x = (screen_width - car_width) // 2 car_y = screen_height - car_height - 20 # Set initial variables clock = pygame.time.Clock() game_over = False # Game loop while not game_over: # Process events for event in pygame.event.get(): if event.type == pygame.QUIT: game_over = True # Move the car keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: car_x -= 5 if keys[pygame.K_RIGHT]: car_x += 5 # Update screen screen.fill((255, 255, 255)) # Fill screen with white color screen.blit(car_image, (car_x, car_y)) # Draw the car pygame.display.flip() # Update the screen clock.tick(60) # Limit the game to 60 FPS # Quit the game pygame.quit()
Editor is loading...