-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·50 lines (36 loc) · 1022 Bytes
/
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
#!/usr/bin/python3
import pygame as pg # type: ignore
from pygame.time import Clock # type: ignore
from events import events_map
from config import CHANNELS
def init() -> Clock:
print(events_map)
pg.init()
pg.display.set_mode((1024, 800), pg.RESIZABLE)
pg.mixer.init()
pg.mixer.set_num_channels(CHANNELS)
# Init joystick. Currently only one.
try:
pg.joystick.init()
for j in range(pg.joystick.get_count()):
pg.joystick.Joystick(j).init()
except pg.error:
print("Joystick error")
quit()
return Clock()
def loop(clock: Clock):
while True:
event = pg.event.poll()
if not event.type:
clock.tick(60)
elif event.type in events_map:
print(f"Type: {event.type}")
events_map[event.type].exec(event)
pg.event.clear()
else:
print(f"Ignored: {event.type}")
def main():
clock = init()
loop(clock)
if __name__ == "__main__":
main()