-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
86 lines (78 loc) · 3.1 KB
/
Copy pathmain.py
File metadata and controls
86 lines (78 loc) · 3.1 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import sys
import os
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
# Set DPI awareness on Windows before importing pygame
# This prevents Windows from applying its own scaling which causes resolution issues in the exe
if sys.platform == 'win32':
try:
import ctypes
# Try to set DPI awareness for Windows 8.1 and later
try:
ctypes.windll.shcore.SetProcessDpiAwareness(2) # PROCESS_PER_MONITOR_DPI_AWARE
print("DPI awareness set: PROCESS_PER_MONITOR_DPI_AWARE")
except Exception:
# Fallback for Windows Vista through 8.0
try:
ctypes.windll.user32.SetProcessDPIAware()
print("DPI awareness set: SetProcessDPIAware")
except Exception:
print("Could not set DPI awareness")
except Exception as e:
print(f"DPI awareness setup failed: {e}")
import pygame
from core.game_engine import GameEngine
from utility.resource_path import resource_path
from core.scene_manager import SceneManager
from entities.player import Player
from ui.title_screen import TitleScreen, InfoScreen
from ui.menus import Button
from core.IntroScene import IntroScene # Import the IntroScene
from ui.loading_screen import LoadingScreen
if __name__ == "__main__":
try:
# Set SDL_VIDEO_CENTERED before pygame.init() for proper window centering
os.environ['SDL_VIDEO_CENTERED'] = '1'
print("Initializing pygame...")
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode((800, 600)) # Temporary screen for loading
pygame.mouse.set_visible(False) # Hide the system cursor
if "-dev" not in sys.argv:
print("Loading screen...")
loading_screen = LoadingScreen(screen)
loading_screen.run()
print("Loading music...")
pygame.mixer.music.load(resource_path("data/corrupted.wav"))
pygame.mixer.music.play(-1) # -1 means loop indefinitely
print("Creating game engine...")
game = GameEngine()
scene_manager = game.scene_manager
print("Initializing scenes...")
# Initialize TitleScreen and set it as the initial scene
title_screen = TitleScreen(game)
info_screen = InfoScreen(game)
intro_scene = IntroScene(game) # Initialize the IntroScene
game.info_screen = info_screen
scene_manager.add_scene("intro_scene", intro_scene) # Add the IntroScene to the SceneManager
from config.constants import STATE_TITLE_SCREEN
print("Starting game loop...")
game.run()
pygame.quit()
print("Game exited normally.")
except Exception as e:
print(f"ERROR: {e}")
import traceback
traceback.print_exc()
finally:
print("\n" + "="*50)
# Only prompt for input if stdin is available (dev mode or console)
if sys.stdin and hasattr(sys.stdin, 'fileno'):
try:
input("Press Enter to exit...")
except:
pass
try:
pygame.quit()
except:
pass
sys.exit(1)