Create a Casual Game with Python3

Notes for Teachers

Nathan Bailey
CS Adventure
3 min readOct 15, 2018

--

Python3 offers an easy to read language that is accessible for programmers of all skill levels. With the addition of a module like Pygame Zero, you can be creating your own game in no time. Pygame Zero offers a zero boilerplate api for Pygame, which makes it perfect for beginners and students.

I typically introduce this project after the students have been introduced to variables and control structures. While the Pygame Zero module uses Object Oriented Programming, the students really don’t have to understand with OOP paradigm to build the game. Students really just need to understand the dot operator. Here’s a good intro to the Dot Notation for students to help get them started.

Students will be using the following to build the game:

Mu-Editor

The Mu Editor is easy to install and comes with Pygame Zero build in as one of it’s modes. You can run Pygame Zero from the command line, but for beginners this can be tough to navigate. If your students are already used to using the command line and a professional editor, you may want to just install Pygame Zero using Pip.

To get started, just download Mu-Editor and install according to the instructions. Students will need to choose the Pygame Zero mode when they launch the Mu-Editor.

One of the strange things about working with the Mu-Editor is that it prescribes the working directory for all code. You will find the code for your game in the Mu_Code folder in your home directory. You can’t change it easily, but the good news is that students never have to wonder where files are being saved. For more info about why the developers chose to do this check out https://codewith.mu/en/tutorials/1.0/files.

Debugging with Mu-Editor is a nightmare. The tracebacks are not complete, and it is very difficult for students to catch the errors. I’d highly recommend that you spend some time working with students on debugging strategies as they work on this project.

Installing Assets

All the assets for the video are available for download as a zip file. All the assets are open source and the original licenses are included in the zip file.

Download Assets — https://github.com/dnbailey/gem_grab/archive/v1.0.zip

Here are links to where I found the assets. All of the assets are included in the link above, but these are good resources for future projects.

Source: https://codewith.mu/en/tutorials/1.0/pgzero

Once students have downloaded the assets, they will need to place them in the correct folders in the Mu_Code directory. The easiest way to do this is to click the button in the Mu-Editor toolbar for the asset directory you need. Just drag the assets from the zip file into the Images, Fonts, and Music folders in the Mu_Code directory.

I noticed a few students struggling with this, and it caused errors later in the tutorial. If you can’t find a syntax error, open the asset folders up and check to see if the files are installed correctly.

The Code

I’ve included the complete code for the game below, so that you can reference it when working with students. The videos walk students through building the game from the ground up, and I think it’s important that they see the process of building the code.

Tutorial on YouTube with Your Students

The tutorial walks students through the process of building the games. Encourage students to not just pause and copy the code. The goal is to model thinking through the problem.

Thanks for reading. Check out other resources on my YouTube Channel or @dnbailey on Twitter. Let me know if you have any questions or ideas for improving this tutorial.

--

--