Hey Python Programmers, In this Post We will be Automating the T-rex Dinosaur Game Which Appears When we are Offline And Unable To Do our Work So To Entertain Us Google Chrome has Created this Game for their Users so that They Don’t Get Bored While they Are Offiline.
From this Python Project the Dinosaur Will Move, Jump & Bend Accordingly the Obstacles Comes, This is a Just a Program Which Press the Up Key Through a Python Program.
You can Either Test This Offline Or Go to This https://chromedino.com/ Website to Test your Program.
Modules Required For this Project:
- PyAutoGUI
pip install PyAutoGUI
- Pillow
pip install Pillow
Step 1: Install the Above Modules Mentioned In Your System
Step 2: Copy the Following Code Given Below:
import pyautogui
from PIL import Image, ImageGrab
import time
def click(key):
pyautogui.keyDown(key)
return
def isCollision(data):
for i in range(530,560):
for j in range(80, 127):
if data[i, j] < 171:
click("down")
return
for i in range(530, 620):
for j in range(130, 160):
if data[i, j] < 100:
click("up")
return
return
if __name__ == "__main__":
time.sleep(5)
click('up')
while True:
image = ImageGrab.grab().convert('L')
data = image.load()
isCollision(data)
Step 3: Run Your Code!
Step 4: Enjoy the Game!
So This was it For this Blog See you in the Next One Till Then Keep Coding Keep Exploring!
- The JS Developer’s Podcast [EP: 2] Variables and Data Manipulation - October 15, 2024
- YouTube Channels to Learn Coding: Top 9 Picks That Will Make a You Master - October 10, 2024
- The JS Developer’s Podcast [EP: 1] Introduction to JavaScript - September 27, 2024