-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (35 loc) · 1.21 KB
/
Copy pathmain.py
File metadata and controls
48 lines (35 loc) · 1.21 KB
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
import os
import sys
import time
from ui import Screen
from demo.scenes import TitleScene
TICK = 1 / 30 # ~33ms per frame
def main():
restart = False
try:
with Screen() as screen:
scene = TitleScene(screen)
scene.enter()
last = time.monotonic()
while scene is not None:
now = time.monotonic()
dt = now - last
last = now
next_scene = scene.update(dt)
if next_scene is not None and next_scene is not scene:
next_scene.enter()
scene = next_scene
scene.draw()
key = screen.read_key(timeout=TICK)
if not key: continue
if key.is_sequence and key.name == 'KEY_F5':
restart = True
break
next_scene = scene.handle_key(key)
if next_scene is not scene:
if next_scene is None: break
next_scene.enter()
scene = next_scene
except KeyboardInterrupt: pass
if restart: os.execv(sys.executable, [sys.executable] + sys.argv)
if __name__ == '__main__': main()