Game Programming with Python

Sean Riley

Publisher: Charles River Media, 2004, 470 pages

ISBN: 1-58450-258-4

Keywords: Python, Game Programming

Last modified: Nov. 9, 2008, 11:30 a.m.

If C and C++ are the languages of choice for game programmers, why should you consider using Python? Game Programming with Python explores this question in depth and teaches you why and how Python can reduce your development time, improve your technical designs, and make the entire development process more efficient.

Game Programming with Python is about building games using Python. It deals with general concepts of game development and specifics that apply when using Python for game development. Some of the general topics include simulations, game architectures, graphics, networking, and user interfaces. The Python-specific topics covered include Python development strategies, using Python for data-driven systems, performance tuning, modules and packages, and interfaces between Python and other programming languages. Additionally, a series of increasingly complex examples are developed throughout the book using Python.

Python is already being used by professional game developers in a number of popular commercial games, including the award winning Star Trek® Bridge Commander (Totally Games), Freedom Force (Irrational Games), and Earth & Beyond (Electronic Arts). Games such as these use Python in three major ways: as a full-fledged programming language to develop real software systems; as a scripting language to control and interface between systems written in other languages; and as a data language to describe game rules and game objects. Throughout the book, each of these major uses of Python is discussed along with the differences between them.

Written for Python programmers interested in learning game development, as well as game developers interested in using Python, the book assumes you have some programming background and a basic grasp of software engineering principles. Some knowledge of the game development process is also assumed, although a concise overview is provided.

Features

  • Explains why and how Python can reduce your development time, improve your technical designs, and make your entire development process more efficient
  • Teaches you how to use Python for game development with three fully functional sample games, example programs for specific topics, and a library of game infrastructure code
  • Shows how to develop game infrastructure in a modular, flexible way using key technologies such as OpenGL graphics and TCP/IP networking
  • Describes key areas and algorithms of game programming, including artificial intelligence, dynamic content generation, collision systems, network protocol design, user interfaces and game application structure
  • Shows how Python can interact with other languages in game environments, including writing extension modules and extension types, and embedding Python as a scripting language
    1. Overview
      • What This Book Is About
      • What Is Python?
      • What Is Game Development?
      • Can Python Be Used for Games?
      • The Contents of This Book
      • Prerequisites
  • SECTION I Introduction
    1. Game Architecture
      1. Architecture Diagram
      2. Physical Simulations
      3. Data Drivers
      4. Graphics Engines
        • 2D Engines
        • 3D Engines
        • Graphics Engine Subcomponents
        • Competing APIs
      5. Audio Systems
      6. Game Simulations
      7. User Interfaces
      8. Network Layers
      • Summary
    2. Python Game Architectures
      1. Performance Characteristics of Python
      2. Pure Python
      3. Python Programming
      4. Python Scripting
      5. Python Data
      6. Other Languages
        • The Lua Programming Language
        • The Tcl Programming Language
        • The Java Programming Language
      • Summary
  • SECTION II Game Infrastructure
    1. Python Game Framework
      1. Infrastructure Technology
      2. Initialization
      3. The Main Module
      4. The Main Loop
      5. Cleanup
      6. Running the Example Code
      • Summary
    2. Simulation Concepts
      1. The Physical Simulation
      2. Components of the Physical Simulation
      3. Implementing Simulations with Python
      4. Reactive Simulation
      5. Controlled Simulation
      6. Parallel Simulation
      7. Simulation Conventions
      8. Variable Rate Updating
      9. The Base Simulation Class
      10. The Simulation World
      11. Updating the Simulation
      • Summary
    3. Data-Driven Simulations
      1. Benefits of Data-Driven Systems
      2. Data Sources
        • Text Files
        • XML
        • Relational Databases
        • Scripting Languages
      3. Implementing a Data Repository
      • Summary
    4. Collision Detection
      1. Classifying Objects for Collision
      2. Partitioning the World for Collision Detection
      3. Methods of Collision Checking
        • Per Polygon
        • Per Pixel
        • Bounding Boxes
        • Bounding Spheres
        • Tiles
      4. Coordinate Spaces
        • Coordinate Spaces for Collision Detection
        • Coordinate Spaces and Bounding Boxes
      5. Axially Aligned Bounding Boxes
      6. Bounding Spheres
      7. Dealing with Moving Objects
      8. Implementing a Collision Grid in Python
      9. Making a Module
      • Summary
  • SECTION III Game Technologies
    1. Graphics
      1. Art Pipeline
      2. Using Python for Graphics Programming
        • Minimize the Number of Elements Exposed in the Interface
        • Minimize the Amount of Python Code Executed at Runtime
        • Keep Graphics-Specific Data in the Graphics Engine
        • Hide Implementation Details
      3. High-Level Graphics Interface
        • Module Interfaces versus Object Interfaces
        • The Graphics Engine Interface
      4. Python Graphics Engine
        • The Module Interface
        • The Graphics Object Interface
        • Integrating with the Simulation
        • Example Application
      5. Visualizing the Collision System
      • Summary
    2. Audio
      1. Audio Concepts
        • Amplitude
        • Frequency
        • Channels
        • Sample Rate
        • Pulse Code Modulation
      2. Playing Sound Effects
      3. Ambient Sounds
      4. Playing Music
      • Summary
    3. Input
      1. Message Handling
      2. Keyboard Input
      3. Mouse Input
      4. Joystick Input
      • Summary
    4. Unit Testing
      1. Introduction to Unit Testing
      2. Setup for Testing
      3. Testing the DataManager
      4. Testing the Simulation
      • Summary
  • SECTION IV Game Programming
    1. Game Simulations
      1. Players and Avatars
        • The PongBallGame Class
        • The PongPlayer Class
        • The Simulation Objects
      2. Game Modes
        • Mode Classes
        • The Breakout Example
      3. The Entity Class
      4. Object Identification
      5. Game Events
      • Summary
    2. Game Levels
      1. Game Levels
      2. Level Data
      3. Level Data in Python
      4. Game Modes for Levels
        • The Pre-Level Mode
        • The Post-Level Mode
      5. Managing Resources with Levels
      • Summary
    3. User Interfaces
      1. Game User Interfaces
        • UI Drawing
        • Coordinate Systems
        • User Interface Optimizations
      2. PyUI Introduction
      3. PyUI Concepts
        • The Desktop
        • Widgets
        • Panels
        • Windows
        • Frames
        • Dialogs
        • Layout Managers
        • Themes
        • Renderers
        • Fonts
        • Events
      4. Using PyUI
        • CanvasPanel Class
        • CanvasFrame Class
        • SaveDialog Class
      5. Interacting with the Simulation
      6. Drawing Text
        • Bitmap Fonts
        • Dynamic Fonts
      • Summary
    4. Artificial Intelligence
      1. Basic State Machines
      2. State Machine Enhancements
        • Transition Validation
        • State Inputs
        • Parallel State Machines
      3. Pathfinding Concepts
        • World Representations for Pathfinding
      4. The A* Algorithm
      5. Implementing A* in Python
      6. Visualizing the Pathfinder
      • Summary
    5. Procedurally Generated Game Content
      1. Predictable Random Numbers
        • Random Number Distributions
        • Predictable Random Numbers
        • Using the random Module
      2. Terrain Generation
        • Height Maps
        • Mid-Point Displacement
      3. Terrain Generation in Python
      4. Name Generation
      • Summary
  • SECTION V Multiplayer Games
    1. Network Concepts
      1. Network Identification
        • Internet Names
        • IP Addresses
        • Name Translation
        • Port Numbers
        • Subnets
      2. TCP/IP
      3. UDP/IP
      4. Blocking and Nonblocking I/O
      5. Bandwidth
      6. Latency
      7. Byte Ordering
      • Summary
    2. Network Layers
      1. Socket Basics
      2. Sending and Receiving Data
      3. TCP/IP Server Models
        • Connection Management
        • Simple Iterative Server
        • Concurrent Forking Server
        • Concurrent Threaded Server
        • Concurrent Asynchronous Server (Reactor Pattern)
      4. Introduction to Twisted
        • The Twisted Reactor
        • Twisted Protocols
      5. Game Protocol Design
        • Static and Dynamic Protocols
        • Streams and Packing
        • Network Packets
      • Summary
    3. Clients and Servers
      1. Multiplayer Game Architectures
        • Peer-to-Peer Architecture
        • Client/Server Architecture
        • Massively Multiplayer
      2. Code Organization
      3. A Game Server
      4. A Game Client
        • The LobbyFrame class
      • Summary
    4. Multiplayer Game Example
      1. Code Organization
      2. The Tic-Tac-Toe Game
      3. The Game Server
        • The TicTacGame Class
        • The TicTacServerProtocol Class
        • The TicTacServer Class
        • Running the Server
      4. The Tic-Tac-Toe Game Client
        • The Client Protocol
        • The Client Application
        • The TicTacWindow Class
        • Running the Client
      • Summary
  • SECTION VI Advanced Topics
    1. Using the Python C API
      1. The Abstract Object Layer
        • The Object Protocol
        • The Number Protocol
        • The Sequence Protocol
        • The Mapping Protocol
        • Other Protocols
      2. Reference Counting
        • Heap vs. Stack Memory
        • Reference Counting Macros
      3. Exception Handling
      4. Data Conversion
        • Extracting Parameter Values
        • Building Return Values
      5. Concrete Object Layer
        • Fundamental Objects
        • Numeric Objects
        • Sequence Objects
        • Mapping Objects
        • Other Objects
      • Summary
    2. Extending Python
      1. Writing Extension Modules
        • Using Extension Modules
        • Creating an Extension Module
        • Extension Module Example
      2. Writing Extension Types
        • Type Structures
        • Instance Creation and Deletion
        • Member Function of Extension Types
      3. Compiling Extension Code
      4. Automating Interface Generation
        • SWIG
        • Boost.Python
        • Psyco
      • Summary
    3. Embedding Python
      1. Embedding the Interpreter
        • Python Context
        • Executing Python Code
      2. Communicating with the Host Application
      3. Example Application
      4. Project Setup
      • Summary
    • Appendix About the CD-ROM

Reviews

Game Programming with Python

Reviewed by Roland Buresund

OK ***** (5 out of 10)

Last modified: June 11, 2008, 9:23 a.m.

A good introduction to game programming.

It contains advanced concepts in game programming and uses Python to demonstrate them compactly. Of course, you need to understand Python and OO before attempting to read this book. Oh, and don't expect to run the examples in the book, as they in part rely on obsolete GUI libraries that the author has written and not updated for years.

A newer, updated, edition would probably get higher rating, but as it stands now, the deficiencies on the Python side of the book is a drag. But as a introduction to Game Programming, I think it is very worthwhile.

Comments

There are currently no comments

New Comment

required

required (not published)

optional

required

captcha

required