import pygame import random # Initialize Pygame pygame.init() # Define colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (255, 0, 0) # Set up the screen WIDTH, HEIGHT = 800, 600 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("GTA Lite") # Player car player_car = pygame.Rect(WIDTH // 2, HEIGHT // 2, 25, 25) # Enemy cars enemy_cars = [] for _ in range(25): x = random.randint(0, WIDTH - 50) y = random.randint(-HEIGHT, -100) enemy_cars.append(pygame.Rect(x, y, 50, 100)) # Game loop clock = pygame.time.Clock() running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Move player car keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: player_car.x -= 5 if keys[pygame.K_RIGHT]: player_car.x += 5 if keys[pygame.K_UP]: player_car.y -= 5 if keys[pygame.K_DOWN]: player_car.y += 5 # Move enemy cars for enemy_car in enemy_cars: enemy_car.y += 3 if enemy_car.y > HEIGHT: enemy_car.y = random.randint(-HEIGHT, -100) enemy_car.x = random.randint(0, WIDTH - 50) # Check for collisions for enemy_car in enemy_cars: if player_car.colliderect(enemy_car): running = False # Draw everything screen.fill(WHITE) pygame.draw.rect(screen, RED, player_car) for enemy_car in enemy_cars: pygame.draw.rect(screen, BLACK, enemy_car) pygame.display.flip() # Cap the frame rate clock.tick(60) pygame.quit()