Building Chrome Dinosaur Game in Pygame (Part 0: Intro & Setup)
Here’s a quick question for you: Why do you love Google Chrome ?
If you’re like me, one reason might be the little dinosaur game that pops up when the internet goes down. Honestly, that game has made my days of poor connection more bearable.
Recently, I started wondering what it would take to build a similar game — but one I can play anytime, without waiting for my Wi-Fi to fail. That curiosity led me to pygame, and this blog series is where I’ll share what I learn as we recreate the Chrome Dino game step by step.
But before we go any further, I need to make it clear that I’m assuming the following things about you:
- You understand basic English. Trust me, this is not a given.
- You possess basic knowledge of the Python programming language. If not, check out this coding resource to learn.
- You’re following along on a Mac, Linux or Windows Laptop or Desktop. You can’t use your smartphone for this I’m afraid.
Alright, let’s dive in !
So, what is pygame ?
Pygame is a collection of Python modules (libraries) designed for the purpose of writing video games. It’s able to achieve this because it builds on the SDL library. Here are some facts about Pygame:
- Pygame was developed by Peter Shinner in 2000.
- It is maintained as a community project and is free for use in personal and commercial projects.
- It’s source code is not actually written in Python but in C and Assembly.
Click here or here to learn some more interesting facts about Pygame.
Overview of the game
The Chrome Dino game is a very simple game featuring a 2D rendering of a dinosaur (supposedly a T-Rex) running across a flat plain dotted by Cacti which serve as obstacles on that path. The objective of the game is keeping the Dino alive for as long as possible by jumping or bending down in order to avoid colliding with Cacti on the road or, if you last long enough, getting hit by flying dinosaurs (Pterodactyls to be precise). This is what we’ll be making in the course of the series:
So, let’s get started.
The Setup
In order to follow along with the lessons in this series, you’ll need the following setup:
- A Code Editor: For the sake of this project, we’ll be using Visual Studio Code. If you do not already have it installed, then go ahead and download it here.
- The Python Interpreter: This is essential for writing and executing code written in the Python programming language. If you don’t already have it installed, then go ahead and download it here.
- The Code: In order to enable you effectively follow along, I’ve taken the liberty of packaging the starting code and assets for this project into a zip file. In order to download and extract the starting files, click here.
Once you’re done downloading these tools, then extract and open the Gino-start-here folder from within the code zip folder in Visual Studio Code. You can rename the folder to anything, I’ll call my own Gino. Once opened in VS code, You should have the following directory structure:
├── .gitignore
├── LICENSE
├── README.md
├── requirements.txt
├── main.py
└── Assets/
├── sprites/
│ └── (sprite files go here)
└── tracks/
└── (sound/music files go here)
This directory structure and the files within it will be explored more in the upcoming posts.
You’re almost done, all that remains is installing pygame on your local system. This can be done by opening up Command Prompt/Powershell (Windows users) or Terminal (MacOS users) and typing in the following command after the system prompt (Usually a $ or > symbol):
pip install pygame
OR (If you’re working on a linux machine):
pip3 install pygame
This should install pygame on your local machine and now, you should be able to follow along with the rest of the series. If you encountered any challenges or difficulties installing pygame, then checkout the following guide for more information on how to install it for both Windows and MacOS. The Linux users will have to find their own fix.
The code for each post in this series will be organized into seperate branches on Github. Don’t worry if you’re not familiar with Git — I’ll include direct links to the code for each post.
In the course of the blog post, you installed and setup a local environment for Python game development using the pygame package. Congrats !!! You’re now a pygamer.
In the next post, we’ll have a look at the code we just downloaded and begin the process of building out the game step-by-step. But for now:
Thanks for reading.