Untitled

 avatar
unknown
plain_text
2 years ago
2.6 kB
10
Indexable
import pygame
import random

# Initialize pygame
pygame.init()

# Set the window size
window_size = (800, 600)
screen = pygame.display.set_mode(window_size)

# Set the game title
pygame.display.set_caption("Frogger")

# Set the colors
white = (255, 255, 255)
green = (0, 255, 0)
red = (255, 0, 0)

# Load the images
frog_image = pygame.image.load("frog.png")
car_image = pygame.image.load("car.png")
log_image = pygame.image.load("log.png")
water_image = pygame.Surface((800, 200))
water_image.fill((0, 0, 255))

# Set the font
font = pygame.font.Font(None, 36)

# Set the initial score and lives
score = 0
lives = 3

# Set the speed of the frog, cars, and logs
frog_speed = 5
car_speed = 10
log_speed = 5

# Set the initial position of the frog
frog_x = 375
frog_y = 550

# Create a list of cars
car_list = []
for i in range(5):
    car_x = random.randint(0, 700)
    car_y = random.randint(100, 400)
    car_list.append([car_x, car_y])

# Create a list of logs
log_list = []
for i in range(5):
    log_x = random.randint(0, 700)
    log_y = random.randint(50, 250)
    log_list.append([log_x, log_y])

# Create a clock
clock = pygame.time.Clock()

# Set the game loop
game_over = False
while not game_over:
    # Handle events
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            game_over = True

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                frog_y -= frog_speed
            elif event.key == pygame.K_DOWN:
                frog_y += frog_speed
            elif event.key == pygame.K_LEFT:
                frog_x -= frog_speed
            elif event.key == pygame.K_RIGHT:
                frog_x += frog_speed

    # Draw the background
    screen.fill(white)
    screen.blit(water_image, (0, 0))

    # Draw the cars
    for car in car_list:
        screen.blit(car_image, car)
        car[0] -= car_speed
        if car[0] < -50:
            car_list.remove(car)
            new_car_x = random.randint(800, 1200)
            new_car_y = random.randint(100, 400)
            car_list.append([new_car_x, new_car_y])

    # Draw the logs
    for log in log_list:
        screen.blit(log_image, log)
        log[0] += log_speed
        if log[0] > 800:
            log_list.remove(log)
            new_log_x = random.randint(-400, -50)
            new_log_y = random.randint(50, 250)
            log_list.append([new_log_x, new_log_y])

    # Draw the frog
    screen.blit(frog_image, (frog_x, frog_y))

    # Check for collisions with cars
    for car in car_list:
        if frog_x
Editor is loading...