Dinosaur Game Thumbnail

Automate Dinosaur Game Using Python | Python Projects for Beginner1 min read

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!

DOWNLOAD SOURCE CODE

Tanmay Sinha

Author

  • Tanmay Sinha

    Founder & CEO of MrProgrammer.in | I help Learning Freaks to Step into the World of Programming and Our Mission is to Provide High Quality and Valuable Content to Our Users! We believe that everyone has the potential to learn to code, and we are committed to making that happen. Our courses are designed to be engaging and interactive, and we offer a variety of learning paths to meet the needs of all learners. We are also committed to providing our learners with the support they need to succeed, and we offer a variety of resources to help learners learn at their own pace. If you are interested in learning to code, we encourage you to check out our courses. We are confident that you will find our content to be high-quality, valuable, and makes sense.

Leave a Reply