In today’s tutorial, we will learn how to “Automated Dinosaur Game in Chrome” by using python programming by importing some modules like pyautogui and image processing. PyAutoGUI let the Python program control the mouse and keyboard to automate interactions with other applications.
Prerequisite: The prerequisite of this project is the basic knowledge of python.
Dinosaur Game is one of the most popular game, where your goal is to jump over all boundaries to win the game. You have to control dinosaur to get more scores and win! This game is also known as T-Rex Game, or the NO INTERNET GAME, as it is one of the hidden Google games which originally can only be activated when you have no internet connection.
For this project, I am using Virtual Studio Code IDE. This tutorial is a part of python series for absolute beginners. If you have not watched my python tutorial, then click on the link below and start learning!
If you have ever tried a programming challenge, then you know they are fun. Accepting a coding challenge is an excellent way to improve your coding skills. If you like my work, make sure to check out my courses. Stay safe and keep yourself up to date with codewithharry.
import pyautogui # pip install pyautogui from PIL import Image, ImageGrab # pip install pillow # 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(300, 415): for j in range(410, 563): if data[i, j] < 100: hit("down") return for i in range(300, 415): for j in range(563, 650): if data[i, j] < 100: 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() isCollide(data) # print(asarray(image)) ''' # Draw the rectangle for cactus for i in range(275, 325): for j in range(563, 650): data[i, j] = 0 # Draw the rectangle for birds for i in range(250, 300): for j in range(410, 563): data[i, j] = 171 image.show() break '''
Very well done harry bai mja aa gaya
there is a problem in the source code...in my case while running the code the dino always remains in down position
Regarding chrome dino. Great project sir. With reference to your code i made for my pc. Problem I am facing is dino collides after 400 or 500 score. Is it that computer is getting slow to check and jump or i have placed the box for checking the pixels too close to dino that till it jumps it is getting collided. This is happening after score of 400 or 500. Sometimes even goes till 700. Another major problem is this is not working when night mode comes. Code is missinterpretating the night black with black of cactus and bird. I believe this program is also possible without using down key. And to my surprise it works. Just needs to jump above the bird when bird is at mid and low height. And leave as it is when bird is at top height. There are around three heights. But weird thing is your program does not fail in night mode. While my with almost same code just changed numbers doesnt work. What is your active email. I emailed you once maybe you dont use it. The one from youtube channel description. Please help.
You are awesome , you can share dinosoar game with separate article
Hello Harry bhai mene ye game ko automate krne ke liy program bnaya, program run hora h screenshots sab sahi hora h but ye game nahi khel rha..mene ye mac-book me bnaya h....please suggest me kya kru.
Harry bhai ye work nahi kar raha program. I have tried my best to solve it but it is not working properly. And instead of blindly copying your code I made my own by adjusting the position of rectangles for birds and cactus. Dino jumps 1 second after it get collide with cactus.Please see the program and then tell me. I have made this program ------ import pyautogui from PIL import ImageGrab import time def hit(key): pyautogui.press(key) return def is_collide(data): # Rectangle for birds for i in range(225, 265): for j in range(275, 378): if data[i, j] < 100: hit('down') return # Rectangle for cactus for i in range(225, 265): for j in range(380, 455): if data[i, j] < 100: hit('up') return return if __name__ == "__main__": print("Hey... Dino game is about to start in 3 seconds...") time.sleep(3) while True: image = ImageGrab.grab().convert('L') data = image.load() is_collide(data) ''' # Rectangle for cactus for i in range(225, 265): for j in range(380, 455): data[i, j] = 0 # Rectangle for birds for i in range(225, 265): for j in range(275, 378): data[i, j] = 100 image.show() break '''
No downloadable resources for this video. If you think you need anything, please post it in the QnA!
Any Course related announcements will be posted here