A simple Zelda-style adventure game built with pygame, featuring character selection and pixel-art graphics.
Check it out live at https://kjenney.github.io/python-game-wasm/
- 3 Playable Characters: Choose between Knight, Mage, or Ranger
- Character Selection Screen: Navigate with arrow keys, confirm with Enter/Space
- Movement Controls: Use WASD or Arrow keys to move your character
- Pixel Art Style: Simple, retro-inspired graphics
- Boundary Detection: Characters stay within screen bounds
- Create a virtual environment:
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txtsource venv/bin/activate # If not already activated
python main.py- LEFT/RIGHT Arrow: Navigate between characters
- ENTER or SPACE: Confirm selection
- Arrow Keys or WASD: Move character
- ESC: Quit game
- Knight (Blue) - A brave warrior with strong defense
- Mage (Purple) - A powerful spellcaster with magical abilities
- Ranger (Green) - A swift archer with high speed
Run tests:
source venv/bin/activate
pytest tests/ -vNote: There is a known compatibility issue between pygame 2.6.1 and Python 3.14 regarding the font module during testing. Core game logic tests (9/26 tests) pass successfully. The game runs correctly when executed directly via python main.py.
python-game/
├── main.py # Entry point
├── game.py # Main game logic
├── character_selection.py # Character selection screen
├── characters.py # Character definitions
├── requirements.txt # Dependencies
├── tests/ # Test suite
│ ├── test_characters.py
│ ├── test_character_selection.py
│ └── test_game.py
└── README.md
The game follows pygame best practices (2025):
- Organized game loop structure
- Separation of concerns (characters, game logic, UI)
- Comprehensive test coverage
- Mock-based unit testing
- Async-compatible for WASM deployment
The game can be deployed to run in web browsers using WebAssembly (WASM) via pygbag.
Linux/Mac:
./build_wasm.shWindows:
build_wasm.batManual build:
pygbag --build .The build output will be in build/web/.
Run a local test server:
pygbag .Then open http://localhost:8000 in your browser.
The test server is enabled by default. For debugging, you can access:
http://localhost:8000?-i- Terminal with REPL and sized-down canvashttp://localhost:8000/#debug- Verbose output for troubleshooting
- Create a new branch for GitHub Pages:
git checkout -b gh-pages- Build the WASM version:
pygbag --build .- Copy the build files to the root:
cp -r build/web/* .- Commit and push:
git add index.html python-game.apk favicon.png
git commit -m "Deploy WASM version"
git push origin gh-pages- Enable GitHub Pages in your repository settings, pointing to the
gh-pagesbranch.
- Build the WASM version:
pygbag --build .- Create a ZIP file of the build directory:
cd build/web
zip -r python-game.zip *- Upload to itch.io:
- Go to https://itch.io/game/new
- Set "Kind of project" to "HTML"
- Upload the
python-game.zipfile - Check "This file will be played in the browser"
- Set dimensions to 800x600 (or larger)
- Publish!
- The game uses async/await for browser compatibility
await asyncio.sleep(0)calls in the game loop allow the browser to process events- Works on desktop Python and in web browsers
- No code changes needed to run in either environment
MIT License