/
ap1k
/
PyGame_Practice
Обзор
Документация
Войти
/
ap1k
/
PyGame_Practice
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/scenes/loading_scene.py
74 строки
2 KB
Roman
The all game
27 май 2025, 15:26
27 май 2025, 15:26
4ea7de9
Код
Авторство
О чём код?
""" LoadingScene class - displays a loading screen while resources are being loaded """ import pygame import threading import time from src.core.scene import Scene from src.utils.resource_loader import ResourceLoader class LoadingScene(Scene): """ Loading scene that displays while game resources are being loaded Implements the Scene interface """ def __init__(self, game): super().__init__(game) self.font = pygame.font.Font(None, 36) self.loading_text = "Loading..." self.loading_dots = 0 self.dot_timer = 0 self.dot_delay = 500 # milliseconds between dot animations self.loading_complete = False # Start loading resources in a separate thread self.loader_thread = threading.Thread(target=self._load_resources) self.loader_thread.daemon = True self.loader_thread.start() def _load_resources(self): """Load all game resources in a separate thread""" # Create a resource loader loader = ResourceLoader() # Load all game resources loader.load_all() # Give a small delay to ensure everything is loaded time.sleep(1.5) # Mark loading as complete self.loading_complete = True def update(self): """Update the loading animation""" current_time = pygame.time.get_ticks() # Update the loading dots animation if current_time - self.dot_timer > self.dot_delay: self.loading_dots = (self.loading_dots + 1) % 4 self.dot_timer = current_time # If loading is complete, change to the game scene if self.loading_complete: self.game.change_scene("game") def render(self, screen): """Render the loading screen""" # Fill the screen with black screen.fill(self.game.config.colors["black"]) # Create the loading text with animated dots dots = "." * self.loading_dots text = self.font.render(f"Loading{dots}", True, self.game.config.colors["white"]) # Center the text on the screen text_rect = text.get_rect(center=(self.game.width // 2, self.game.height // 2)) # Draw the text screen.blit(text, text_rect) def handle_event(self, event): """Handle pygame events""" # No events to handle in the loading scene pass