-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
60 lines (48 loc) · 1.59 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 sys
import button
SCREENWIDTH, SCREENHEIGHT = 1920, 1080
FPS = 60
screen = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT))
class Game:
def __init__(self) :
pygame.init()
self.clock = pygame.time.Clock()
self.gameStateManager = GameStateManager('level')
self.start = Start(screen, self.gameStateManager)
self.level = Level(screen, self.gameStateManager)
self.states = {'start': self.start, 'level': self.level}
def run(self):
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
self.states[self.gameStateManager.get_state()].run()
pygame.display.update()
self.clock.tick(FPS)
class Level:
def __init__(self, display, gameStateManager):
self.display = display
self.gameStateManager = gameStateManager
def run(self):
self.display.fill('blue')
keys = pygame.key.get_pressed()
if keys[pygame.K_a]:
self.gameStateManager.set_state('start')
class Start:
def __init__(self, display, gameStateManager):
self.display = display
self.gameStateManager = gameStateManager
def run(self):
self.display.fill('red')
class GameStateManager:
def __init__(self, currentState):
self.currentState = currentState
def get_state(self):
return self.currentState
def set_state(self, state):
self.currentState = state
if __name__ == '__main__':
game = Game()
game.run()