-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdino.py
60 lines (46 loc) · 1.37 KB
/
dino.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
import pyautogui # pip install pyautogui
# to control GUI
from PIL import Image, ImageGrab # pip install pillow
# to take screenshot and modify image
# from numpy import asarray
import time
def hit(key):
pyautogui.keyDown(key)
return
def isCollide(data):
# Draw the rectangle for birds
"""for i in range(230, 250):
for j in range(300, 380):
if data[i, j] > 100:
hit("down")
return
"""
# Draw rectangle for cactus
for i in range(400, 430):
for j in range(380, 455):
if data[i, j] > 100:
if data[i,j] < 220:
hit("up")
return
return
if __name__ == "__main__":
print("Hey.. Dino game about to start in 3 seconds")
time.sleep(2)
# hit('up')
while True:
image = ImageGrab.grab().convert('L')
data = image.load()
#image.show()
isCollide(data)
# print(asarray(image))
"""# Draw the rectangle for cactus
for i in range(250, 260):
for j in range(380, 455):
data[i, j] = 0
# Draw the rectangle for birds
for i in range(230, 240):
for j in range(300, 360):
data[i, j] = 220
image.show()
break
"""