Python JSON logging has become the standard for generating readable structured data from logs. While logging in JSON is definitely much better than using the standard…
The world of computer games is vast, ranging from single-player agility games and logic puzzles with simple 2D animations to the stunning graphics in 3D rendered massive multiplayer online role-playing games like the Lost Ark.
Wanting to design and build your own games is a common motivator for learning to code while building a portfolio of work is an essential step for breaking into the gaming industry. For experienced developers, creating your own game from scratch can be anything from a satisfying side project. It can be an opportunity to experiment with elements of computing that don’t feature in your day job – like graphics and audio – or a taste of what would be involved in moving to a new role within computing.
Once you’ve devised an idea for a new computer game, one of your decisions needs to be which programming language to use to turn your ideas into reality. Python is one of the most popular programming languages in the world and an excellent choice for those new to coding. However, as you may have found if you’ve already started researching this topic, Python isn’t necessarily an obvious choice for game development. In this article, we’ll look at the pros and cons of Python for building computer games, some of the considerations for writing games in Python, and essential libraries and frameworks to help you get started.
As we said above, Python is one of the world’s most popular programming languages, and with good reason. Its concise, human-readable syntax and built-in interpreter make Python an optimal choice for anyone new to programming. Its platform independence, extensive ecosystem of libraries, and high-level design ensure versatility and increase developer productivity.
How does that translate to game development? If you’re new to coding, you’ll find plenty of resources to help you start writing code in Python. As a high-level language, Python abstracts away details about how your code is run, leaving you focused on the logic and aesthetics of your game design. However, for games where performance is a key concern, this is the biggest disadvantage.
Developer overheads when working in Python are quite low, so you can get something up and running quickly. This is great for beginners and experienced developers alike. As a novice, seeing your progress and building up your game incrementally makes for a more rewarding experience and makes it easier to find mistakes as you go. For professionals, this makes Python an ideal tool for getting something working quickly in the case of prototyping while also providing a dev-friendly language for longer-term development.
Furthermore, the Python ecosystem is vast, with a friendly online community of developers you can turn to for pointers if you get stuck. Because it’s both open-source and flexible, Python is used for a wide range of applications, so you can find libraries for machine learning, artificial intelligence, manipulating audio, and processing graphics, as well as several libraries and frameworks aimed explicitly at game development (discussed in more detail below). All of this makes it easier to start developing games with Python.
One of Python’s key upsides as a general programming language is also its main drawback when it comes to game development, at least where video games are concerned. The high rendering speeds, realistic graphics, and responsiveness that players expect from video games require developers to optimize their code for every microsecond of computing performance. Although high-level languages like Python are not designed to be slow, they don’t give developers the flexibility to control how memory is allocated and released or to interact with hardware-level components. Furthermore, Python is interpreted at runtime rather than compiled in advance – that doesn’t necessarily make a perceptible difference on modern hardware for most applications. Still, when speed is of the essence, it matters.
Instead, video game developers have tended towards lower-level languages that give them more precise control over resources, with C++ being the primary choice. While computing power and memory have increased significantly in the last decade, so have user expectations. When you’re building a game involving 3D graphics that emulate real-world physics from multiple perspectives while responding to hundreds of simultaneous inputs, you simply can’t afford to waste processor cycles. Combine that with decades of industry experience and knowledge poured into building the tools to support game development. Unsurprisingly, many best-known gaming engines, including Unreal, Unity, CryEngine, and Godot, are written wholly or partly in C++. Other popular languages within the gaming world include C# (also used by Unity) and Java.
Despite these limitations, Python has plenty to offer game developers.
Because it’s easy to work with, Python is a great choice for prototyping all kinds of programs, including games. Even if you’re planning to build the final version in a different language for performance reasons, Python provides a quick turnaround time for trying out game logic, testing concepts on your target audience, or pitching ideas to colleagues and stakeholders.
If you’re using game development to learn how to code, then Python is an excellent way to become familiar with the basics and learn about object orientation. You’ll be able to progress relatively quickly and test what you’re building as you go. You’ll also find plenty of gaming libraries and tutorials for different experience levels.
If your sights are set on a career in gaming, and you’re concerned that learning Python will be a waste of effort, you might want to think again. As a widely used, open-source scripting language, Python is a common choice for some supporting code in developing larger games. Unreal Engine, for example, supports Python for scripting tasks that you can perform manually from the editor, like importing assets or randomizing actor placement. In contrast, Unity supports Python for automating scene and sequence assembly, among other tasks.
Don’t let performance considerations turn you off Python for gaming completely. If you’re looking to develop a game that doesn’t need to be tuned for maximum performance and you’re not using one of the heavyweight gaming engines, then Python is a valid choice. For a sense of what’s possible, look at existing games built with Python, including Disney’s ToonTown Online, Frets on Fire, The Sims 4, and Eve Online.
The Python ecosystem offers gaming libraries for everyone from complete novices to experienced Pythonistas, including:
Part of being a developer is choosing the correct programming language for the job. Python has a place within game development: as an entry point for those new to coding, as a prototyping tool for creating proofs of concept quickly to test your ideas and gather feedback, as a powerful scripting language to support other aspects of game development, and as a simple yet powerful language for building games for any platform.
While Python would not be the ideal choice where game performance is critical, it’s an excellent tool for developing something quickly or if you don’t want to learn a more complex language and gaming engine.