-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (42 loc) · 1.28 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
import pygame as py
import config as cfg
import states
# load pygame display
py.init()
# Screen dictionary
states = {
"MENU": states.menu.Menu(),
"LOGIN": states.login.Login(),
"LOBBY": states.lobby.Lobby(),
"WAIT": states.wait.Wait(),
"GAMEPLAY": states.gameplay.Gameplay(),
"RESULT": states.result.Result(),
"LOCAL": states.local.Local(),
"HIGHSCORES" : states.highscores.Highscores()
}
class Game:
def __init__(self, states, start_state):
# states = object dictionary, start_state = single object
self.states = states
self.state = self.states[start_state]
def event_loop(self):
for event in py.event.get():
self.state.get_event(event)
def update(self):
# check whether the screen needs to be changed
if self.state.next_state:
change_state = self.state.next_state
self.state.next_state = None
self.state = self.states[change_state]
def draw(self):
self.state.state_draw(cfg.window)
def run(self):
while not self.state.done:
py.time.Clock().tick(10)
self.event_loop()
self.update()
self.draw()
py.display.update()
py.quit()
game = Game(states, "MENU")
game.run()