-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
49 lines (40 loc) · 1.28 KB
/
game.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
import pygame
import time
from singleton import Singleton
from gamestatemachine import GameStateMachine
from gamestate import MainMenuState, GameOverState
from inputhandler import TheInputHandler
class TheGame(metaclass=Singleton):
window_x: int = 720
window_y: int = 480
surface: pygame.Surface
clock: pygame.time.Clock
score: int
score: int
running: bool
font: pygame.font.Font
gameStateMachine: GameStateMachine
def init(self):
pygame.init()
TheInputHandler().init()
self.surface = pygame.display.set_mode((self.window_x, self.window_y))
self.clock = pygame.time.Clock()
self.font = pygame.font.SysFont("Arial", 64)
self.gameStateMachine = GameStateMachine()
self.gameStateMachine.pushState(MainMenuState())
self.running = True
self.score = 0
def handleEvents(self):
TheInputHandler().update()
def update(self):
self.handleEvents()
self.surface.fill(pygame.Color(0, 0, 0))
self.gameStateMachine.update()
pygame.display.flip()
def quit(self):
self.running = False
def gameOver(self):
self.gameStateMachine.changeState(GameOverState())
def gameLoop(self):
while(self.running):
self.update()