Sync pygame-a-primer with the updated tutorial - #846
Open
realpython-bot wants to merge 1 commit into
Open
realpython-bot wants to merge 1 commit into
realpython-bot wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 pinnedflake8andblack, 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'sdependenciesfield. pygame has no transitive dependencies, so that single==line is the whole install. This is how the other pygame folders in this repo pin (seeasterioids-pygame-project/*/requirements.txt).Pipfile/Pipfile.lock(removed) — they requiredpython_version = "3.6"(EOL since December 2021, and the article no longer recommends it) and pinnedblack==19.3b0plusflake8, which this repo replaced with theruff==0.14.1pinned in the rootrequirements.txt. Keeping a lockfile that can't resolve on 3.13 next to arequirements.txtthat 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 inPlayer.update()are now four plainifstatements, as the article shows, instead ofif/elifpairs. 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), theimport pygame/import randomsplit back into the two separately commented imports the article numbers as lines 1-5, and thepygame.localsimport back in the article's order withRLEACCELfirst. 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 stylesuper()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 thepip install pygameandrequirements.txtinstall 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 withSDL_VIDEODRIVER=dummyandSDL_AUDIODRIVER=dummy:pygame.QUITafter a few seconds, since the scripts are infinite game loops.py_tutfinal.pyandpy_tut_with_images.pywere also run withpygame.key.get_pressed()patched to cycle through ↑/↓/←/→, so every branch ofPlayer.update()executes, including the four boundary checks and themove_up_sound/move_down_soundplayback. Both runs spawned enemies (and clouds, in the images version) off theUSEREVENTtimers and hit thespritecollideany()collision path, which exercisesplayer.kill(), the sound.stop()/.play()calls, and the mixer shutdown at the end.Collision.oggviapygame.mixer.Sound,Apoxode_-_Electric_1.mp3viapygame.mixer.music.load(), andjet.pngviapygame.image.load().convert().ruff==0.14.1:uvx ruff@0.14.1 format --check pygame-a-primerreports 3 files already formatted anduvx ruff@0.14.1 check pygame-a-primerreports All checks passed!.Nothing outside
pygame-a-primer/is touched.🤖 Generated with Claude Code