-
Notifications
You must be signed in to change notification settings - Fork 0
/
InteractivePlay.py
50 lines (36 loc) · 1003 Bytes
/
InteractivePlay.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
from Game import GameCore
import cv2
WINNAME = "fruit-merger"
FPS = 60
FAST_MODE = False
# FAST_MODE = False
gc = GameCore()
def onTick():
gc.update(1.0 / FPS)
gc.draw(debug=True)
# gc.draw()
cv2.imshow(WINNAME, gc.screen)
def onMouse(event, x, y, flags, param=None):
if event == cv2.EVENT_LBUTTONDOWN:
gc.click((x, y))
if FAST_MODE:
gc.update_until_stable(FPS)
elif event == cv2.EVENT_MOUSEMOVE:
gc.move((x, y))
elif event == cv2.EVENT_RBUTTONDOWN:
# gc.rclick((x, y))
gc.save_screen()
if __name__ == "__main__":
cv2.namedWindow(WINNAME)
cv2.setMouseCallback(WINNAME, onMouse)
while True:
onTick()
key = cv2.waitKey(int(1000 / FPS))
if key != -1:
print(key)
if key == ord("q") or key == 27:
break
# close the window
if cv2.getWindowProperty(WINNAME, cv2.WND_PROP_VISIBLE) <= 0:
break
cv2.destroyAllWindows()