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


import turtle
import random

# Настройка окна
window = turtle.Screen()
window.title("Ловец объектов")
window.bgcolor("sky blue")
window.setup(width=600, height=600)
window.tracer(0)  # Отключаем автоматическое обновление для плавности

# --- Игрок (корзинка) ---
player = turtle.Turtle()
player.shape("square")
player.shapesize(stretch_wid=1, stretch_len=3)
player.color("brown")
player.penup()
player.goto(0, -250)

# --- Падающий объект ---
faller = turtle.Turtle()
faller.shape("circle")
faller.color("red")
faller.shapesize(1.5)
faller.penup()
faller.goto(random.randint(-280, 280), 280)

# --- Счётчик очков ---
score = 0
score_display = turtle.Turtle()
score_display.hideturtle()
score_display.color("white")
score_display.penup()
score_display.goto(0, 260)
score_display.write(f"Счёт: {score}", align="center", font=("Arial", 20, "bold"))

# --- Текст Game Over ---
game_over_text = turtle.Turtle()
game_over_text.hideturtle()
game_over_text.penup()
game_over_text.color("red")

# --- Движение игрока ---
def move_left():
    x = player.xcor()
    if x > -260:  # ограничение по экрану
        player.setx(x - 30)

def move_right():
    x = player.xcor()
    if x < 260:
        player.setx(x + 30)

# --- Сброс игры ---
def restart_game():
    global score, game_active
    score = 0
    game_active = True
    update_score()
    game_over_text.clear()
    faller.goto(random.randint(-280, 280), 280)
    player.goto(0, -250)

def exit_game():
    window.bye()

# --- Обновление счёта на экране ---
def update_score():
    score_display.clear()
    score_display.write(f"Счёт: {score}", align="center", font=("Arial", 20, "bold"))

# --- Управление ---
window.listen()
window.onkeypress(move_left, "Left")
window.onkeypress(move_right, "Right")

# --- Игровой цикл ---
game_active = True
faller_speed = 10

while True:
    window.update()
    
    if game_active:
        # Движение падающего объекта
        faller.sety(faller.ycor() - faller_speed)
        
        # Проверка столкновения с игроком
        if (faller.ycor() - 20 < player.ycor() + 20 and
            abs(faller.xcor() - player.xcor()) < 40):
            score += 1
            update_score()
            faller.goto(random.randint(-280, 280), 280)
            # Увеличиваем скорость каждые 5 очков
            if score % 5 == 0:
                faller_speed += 2
        
        # Проверка, что объект упал на землю (пропущен)
        if faller.ycor() < -280:
            game_active = False
            game_over_text.write("GAME OVER", align="center", font=("Arial", 36, "bold"))
            game_over_text.goto(0, 0)
            # Показываем опции рестарта
            game_over_text.goto(0, -50)
            game_over_text.write("Нажми R для рестарта или Q для выхода", 
                                 align="center", font=("Arial", 14, "normal"))
            game_over_text.goto(0, 0)
    
    # Обработка действий после Game Over
    if not game_active:
        window.onkeypress(restart_game, "r")
        window.onkeypress(exit_game, "q")
    
    turtle.delay(10)