-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
60 lines (43 loc) · 1.38 KB
/
main.py
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
import pygame
import constants
import utils
from states import GameState
fullscreen = False
if fullscreen:
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
else:
screen = pygame.display.set_mode((constants.WIDTH, constants.HEIGHT))
pygame.display.set_caption(constants.TITLE)
running = True if pygame.display.get_surface() is not None else False
# set up clock for limiting framerate and getting dt
clock = pygame.time.Clock()
states = utils.StateStack() # Stack that holds all the States
state_data = dict(screen=screen, states=states)
states.push(GameState(state_data))
# ====== Main Game Loop ======
while running:
clock.tick(constants.FPS)
dt = clock.get_time() / 1000
# Update
if states.isEmpty() is not True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
states.top().update_events(dt, event)
states.top().update(dt)
if states.top().get_quit():
states.top().end_state()
states.pop()
else:
running = False
# Render
screen.fill((255, 255, 255))
if not states.isEmpty():
states.top().render()
fps = str(round(clock.get_fps(), 2))
constants.small_font.render_to(screen, (
constants.WIDTH - 80,
constants.HEIGHT - 25),
fps, (0, 0, 0))
pygame.display.flip()
pygame.quit()