Sign in to follow this  
mcaccountman

Is Python good for 2d - 3d games?

Recommended Posts

It's possible to write indie-scale games in pure Python. There are a number of them. Libraries like PyGame make this easier.

Python will work just fine for you if you want to toy around with making games.

However, it is not suitable for writing big AAA games like Mount & Blade.

Share this post


Link to post
Share on other sites

Python isn't the fastest language around so speed-reliant code is difficult to write.

 

On the other hand, it's certainly fast enough to do the sums involved in moving a few hundred sprite objects around the screen -- one lets the rendering system do all the looping work.

 

The advantage, from a learning point of view, is that much of the boring fiddly work of who owns which bits of memory is done for you so you can focus on the more interesting parts.

 

Many of us grew up writing games in a mix of BASIC and assembly language on 8-bit micros, and the kinds of games which worked well there can be written these days in Python much more easily. M&B is, as Sean says, a bit out of reach, but rogue-likes, 2D puzzlers and platformers, shoot-em-ups and so on are within reach (only with better graphics than the 8-bits!). I wouldn't be surprised to find that with a little extra work, things like Starglider could be done in Python these days.

 

The trick is to design a game that doesn't involve large amounts of data.

 

Large, of course, means something slightly different these days. A z80 instruction to block copy memory[1] costs 21 cycles per byte copied. You only get 50-100 thousand cycles per 50th second TV field on most 8-bit micros. So you can realistically only copy a few kilobytes of memory per frame..  I had a quick naive play with some code and python on its own is capable of copying 400k per frame. So even in plain old python you've got 100 times as much processing power as we had back in the early 80s...

 

 

 

[1] LDIR, for reference.

Share this post


Link to post
Share on other sites

I would say, that it is perfectly capable for both "indie-scale" and 3D AAA level, but for the later a different approach is required.
In python alone a calculation heavy, speed reliant software can not be created due to it's interpreted nature, but if a middle-ware/engine is written in c/c++ (all the performance critical parts well optimized, like: collision detection & physics, animation, rendering) and python is leveraged as a scripting system to "drive" the engine, I think close 100% of the game logic and engine configuration could be done in python (some will probably say this is cheating or the question specifically asked if a whole game could be done in python, but what ever laugh.png, what is important, that creating a game in python, be it any kind, is perfectly possible)!

This IS supported by the following list:
https://wiki.python.org/moin/PythonGames

Some famous examples from this list:
"Mount&Blade is a single player pseudo-historical game that utilizes python scripts for its module system"
"EVE Online is a massively multiplayer online space game written in StacklessPython"
...

So for small 2d games http://www.pygame.org/ is a perfectly capable library and for 3d graphics and calculation heavy games use https://www.panda3d.org/ or https://www.blender.org/manual/game_engine/introduction.html.

With these libraries & engines technically you can fully develop a 2d or 3d game without ever touching any language other than python, and many previous games prove this wink.png!

Share this post


Link to post
Share on other sites

Creating large open world games like Mount & Blade is possible.

 

Using python and Panda 3D I have made several open world games, you just need to understand instancing and Batching.

The games where "walking simulators" with over two-hundred characters of 14 000 polygons each running over 120 FPS on a mid range graphics card.

 

 

The down side is that with the level of knowledge you need to make a game like this, you could just download the UE4 and make a game that is several times better.

The game engine will do most of the background performance saving for you, the blueprint editor allows you to make games even if you only know the basics of programming.

Share this post


Link to post
Share on other sites

Even though the language is inherently object- and allocation-hungry (as shown by the CPython API), it probably depends more on the implementation that you use for Python. The default one (CPython) is even slower than PHP, last I checked. You might have more luck with one of the JIT-based ones, though be aware that they won't be allowed to be used in embedded devices (phones/consoles). If CPython is the only option, you might want to keep in mind that any kind of loop is going to be a lot more slow than it is with compiled languages.

 

And for speed/stability, expect to write some C/C++ data processing code along with some special data structures for the more performance-sensitive operations if you're taking a project of a substantial size. Writing these and other binding code may outweigh the benefits of using a scripting language.

Share this post


Link to post
Share on other sites


However, it is not suitable for writing big AAA games like Mount & Blade.

 

Kind of a nitpick, but Mount & Blade isn't really a AAA game.  I remember playing the original back in 2006, back in the 0.7ish days.  At the time, I think they were still just a handful of guys in Turkey working part-time on it.  Today they'd probably be a Kickstarter or Steam Greenlight early-access vaporware.

 

I'm sure that you could build something on the level of Mount&Blade today with Python.  More likely, though, is that you would end up with a situation similar to what Taleworld's did, which is have a hybrid system, with the high-performance parts of the code (graphics, physics, etc) written in C/C++, with the higher-level, less performance-critical code in Python (Although they almost certainly came at it the other way around, with the C/C++ engine which they bolted the Python scripting onto).  You most certainly can build games with Python - PyGame is incredibly easy to use and get something going quickly.  

 

Just be aware that if you want to build something on the scale of Mount&Blade, it is going to take many years, unless you have many people and lots of money to throw at it, in which case it will still take years.  The Taleworld's guys were releasing alpha/betas in 2004, by 2006 it was kind of playable, in late 2007 it was finally released as 1.0.  And graphics-wise, Mount&Blade is pretty dated.  I'm not sure if it is still there, but I have distinct memories of the DirectX 7 vs DirectX 9 selector toggle in the options (DX7 wasn't as shiny, but gave about 3x the FPS on my old laptop).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this