COURSE / REAL PRACTICE
Your first Python game loop
Build a playable catch-the-ball game: pure state updates, input, elapsed time, Pygame shapes, scoring and restart.
Read the explanation and diagrams, then work through the practice. Your browser profile supplies your saved progress.
What you’ll work toward
Play a complete desktop catch-the-ball game, test its model without a display, and explain the event → update → render loop. The optional desktop renderer uses pygame-ce; hosted exercises use the Python standard library.
Read an explanation, inspect the diagrams and work through the available checks, debugging exercises and builds. Feedback and prerequisite links guide the next step.
Before you start
This course builds on these skills:
- Composition & collaborator ownership
- Functions, control flow & contracts
- Collections, grouping & deterministic order
Individual lessons can add prerequisites. Your lesson progress shows your actual readiness.
A look inside the first lesson
Keep game state independent from pixels
width, paddle_width, radius = 480, 90, 9
half = paddle_width / 2
print("center", width / 2)
print("paddle bounds", half, width - half)
print("ball center bounds", radius, width - radius)Your lesson sequence
Follow the same units and lessons in either view. Prerequisite links and your practice progress stay with each lesson.
State, input and time
- LESSON 01.01
Keep game state independent from pixels
Compose immutable state objects, define board coordinates and reset counters without opening a window.
Open lesson - LESSON 01.02
Separate held directions from command events
Convert held left/right keys and one-frame commands into a deterministic Controls value.
Open lesson - LESSON 01.03
Move in pixels per second
Scale motion by elapsed seconds, cap stalled frames and clamp the paddle to its legal center bounds.
Open lesson
Shapes and transitions
- LESSON 02.01
Render shapes without changing the game
Translate a World into drawing commands, round at the display boundary and keep model tests independent from Pygame.
Open lesson - LESSON 02.02
Resolve one catch or miss per falling ball
Detect a catch-plane crossing, award one outcome, reset the ball and keep score + misses equal to the turn count.
Open lesson - LESSON 02.03
Make pause, restart and quit explicit transitions
Define command priority, terminal shutdown and restart behavior using a small state machine.
Open lesson