-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (35 loc) · 1.14 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
import pygame
from constants import *
import utils
from states import GameState
# TODO: add an animation module for pygame surfaces
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(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((69, 69, 69))
if not states.isEmpty():
states.top().render()
fps = str(round(clock.get_fps(), 2))
small_font.render_to(screen, (WIDTH - 80, 5), fps, (0, 0, 0))
pygame.display.flip()
pygame.quit()