/
Dragon925
/
Python-Graphics
Обзор
Документация
Войти
/
Dragon925
/
Python-Graphics
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
lesson_31
dino.py
71 строка
2 KB
Alexandr Romanov
Пример выполнения задания 16
22 май 2025, 20:18
22 май 2025, 20:18
421a7da
Код
Авторство
О чём код?
import pygame import display import moving import creation import edit_obstacles import game_settings from classes import Obstacle # Параметры игрового поля и fps WIDTH, HEIGHT = 1400, 600 START_FPS = 70 OBSTACLES_SPEED = 10 CLOUD_MIN_SPEED = 2 CLOUD_MAX_SPEED = 10 GREY = pygame.Color("darkslategrey") fps = START_FPS pygame.init() screen = pygame.display.set_mode((WIDTH, HEIGHT)) clock = pygame.time.Clock() dino, ground, clouds, obstacles = creation.create_world( WIDTH, HEIGHT, -10, 0.25, 0, 4, 0, 0, 9, 0 ) current_obstacles: list[Obstacle] = [] score = 0 score_font = pygame.font.SysFont("Arial", 20) game_over_font = pygame.font.SysFont(None, 100) game_over = game_over_font.render("GAME OVER", True, GREY) timer = 1 display.add_background_music("music/background.mp3") while True: # Выход по нажатию крестика for event in pygame.event.get(): if event.type == pygame.QUIT: exit() if game_settings.check_start(ground.speed): dino, ground, obstacles, current_obstacles, clouds, fps, score = game_settings.start(dino, ground, obstacles, clouds) current_obstacles = edit_obstacles.check_new_obstacles(current_obstacles, obstacles, WIDTH) display.draw_world(screen, dino, ground, clouds, current_obstacles) moving.move(WIDTH, HEIGHT, dino, ground, clouds, current_obstacles) current_obstacles = edit_obstacles.delete_first_obstacle(current_obstacles) score_text = score_font.render(str(int(score)), True, GREY) screen.blit(score_text, (10, 10)) if game_settings.check_game_over(dino, current_obstacles): dino, ground, obstacles, clouds = game_settings.game_over( WIDTH, HEIGHT, dino, ground, screen, game_over, obstacles, clouds ) if timer % (fps // 10) == 0: dino.animate() timer = (timer + 1) % fps score = game_settings.increase_score(score, fps, ground.speed) pygame.display.update() clock.tick(fps + score // 10)