| [ LiB ] |
I've covered quite a bit in this short chapter. Before you move
on to more specifics with Python in the
Python, Lua, and Ruby organizations keep active lists of
projects that are pretty
Math and algebra are handled very similarly in each language.
Boolean operators, Boolean comparisons, conditional control statements, and iterative control statements can all be used to control the flow of a program.
Lists, strings, and a number of other commands all look and are handled in a similar way in each language.
Implementing "Hello World" in a standard way in C takes more lines of code and more symbols than any of the other three languages.
| [ LiB ] |
| [ LiB ] |
| 1: |
Q: Why are there more projects in Python and Lua than Ruby? |
| A: |
A:
Ruby is probably the most difficult of the three
languages to find evidence of in the game industry. This is partly
due to the language
|
| 2: |
Q:
I already know how to program "Hello
World", when do I get to write graphics and
|
| A: |
A:
You'll start writing much more
|
| [ LiB ] |
| [ LiB ] |
| 1: |
Describe the difference between a conditional control statement and an iterative control statement. |
| 2: |
Boolean logic uses only two values. Which two values are they? |
| 3: |
Which else/if structure ( elseif , elsif , and elif ) goes with which language (Python, Lua, and Ruby)? |
| 4: |
When printing a simple statement (like "Hello World"), one of the three languages normally uses a puts command instead of a print command. Which one is it? |
| [ LiB ] |
| [ LiB ] |
The
next three chapters are all about Python. This part of the book starts with an overview of the Python language and its syntax, then moves in to examine commonly used libraries for writinggames in Python, including Pygame and PyOpenGL. Finally, a few real-world Python game projects are examined.
| [ LiB ] |
| [ LiB ] |
Latet anguis in herba
Virgil (70-19 BC), Roman poet, "Aeneid" (Translation: There's a snake hidden in the grass.)
Let's jump right into programming with Python. I'll start with an introduction to a few useful tools and then give you a speedy overview of the Python language.
| [ LiB ] |
| [ LiB ] |
You can execute .py files once Python is installed on your
machine, but that doesn't make your Python game programs
When modules are imported in Python by other modules, Python
compiles the relevant code into byte-code, an intermediate,
portable, closer-to-low-level binary language form. This
Python's .pyc files
Precompiling scripts is one way to speed up Python programs that need to import many modules. You can minimize a program's startup time by making sure source code is kept in directories where Python will have access to writing .pyc files.
You can also ship Python programs as .pyc files rather than as
.py scripts. Since .pyc files are binary, they cannot be run as
scripts, but they can be sent to the Python interpreter; simply add
the
Python runme.pyc
In order to build a compiled Python file from the Python interpreter, import the compile function from py_compile and run the compile command, like this:
from py_compile import compile
compile("script_to_compile.py")
Freeze is a system that takes Python script files and turns them
into modules packaged into C files. Originally Freeze was used as
one way to ship Python source, but it is now mostly
ActiveState is a company that focuses on applied
The py2exe extension is an open source utility that converts
Python scripts into executable Windows programs. The software is
The extension is still under development but has expanded
recently to include the ability to
py2exe is a Distutils (Python Distribution Utilities) extension, and relies on the work by Greg Ward to make Python programs distributable (see the Disutils Website at http://www.python.org/doc/current/dist/). The Distutils are necessary for py2exe to work and are also included on the Python folder in this book's CD.
| [ LiB ] |