-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathgame.py
More file actions
43 lines (36 loc) · 1.13 KB
/
Copy pathgame.py
File metadata and controls
43 lines (36 loc) · 1.13 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
import pygame
import constants
class Game(object):
def __init__(self, screen, states, start_state):
self.done = False
self.screen = screen
self.clock = pygame.time.Clock()
self.fps = constants.FPS
self.states = states
self.state_name = start_state
self.state = self.states[self.state_name]
def event_loop(self):
for event in pygame.event.get():
self.state.get_event(event)
def flip_state(self):
next_state = self.state.next_state
self.state.done = False
self.state_name = next_state
self.state = self.states[self.state_name]
self.state.startup()
def update(self, dt):
if self.state.quit:
self.done = True
elif self.state.done:
self.flip_state()
self.state.update(dt)
def draw(self):
self.screen.fill((0, 0, 0))
self.state.draw(self.screen)
def run(self):
while not self.done:
dt = self.clock.tick(self.fps)
self.event_loop()
self.update(dt)
self.draw()
pygame.display.update()