-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
57 lines (40 loc) · 1.42 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
import sys
from collections import deque
import pygame
from game.score import Score
from game.states.title import Title
from game.constants import DISPLAY_WIDTH, DISPLAY_HEIGHT, FPS, GAME_TITLE
class Game:
def __init__(self) -> None:
pygame.init()
self.score = Score()
self.display = pygame.display.set_mode((DISPLAY_WIDTH, DISPLAY_HEIGHT))
self.clock = pygame.time.Clock()
self.playing = True
self.state_stack = deque()
self.state_stack.append(Title(self))
self.particles = pygame.sprite.Group()
self.delta_time = 0
def run(self):
while self.playing:
pygame.display.set_caption(GAME_TITLE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.playing = False
self.state_stack[-1].event_handler(event)
self.update()
self.draw()
pygame.display.update()
self.delta_time = self.clock.tick(FPS) / 1000
sys.exit()
def update(self):
"""Update current state and particles."""
self.state_stack[-1].update(self.delta_time)
self.particles.update(self.delta_time)
def draw(self):
"""Draw current state and particles."""
self.state_stack[-1].draw(self.display)
self.particles.draw(self.display)
if __name__ == "__main__":
game = Game()
game.run()