Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snake-7 #8

Open
Stervar opened this issue Oct 22, 2024 · 0 comments
Open

Snake-7 #8

Stervar opened this issue Oct 22, 2024 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@Stervar
Copy link
Owner

Stervar commented Oct 22, 2024

def animation_loading(stdscr):
"""
Функция анимированной загрузки игры
"""
# Определение ASCII-арта для логотипа
loading_text = [
" _____ _ _____ ",
" / | | | / | ",
" | (
__ _ _ __ | |
___ | | __ __ _ _ __ ___ ___ ",
" \
\ / | '_ \\| __/ _ \\| | |_ |/ _ | ' ` _ \ / _ \",
" ) | (| | | | | || /| || | (| | | | | | | /",
" |
_/ \,
|
| |
|\\| \|\,|| || ||\_|"
]
# Заголовок игры
game_title = "Игра про змейку высшего уровня"

# Подготовка экрана
stdscr.clear()                # Очистка экрана
curses.curs_set(0)           # Скрытие курсора
stdscr.nodelay(1)            # Включение неблокирующего режима

# Параметры анимации
start_time = time.time()              # Время начала анимации
animation_duration = 5                 # Длительность анимации в секундах

while True:
    stdscr.clear()                    # Очистка экрана для каждого кадра
    elapsed_time = time.time() - start_time  # Прошедшее время
    
    # Расчет прогресса анимации (от 0 до 1)
    progress = elapsed_time / animation_duration
    
    if progress <= 1:
        # Анимация постепенного появления текста логотипа
        for i, line in enumerate(loading_text):
            visible_chars = int(len(line) * progress)  # Количество видимых символов
            stdscr.addstr(
                stdscr.getmaxyx()[0] // 2 - len(loading_text) // 2 + i,  # Позиция Y
                stdscr.getmaxyx()[1] // 2 - len(line) // 2,              # Позиция X
                line[:visible_chars]                                      # Видимая часть строки
            )
        
        # Отрисовка прогресс-бара
        bar_length = 30                                    # Длина прогресс-бара
        filled_length = int(bar_length * progress)         # Заполненная часть
        bar = '█' * filled_length + '-' * (bar_length - filled_length)  # Формирование прогресс-бара
        
        # Вывод прогресс-бара
        stdscr.addstr(
            stdscr.getmaxyx()[0] // 2 + len(loading_text) // 2 + 2,  # Позиция Y
            stdscr.getmaxyx()[1] // 2 - bar_length // 2,             # Позиция X
            f"[{bar}] {int(progress * 100)}%"                        # Прогресс-бар и процент
        )
    else:
        # Показ полного логотипа после завершения анимации
        for i, line in enumerate(loading_text):
            stdscr.addstr(
                stdscr.getmaxyx()[0] // 2 - len(loading_text) // 2 + i,
                stdscr.getmaxyx()[1] // 2 - len(line) // 2,
                line
            )
        
        # Показ заголовка игры
        if progress > 0.5:  # Показ заголовка после половины анимации
            title_progress = (progress - 0.5) * 2  # Ускорение анимации заголовка
            visible_title_chars = int(len(game_title) * title_progress)
            stdscr.addstr(
                stdscr.getmaxyx()[0] - 2,
                stdscr.getmaxyx()[1] // 2 - len(game_title) // 2,
                game_title[:visible_title_chars]
            )
    
    # Обновление экрана
    stdscr.refresh()
    
    # Остановка анимации после завершения
    if progress > 1:
        stdscr.refresh()  # Обновление экрана перед задержкой
        time.sleep(1)  # Задержка в 1 секунду
        break
    
    # Задержка между кадрами
    time.sleep(0.05)

В этой функции происходит анимированная загрузка игры с ASCII-артом логотипа и прогресс-баром. Анимация длится 5 секунд и постепенно отображает логотип и прогресс-бар. После завершения анимации отображается заголовок игры.

@Stervar Stervar self-assigned this Oct 22, 2024
@Stervar Stervar added the documentation Improvements or additions to documentation label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant