-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
45 lines (39 loc) · 1.22 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
from asciimatics.screen import Screen
from asciimatics.event import KeyboardEvent
from field import Field
import time
import modes
import Input
import json
with open('config.json','r') as f:
js = json.load(f)['client']['controls']
for action, key in js.items():
Input.bind(key, action)
def background(screen,color=0):
for y in range(screen.height):
screen.print_at(' '*screen.width, 0, y, bg=color)
def main(screen):
framerate = 1/60
dt = 0
mode = modes.MainMenu(screen, Input, True)
while True:
start = time.perf_counter()
Input.update()
background(screen)
ev = screen.get_event()
key = ev.key_code if isinstance(ev, KeyboardEvent) else None
if key in (ord('Q'), ord('q')):
if hasattr(mode,'quit'):
mode.quit()
return
elif key in (ord('E'), ord('e')):
if hasattr(mode,'quit'):
mode.quit()
mode = modes.MainMenu(screen, Input)
mode.run(key, dt)
screen.refresh()
end = time.perf_counter()
if end - start < framerate:
time.sleep(framerate - (end - start))
dt = time.perf_counter() - start
Screen.wrapper(main)