Skip to content

Sync pygame-a-primer with the updated tutorial - #846

Open
realpython-bot wants to merge 1 commit into
masterfrom
maintenance/pygame-a-primer-20260916
Open

realpython-bot wants to merge 1 commit into
masterfrom
maintenance/pygame-a-primer-20260916

Conversation

@realpython-bot

Copy link
Copy Markdown
Collaborator

The maintenance update of Pygame: A Primer on Game Programming in Python re-pins the tutorial from Python 3.6 / pygame 1.9.6 to Python 3.13 / pygame 2.6.1, so the companion code in pygame-a-primer/ needed to catch up. The folder still shipped a Pipfile that required Python 3.6 and pinned flake8 and black, and the three scripts had drifted away from the listings the article actually shows.

What changed

  • requirements.txt (new)pygame==2.6.1, matching the article's dependencies field. pygame has no transitive dependencies, so that single == line is the whole install. This is how the other pygame folders in this repo pin (see asterioids-pygame-project/*/requirements.txt).
  • Pipfile / Pipfile.lock (removed) — they required python_version = "3.6" (EOL since December 2021, and the article no longer recommends it) and pinned black==19.3b0 plus flake8, which this repo replaced with the ruff==0.14.1 pinned in the root requirements.txt. Keeping a lockfile that can't resolve on 3.13 next to a requirements.txt that can would only confuse readers.
  • pygame_simple.py, py_tutfinal.py, py_tut_with_images.py — resynced with the article's code blocks. No behavior changes apart from one: the four screen-boundary checks in Player.update() are now four plain if statements, as the article shows, instead of if/elif pairs. Everything else is the article's current comment wording ("Set up the drawing window", "Instantiate player. Right now, this is just a rectangle.", "Add a new enemy?", "All done! Stop and quit the mixer.", and so on), the import pygame / import random split back into the two separately commented imports the article numbers as lines 1-5, and the pygame.locals import back in the article's order with RLEACCEL first. Ruff's isort rules are not enabled in this repo (ignore = ["I"]), so the article's ordering passes the gates. super(Player, self).__init__() is deliberately left alone — the research pass filed the Python 2 style super() calls as a LOW pedagogical issue for a human, and the article still shows them.
  • readme.md — was a one-line stub saying "Link TBD". It now links the tutorial, states the Python 3.13 / pygame 2.6.1 versions, shows both the pip install pygame and requirements.txt install paths, and explains what each of the three scripts is and that they must be run from inside the folder so the images and sounds resolve.

How this was verified

On a fresh Python 3.13.14 virtualenv installed from the new requirements.txt (pygame 2.6.1, SDL 2.28.4), headless with SDL_VIDEODRIVER=dummy and SDL_AUDIODRIVER=dummy:

  • All three scripts run to a clean exit. A watchdog posts pygame.QUIT after a few seconds, since the scripts are infinite game loops.
  • py_tutfinal.py and py_tut_with_images.py were also run with pygame.key.get_pressed() patched to cycle through ///, so every branch of Player.update() executes, including the four boundary checks and the move_up_sound / move_down_sound playback. Both runs spawned enemies (and clouds, in the images version) off the USEREVENT timers and hit the spritecollideany() collision path, which exercises player.kill(), the sound .stop() / .play() calls, and the mixer shutdown at the end.
  • Asset loading was confirmed directly: Collision.ogg via pygame.mixer.Sound, Apoxode_-_Electric_1.mp3 via pygame.mixer.music.load(), and jet.png via pygame.image.load().convert().
  • Repo gates with the pinned ruff==0.14.1: uvx ruff@0.14.1 format --check pygame-a-primer reports 3 files already formatted and uvx ruff@0.14.1 check pygame-a-primer reports All checks passed!.

Nothing outside pygame-a-primer/ is touched.

🤖 Generated with Claude Code

…on Game Programming in Python

The tutorial is now pinned to Python 3.13 / pygame 2.6.1, so the folder
gets a pinned requirements.txt and loses the Python 3.6 Pipfile that
pinned flake8 and black. The three scripts are brought back in line with
the listings in the article, and the readme now links the tutorial and
explains how to run the examples.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant