forked from shubham99bisht/Python-plays-Dino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdino.py
More file actions
34 lines (27 loc) · 788 Bytes
/
dino.py
File metadata and controls
34 lines (27 loc) · 788 Bytes
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
import os
import sys
import time
from PIL import Image
from os import environ
import cv2
import numpy as np
import pyautogui as pg
pg.PAUSE = 0
#for mac or windows users:
from PIL import ImageGrab
#for ubuntu users:
#import pyscreenshot as ImageGrab
#(x,y) to represent left-top corner of the rectangle, little away from dino
#(x+w,y+h) bottom-right corner of the rectangle enclosing dino and coming cactus.
x, y, w, h = 585, 327, 244, 100
while True:
img = ImageGrab.grab()
img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
img = img[ y:y+h, x:x+w ]
for x0 in range(170,240,5):
px = img[58,x0]
if (px[0]<=150):
print("jump")
pg.press("up")
time.sleep(0.05)
break