Untitled
unknown
plain_text
a month ago
1.5 kB
3
Indexable
import pygame import random # Initialize Pygame pygame.init() # Set up the display width, height = 800, 600 screen = pygame.display.set_mode((width, height)) pygame.display.set_caption('Indian Car Game') # Colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (255, 0, 0) GREEN = (0, 255, 0) # Car settings car_width = 50 car_height = 100 car_x = width // 2 - car_width // 2 car_y = height - car_height - 10 car_speed = 5 # Game loop flag running = True # Load car image (ensure the image is in the same directory or specify the correct path) car_img = pygame.image.load('indian_car.png') car_img = pygame.transform.scale(car_img, (car_width, car_height)) # Function to draw the car def draw_car(x, y): screen.blit(car_img, (x, y)) # Main game loop clock = pygame.time.Clock() while running: # Handle events for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Handle car movement keys = pygame.key.get_pressed() if keys[pygame.K_LEFT] and car_x > 0: car_x -= car_speed if keys[pygame.K_RIGHT] and car_x < width - car_width: car_x += car_speed # Fill the screen with a color screen.fill(WHITE) # Draw the car draw_car(car_x, car_y) # Update the display pygame.display.update() # Set the frames per second clock.tick(60) # Quit Pygame pygame.quit()
Editor is loading...
Leave a Comment