Untitled

mail@pastecode.io avatarunknown
plain_text
a month ago
1.1 kB
1
Indexable
Never
import pygame
import random

# Initialize Pygame
pygame.init()

# Set up display
width, height = 800, 600
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Hill Climb Racing")

# Colors
white = (255, 255, 255)
black = (0, 0, 0)
green = (0, 255, 0)

# Car properties
car_width = 50
car_height = 80
car_x = width // 2 - car_width // 2
car_y = height - car_height - 10
car_speed = 5

# Game loop
clock = pygame.time.Clock()
running = True

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    keys = pygame.key.get_pressed()
    if keys[pygame.K_LEFT]:
        car_x -= car_speed
    if keys[pygame.K_RIGHT]:
        car_x += car_speed

    # Clear the screen
    screen.fill(white)
    
    # Draw hills
    hill_color = green
    pygame.draw.rect(screen, hill_color, (0, height - 100, width, 100))
    
    # Draw car
    pygame.draw.rect(screen, black, (car_x, car_y, car_width, car_height))

    pygame.display.update()
    clock.tick(60)

pygame.quit()