# Introduction to 2D Game Physics with Pygame

(revisions) (ttc)

The following sequence of topics 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. 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.

Many of the topics on this page are demonstrated at www.timetocode.org using a live HTML-5 Canvas. Here's a link to Puck Popper.

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, there are references to things like: air tracks and air tables, separation of rendering from floating-point calculation engines, Euler's method, impulse and non-impulse collision calculations, and object-penetration correction (anti-stickiness). Students need only have experience with vectors.
• Multiplayer networking supports tournament play.
• This content is aimed at students of a January-term class. Much has to be absorbed in about 2.5 weeks (two lectures and a lab each day), leaving about a week for team-based project work.

Each topic 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
• A screen-capture video of the code running and rendering in a Pygame window (the videos can also be viewed from this playlist).

The revision history includes a discussion of the scope of the J-term course.