-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
64 lines (51 loc) · 1.37 KB
/
main.py
File metadata and controls
64 lines (51 loc) · 1.37 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
import os
import sys
import pygame
from typing import Tuple
from utils import (
WINDOW_WIDTH,
WINDOW_HEIGHT,
BACKGROUND_COLOR,
FPS,
TITLE_TEXT,
FONT_NAME,
)
from sprites import prepare_sprites
from simulation import Simulation
def main() -> None:
"""Entry point: initialize pygame, create the simulation, and run the main loop."""
pygame.init()
try:
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
except Exception:
# Fallback for environments that need explicit flags
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), pygame.SCALED | pygame.RESIZABLE)
pygame.display.set_caption(TITLE_TEXT)
clock = pygame.time.Clock()
font = pygame.font.Font(FONT_NAME, 28)
small_font = pygame.font.Font(FONT_NAME, 18)
sprites = prepare_sprites()
sim = Simulation(screen, sprites, font, small_font)
running = True
while running:
dt_ms = clock.tick(FPS)
dt = dt_ms / 1000.0
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE or event.key == pygame.K_q:
running = False
elif event.key == pygame.K_r:
sim.reset()
# Update
sim.update(dt)
# Draw
screen.fill(BACKGROUND_COLOR)
sim.draw()
sim.draw_hud(fps_value=clock.get_fps())
pygame.display.flip()
pygame.quit()
sys.exit(0)
if __name__ == "__main__":
main()