-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovement_crossy_road.py
66 lines (56 loc) · 1.8 KB
/
movement_crossy_road.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import pyautogui
import time
import constants_crossy_road as const
pyautogui.PAUSE = const.PY_PAUSE
last_move_time = 0
def forward():
global last_move_time
time_since_last_move = time.time() - last_move_time
if(time_since_last_move >= const.MOVE_TIME):
pyautogui.keyDown('up')
time.sleep(const.PRESS_TIME)
pyautogui.keyUp('up')
last_move_time = time.time()
def left():
global last_move_time
time_since_last_move = time.time() - last_move_time
if(time_since_last_move >= const.MOVE_TIME):
pyautogui.keyDown('left')
time.sleep(const.PRESS_TIME)
pyautogui.keyUp('left')
last_move_time = time.time()
def right():
global last_move_time
time_since_last_move = time.time() - last_move_time
if(time_since_last_move >= const.MOVE_TIME):
pyautogui.keyDown('right')
time.sleep(const.PRESS_TIME)
pyautogui.keyUp('right')
last_move_time = time.time()
def backward():
global last_move_time
time_since_last_move = time.time() - last_move_time
if(time_since_last_move >= const.MOVE_TIME):
pyautogui.click(x = const.PLAY_BUTTON_X, y = const.PLAY_BUTTON_Y)
pyautogui.keyDown('down')
time.sleep(const.PRESS_TIME)
pyautogui.keyUp('down')
last_move_time = time.time()
def restart():
pyautogui.click(x = const.PLAY_BUTTON_X, y = const.PLAY_BUTTON_Y)
time.sleep(const.WAIT_SCREEN)
pyautogui.click(x = const.PLAY_BUTTON_X, y = const.PLAY_BUTTON_Y)
def escape():
pyautogui.keyDown('esc')
time.sleep(const.PRESS_TIME)
pyautogui.keyUp('esc')
time.sleep(const.WAIT_SCREEN)
if __name__ == '__main__':
restart()
start = time.time()
left()
right()
backward()
forward()
end = time.time()
print("Took", end-start, " seconds")