Introduction to 2D Game Physics with Pygame

The following sequence of assignments reflects the J-term course given at Gustavus Adolphus College in 2013. This content was originally presented with a mixture of lecture and lab; most of this had verbal explanation. But it's posted here to support future offerings of the course and for the curious out there who may want to try this on their own. It's a great way to gain useful coding experience and learn the Python language.

First, some thanks directed at sites that sparked this one:

• Peter Collingridge's Pygame physics tutorial
• Phil Hassey's pgu module on GUI controls for Pygame
• Chris McCormick's PodSixNet module on multiplayer for Pygame
• The pybox2d project

This tutorial emphasizes the following:

• This is a progression starting from very basic Pygame ideas, through 1D and 2D (pure Python) physics engines, ending with an application of the Box2D physics engine.
• There is a physics instructor behind this, so of course there will be references to things like air tracks and air tables. Time-based physics calculations are separated from any rendering. The engines calculate object position (meters in floating point) based on time intervals in the game loop. Euler's integration method is used (rate calculations). Both impulse and non-impulse collision calculations are made. The hope here is that students do not need formal training in physics (but probably do need some high school math).
• There is attention given to the issue of stickiness (object-penetration correction). This uses an intuitive calculation to determine where the objects would be after the collision had they not penetrated each other.
• I wanted the incentive of a tournament behind the course, so there's multiplayer networking.
• This is all aimed at students of a January-term class. The bulk of this had to be absorbed by the students in about 2.5 weeks (two lectures and a lab each day). This leaves them about a week to do project work in a team.

Each section below has the following:

• An assignment in PDF form that includes a problem statement, reference material, algorithms, conceptual drawings, and (sometimes obfuscated) code hints. The good stuff is in the PDFs.
• Source code in a raw text file and also a colored HTML version.
• A screen-capture video of the code running and rendering in a Pygame window.

Here's a short but growing revision history along with comments on the content scope that was used in the J-term course.