/
Dragon925
/
Python-Graphics
Обзор
Документация
Войти
/
Dragon925
/
Python-Graphics
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
lesson_31
game_settings.py
55 строк
2 KB
Alexandr Romanov
Пример выполнения задания 15
22 май 2025, 20:17
22 май 2025, 20:17
b02d03f
Код
Авторство
О чём код?
from pygame import Surface, key, K_SPACE from classes import Dino, Obstacle, Cloud, Ground from random import randint START_FPS = 70 OBSTACLES_SPEED = 10 CLOUD_MIN_SPEED = 2 CLOUD_MAX_SPEED = 10 def check_start(ground_speed: int) -> bool: keys = key.get_pressed() return keys[K_SPACE] and ground_speed == 0 def increase_score(score: int, fps: int, ground_speed: int) -> int: if ground_speed: score += fps / 200 return score def check_game_over(dino: Dino, current_obstacles: list[Obstacle]) -> bool: if dino.rect.collidelist(current_obstacles) != -1: if dino.crash: dino.crash_sound.play() dino.crash = False return True return False def start( dino: Dino, ground: Ground, obstacles: list[Obstacle], clouds: list[Cloud] ) -> tuple[Dino, Ground, list[Obstacle], list[Obstacle], list[Cloud], int, int]: score = 0 ground.speed = OBSTACLES_SPEED fps = START_FPS current_obstacles = [] dino.crash = True for obstacle in obstacles: obstacle.speed = OBSTACLES_SPEED for cloud in clouds: cloud.speed = randint(CLOUD_MIN_SPEED, CLOUD_MAX_SPEED) return dino, ground, obstacles, current_obstacles, clouds, fps, score def game_over( width: int, height: int, dino: Dino, ground: Ground, screen: Surface, text: Surface, obstacles: list[Obstacle], clouds: list[Cloud] ) -> tuple[Dino, Ground, list[Obstacle], list[Cloud]]: ground.speed = 0 for obstacle in obstacles: obstacle.speed = 0 for cloud in clouds: cloud.speed = 0 screen.blit(text, (width // 2 - 230, height // 4)) return dino, ground, obstacles, clouds