18 June, 2021
When introducing your kids to coding it is vital to take their interests into account, in order to make their learning experience as successful as possible. Luckily, developing video games is one of the best ways that kids can learn to code, with plenty of engaging visual elements and a fun, playable outcome. Younger kids can use visual programming languages such as Scratch and Kodu, however the games which can be created on these platforms are fairly limited. Older kids with typing abilities can instead learn to program with text-based languages like Python – and a fantastic way to do this is through Pygame.
Pygame is a Python-based library which is filled with different modules (files containing code) that are used for developing 2D videogames and other multimedia programs. Popular among millions of people across the world, Pygame is suitable for kids learning to code who want to create something exciting, unique and fun.
Python is one of the world’s most popular coding languages, and is the main language used in industries such as machine learning and big data. It might sound complex, however Python is actually simpler for kids to learn than other text-based coding languages such as Java, for a number of reasons:
In fact, Python’s core philosophy, known as The Zen of Python, states that “Beautiful is better than ugly, simple is better than complex, complex is better than complicated, readability counts”.
Graphics programming can be fairly complicated for new coders, so the best way for kids to set themselves up for success in Pygame is to get comfortable using Python. They can write some simple games and programs, get to know some of the most important functions of the language, such as strings, lists and variables, and understand how to import a program from multiple source files. Practice makes perfect, and by experimenting with Python, revisiting the core concepts of coding and tinkering when problems arise, it will be much more enjoyable for kids to use Pygame when the language behind it is second nature to them.
Pygame is beginner-friendly, making it a great platform for adults and kids alike. Just as the syntax of Python is easier to write than other text-based languages, the code written in Pygame is kept simple. It’s important to download Python 3.7.7 or later, as this version runs much faster and is simpler for new coders.
As well as writing their own code, kids can download programs written by other users, getting inspiration from coders around the world. They can visit the Python Package Index (PyPI, a repository of software developed by other Python users) to access the source code for countless games, find example game programs to help them get started, and download extra features such as touch interfaces and widgets in GUI libraries, which are developed outside of Pygame and can be downloaded and imported into the software. This allows kids to build their game without having to write some of the more complex code themselves.
Pygame Zero is a simpler version of the program. All of the common elements which users must put together themselves on Pygame are already pre-loaded in Pygame Zero, making it even easier for young coders who are just starting out. Whichever version of Pygame your child chooses, there are many tutorials online to walk beginners through the first steps.
Pygame is a fantastic creative outlet for kids as it is fully customisable. Thanks to its modular make-up, each piece of the game can be compiled separately. Kids can add their own images and mp3 files, have full control over what is displayed on their screen, and can choose their preferred type of user input and play their game with arrow keys, joystick or mouse. With these features, it’s possible to develop all kinds of games on Pygame – from retro arcade and multiplayer strategy games, to puzzles and sudokus. It is even possible for more experienced coders to recreate popular games like Super Mario or Flappy Bird!
On Pygame, users create open source, freeware, shareware, and commercial games. So, kids don’t only have access to programs written by other coders, but they can also put their own projects out into the world! In fact, many games created on Pygame have actually been published on the official website, and their creators have been honoured at videogames festivals such as the IndieCade Festival of Independent Games, known as the ‘Sundance’ of the video game industry.
Pygame and Python are free to download, and run on nearly every operating system including Linux, Windows and Mac, so it’s not necessary to update your kid’s device to the latest, most expensive piece of hardware before starting on their coding journey.
To use Pygame, first you must install Python on your computer. Next you can install Pygame using the Python Package Installer – known as ‘pip’ – by typing in the command line ‘pip install pygame’. Once the game window has been set up, you should import the Pygame modules by typing ‘import pygame’ and then ‘pygame.init()’ to initialise Pygame. Once all that is done, your kid is ready to start coding!
Photo by Sigmund on Unsplash, photos by cottonbro, Christina Morillo, Monstera on Pexels