The video game industry generates something in the region of $140 billion each year, and that number is growing fast. It’s a long way from the 8-bit days of the Commodore 64 and ZX Spectrum; the arcade titles that used to devour our pocket money and the wood panelled home consoles that Atari lovingly developed. These days, it’s all about teams of coders, graphic artists, musicians, PR, projects and development platforms.
Coding a game from scratch, using raw code, has become something of the past. Most games these days are created using a range of development tools. These tools can be off-the-shelf engines, such as the Unreal Engine, while others are custom built around an original product, such as the world generating engine that Bethesda use for the Skyrim and Fallout series of games. Others examples can be coded from the ground up, but these are generally few and far between. So where does Python fit into all this?
The limiting factor with Python is performance. While most games require a huge degree of performance from the platform for which they are written, Python’s code, which is good, isn’t really designed to cope with the fast-paced formula on which games such as Battlefield or the Call of Duty series are based. These games are often coded with C++, or some other form of low-level programming language. But that doesn’t mean Python is left out in the cold when it comes to game development, in fact it’s quite the opposite.
In the game industry, Python is mostly limited to the development of in-game tools used by the developers of the game, or to help bridge the gaps between different areas of code. For example, in-game tools coded in Python can be used by designers to create levels for the game, or specific elements that would make up a character’s inventory, or even creating dialog between the player and non-playing characters in the game.
You will also find that Python can be used to control the game’s AI (Artificial Intelligence), which will give the characters in a game a certain element of life. As an example, the popular Sims games consist of characters other than the one the gamer controls. These Sims will go about their business with their actions determined by the player’s choices, this involves an advanced form of Artificial Intelligence that is coded using Python.
Other examples include many of the available open world games, where the introduction of the player will change the course of a village’s, Town’s, or even city’s inhabitant’s behaviour. Blow up a few cars in the middle of the street and it’ll affect the way the other drivers behave; jump up and down on top of a market stall in the middle of a medieval village and the folk around you will react. This, again, is all down to Python code written within the main code of the game, alongside the game development engine.
Some good examples of the types of games in which Python is used are the following:
- Battlefield 2 – Python is used for the game’s add-ons and functionality of the player elements. The Sims – AI, and many of the game’s interactions.
- Civilisation – Python is used throughout the Civ games, controlling movement and the non-player AI.
- Eve Online – Utilises Python for floating point number calculations and other tasks.
- World of Tanks – Python is used to control AI objects and detail the large amount of graphical data.
In particular, it’s worth noting that Python’s use in games is due to its ability to automate repetitive tasks quickly. While another programming language may be faster at drawing the graphics on the screen, Python can quickly repeat resizing hundreds of textures in batches. There’s also Python’s excellent and sizeable libraries that can be tweaked for certain tasks, specifically in-game tasks freeing up other components to deliver the performance that modern games need.
In short, while Python may not be the ideal language with which to create a modern game entirely, its use is often behind the scenes, in areas where other programming languages will struggle. Python can be used as the glue that sticks elements of game technologies together, creating complex AI or simply designing a dialog box.