File size: 1,091 Bytes
c02cd3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
Bootstrap helpers for initializing Pygame with project defaults.

This keeps startup logic separate from the gameplay code so we can evolve
menus and settings without touching the core loop.
"""

from __future__ import annotations

import os
from typing import Dict, Tuple

from config import constants
from config.settings_schema import DEFAULT_SETTINGS

os.environ.setdefault("PYGAME_HIDE_SUPPORT_PROMPT", "1")


def init_pygame(settings: Dict[str, object] | None = None):
    import pygame

    pygame.init()
    try:
        pygame.mixer.init()
    except Exception:
        # Audio is optional; game will still run without mixer.
        pass
    data = dict(DEFAULT_SETTINGS)
    if settings:
        data.update(settings)

    resolution: Tuple[int, int] = data.get("resolution", constants.BASE_RESOLUTION)  # type: ignore[assignment]
    flags = pygame.FULLSCREEN if data.get("fullscreen") else 0
    screen = pygame.display.set_mode(resolution, flags)
    pygame.display.set_caption("SCRAP COLLECTOR - Prototype")

    clock = pygame.time.Clock()
    return screen, clock, data