Загрузка данных


import pygame

import random

pygame.init()

pygame.mixer.init()

WIDTH, HEIGHT = 1060, 600

screen = pygame.display.set_mode((WIDTH, HEIGHT))

pygame.display.set_caption("Поймай 67!")

WHITE = (255, 255, 255)

BLACK = (0, 0, 0)

BLUE = (0, 0, 255)

RED = (255, 0, 0)

murino_bg = pygame.image.load("murino.jpg")

murino_bg = pygame.transform.scale(murino_bg, (WIDTH, HEIGHT))

basket_image = pygame.image.load("basket.jpg")

tazik_image = pygame.image.load("tazik 2.jpg")

fog_image = pygame.image.load("fog.jpg")

mit_image = pygame.image.load("mitisci.jpg")

cheremsha_image = pygame.image.load("cheremsha.jpg")

vinograd_image = pygame.image.load("vinograd.jpg")

sound_67 = pygame.mixer.Sound("67.mp3")

sound_vinograd = pygame.mixer.Sound("vinograd.mp3") 
sound_played = False

sound_played_vinograd = False  

basket_width = 120

basket_height = 80

basket_x = WIDTH // 2 - basket_width // 2

basket_y = HEIGHT - basket_height - 10

basket_speed = 10

fog_size = 60

fog_speed = 5

cheremsha_size = 50

cheremsha_speed = 5

vinograd_size = 70

ball_radius = 20

ball_speed = 6

ball_x = random.randint(ball_radius, WIDTH - ball_radius)

ball_y = random.randint(-400, -ball_radius)

red_orb_radius = 20

red_orb_speed = 7

red_orb_x = random.randint(red_orb_radius, WIDTH - red_orb_radius)

red_orb_y = random.randint(-500, -red_orb_radius)

fog_image = pygame.transform.scale(fog_image, (fog_size, fog_size))

mit_image = pygame.transform.scale(mit_image, (1060, 600))

cheremsha_image = pygame.transform.scale(cheremsha_image, (cheremsha_size, cheremsha_size))

vinograd_image = pygame.transform.scale(vinograd_image, (vinograd_size, vinograd_size))

fog1_x, fog1_y = random.randint(0, WIDTH - fog_size), random.randint(-200, -fog_size)

fog2_x, fog2_y = random.randint(0, WIDTH - fog_size), random.randint(-400, -fog_size)

fog3_x, fog3_y = random.randint(0, WIDTH - fog_size), random.randint(-600, -fog_size)

cheremsha_x = random.randint(0, WIDTH - cheremsha_size)

cheremsha_y = random.randint(-800, -cheremsha_size)

vinograd_x = random.randint(0, WIDTH - vinograd_size)

vinograd_y = -100

vinograd_speed = 3

vinograd_spawned = False

score = 0

font = pygame.font.SysFont(None, 36)

menu_font = pygame.font.SysFont(None, 60)

clock = pygame.time.Clock()

FPS = 60

def show_win_screen():

    win_running = True

    while win_running:

        screen.fill(WHITE)

        line1 = font.render("Вы хотели собрать зайцев,", True, BLACK)

        line2 = menu_font.render("а нашли нечто большее... Виноград", True, RED)

        screen.blit(line1, (WIDTH // 2 - line1.get_width() // 2, HEIGHT // 2 - 60))

        screen.blit(line2, (WIDTH // 2 - line2.get_width() // 2, HEIGHT // 2))

        for event in pygame.event.get():

            if event.type == pygame.QUIT:

                pygame.quit()

                exit()

            if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN:

                win_running = False

        pygame.display.flip()

        clock.tick(FPS)

def show_menu():

    menu_running = True

    button_rect = pygame.Rect(WIDTH // 2 - 100, HEIGHT // 2 - 25, 200, 50)

    while menu_running:

        screen.blit(murino_bg, (0, 0))

        pygame.draw.rect(screen, WHITE, button_rect)

        pygame.draw.rect(screen, BLACK, button_rect, 2)

        btn_text = font.render("ВОЙТИ", True, BLACK)

        screen.blit(btn_text, (button_rect.centerx - btn_text.get_width() // 2, button_rect.centery - btn_text.get_height() // 2))

        title_text = menu_font.render("А не собрать ли нам зайцев", True, WHITE)

        screen.blit(title_text, (WIDTH // 2 - title_text.get_width() // 2, 100))

        for event in pygame.event.get():

            if event.type == pygame.QUIT:

                pygame.quit()

                exit()

            if event.type == pygame.MOUSEBUTTONDOWN:

                if button_rect.collidepoint(event.pos):

                    menu_running = False

        pygame.display.flip()

        clock.tick(FPS)

show_menu()

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] and basket_x > 0:

        basket_x -= basket_speed

    if keys[pygame.K_RIGHT] and basket_x < WIDTH - basket_width:

        basket_x += basket_speed

    if score < 100:

        fog1_y += fog_speed

        fog2_y += fog_speed

        fog3_y += fog_speed

        cheremsha_y += cheremsha_speed

        ball_y += ball_speed

        red_orb_y += red_orb_speed

        if fog1_y > HEIGHT: fog1_x, fog1_y = random.randint(0, WIDTH - fog_size), random.randint(-100, -fog_size)

        if fog2_y > HEIGHT: fog2_x, fog2_y = random.randint(0, WIDTH - fog_size), random.randint(-100, -fog_size)

        if fog3_y > HEIGHT: fog3_x, fog3_y = random.randint(0, WIDTH - fog_size), random.randint(-100, -fog_size)

        if cheremsha_y > HEIGHT: cheremsha_x, cheremsha_y = random.randint(0, WIDTH - cheremsha_size), random.randint(-100, -cheremsha_size)

        if ball_y > HEIGHT: ball_x, ball_y = random.randint(ball_radius, WIDTH - ball_radius), random.randint(-300, -ball_radius)

        if red_orb_y > HEIGHT: red_orb_x, red_orb_y = random.randint(red_orb_radius, WIDTH - red_orb_radius), random.randint(-400, -red_orb_radius)

    else:

        vinograd_spawned = True

        if not sound_played_vinograd:  

            sound_vinograd.play()      

            sound_played_vinograd = True  

        if vinograd_y < HEIGHT + 100:

            vinograd_y += vinograd_speed

    basket_rect = pygame.Rect(basket_x, basket_y, basket_width, basket_height)

    if score < 100:

        if basket_rect.colliderect(pygame.Rect(fog1_x, fog1_y, fog_size, fog_size)):

            score += 1

            fog1_x, fog1_y = random.randint(0, WIDTH - fog_size), random.randint(-100, -fog_size)

        if basket_rect.colliderect(pygame.Rect(fog2_x, fog2_y, fog_size, fog_size)):

            score += 1

            fog2_x, fog2_y = random.randint(0, WIDTH - fog_size), random.randint(-100, -fog_size)

        if basket_rect.colliderect(pygame.Rect(fog3_x, fog3_y, fog_size, fog_size)):

            score += 1

            fog3_x, fog3_y = random.randint(0, WIDTH - fog_size), random.randint(-100, -fog_size)

        if basket_rect.colliderect(pygame.Rect(cheremsha_x, cheremsha_y, cheremsha_size, cheremsha_size)):

            score -= 1

            cheremsha_x, cheremsha_y = random.randint(0, WIDTH - cheremsha_size), random.randint(-100, -cheremsha_size)

        ball_rect = pygame.Rect(ball_x - ball_radius, ball_y - ball_radius, ball_radius * 2, ball_radius * 2)

        if basket_rect.colliderect(ball_rect):

            basket_width += random.randint(10, 20)

            ball_x, ball_y = random.randint(ball_radius, WIDTH - ball_radius), random.randint(-300, -ball_radius)

        red_orb_rect = pygame.Rect(red_orb_x - red_orb_radius, red_orb_y - red_orb_radius, red_orb_radius * 2, red_orb_radius * 2)

        if basket_rect.colliderect(red_orb_rect):

            basket_width = max(30, basket_width - random.randint(10, 20))

            red_orb_x, red_orb_y = random.randint(red_orb_radius, WIDTH - red_orb_radius), random.randint(-400, -red_orb_radius)

    if vinograd_spawned and basket_rect.colliderect(pygame.Rect(vinograd_x, vinograd_y, vinograd_size, vinograd_size)):

        show_win_screen()

    if score == 67 and not sound_played:

        sound_67.play()

        sound_played = True

    elif score != 67:

        sound_played = False

    screen.blit(mit_image, (0,0))

    if score >= 50:

        current_basket_img = pygame.transform.scale(tazik_image, (basket_width, basket_height))

    else:

        current_basket_img = pygame.transform.scale(basket_image, (basket_width, basket_height))

    screen.blit(current_basket_img, (basket_x, basket_y))

    if score < 100:

        screen.blit(fog_image, (fog1_x, fog1_y))

        screen.blit(fog_image, (fog2_x, fog2_y))

        screen.blit(fog_image, (fog3_x, fog3_y))

        screen.blit(cheremsha_image, (cheremsha_x, cheremsha_y))

        pygame.draw.circle(screen, BLUE, (ball_x, ball_y), ball_radius)

        pygame.draw.circle(screen, RED, (red_orb_x, red_orb_y), red_orb_radius)

    if vinograd_spawned:

        screen.blit(vinograd_image, (vinograd_x, vinograd_y))

    score_text = font.render(f"Счёт: {score}", True, BLACK)

    screen.blit(score_text, (10, 10))

    pygame.display.flip()

    clock.tick(FPS)

pygame.quit()