python for game programming

miller.paul.w at gmail.com miller.paul.w at gmail.com
Sun Feb 3 13:53:52 EST 2008


On Feb 3, 9:05 am, t3chn0n3rd <darrin_al... at japan.com> wrote:
> Is Python program language popular for game programming?

Well, Python is at the center of my favorite game, Sid Meier's
Civilization 4. :-)

Another poster mentioned the pygame and pyglet libraries.  I'd suggest
you look into them if you want to code a game in Python.  Also keep in
mind the "alternate hard and soft layers" design pattern (as much as I
hate the phrase "design pattern," there's no better way to describe
this particular one.)

The essence of "alternate hard and soft layers" is to design your
application in one of two ways:

* Most of your code is in Python, with C or C++ extensions for
performance-critical areas, or
* Your main app is in C, C++, or some other language that can embed a
Python interpreter.  The embedded Python interpreter provides a
scripting interface that can be used by level/scenario designers or
end users to customize the game.  The scripting interface can be as
simple as a wrapper around functions in the main code, so you can
choose how much functionality you want to expose.

These two patterns are basically equivalent, but I prefer to use the
first, because it lets me write more Python and less C.  In the second
approach, you end up writing most of the game in C and exposing a few
of those C functions to Python.

If you only want to expose a subset of game functionality to Python
(for example, AI or level generation), I'd guess the second way is the
way to go.



More information about the Python-list mailing list