Untitled
unknown
plain_text
a year ago
1.1 kB
20
Indexable
Never
import pygame import random # Initialize Pygame pygame.init() # Set up the game window width = 800 height = 600 screen = pygame.display.set_mode((width, height)) pygame.display.set_caption("Car Racing Game") # Load images car_img = pygame.image.load("car.png").convert_alpha() car_rect = car_img.get_rect() car_rect.center = (width/2, height-100) road_img = pygame.image.load("road.png").convert_alpha() road_y = 0 # Set up clock clock = pygame.time.Clock() # Game loop while True: # Handle events for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() # Move the car keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: car_rect.x -= 5 elif keys[pygame.K_RIGHT]: car_rect.x += 5 # Move the road road_y += 10 if road_y > height: road_y = 0 # Draw the game objects screen.blit(road_img, (0, road_y)) screen.blit(car_img, car_rect) # Update the display pygame.display.update() # Set the frame rate clock.tick(60)