A simple 2D game engine built on top of PySDL2 with physics simulation using pymunk.
Get up and running in 3 steps:
-
Install dependencies:
# Install uv (if not already installed) curl -LsSf https://astral.sh/uv/install.sh | sh # Install SDL2 libraries # macOS: brew install sdl2 sdl2_gfx sdl2_ttf sdl2_image # Linux (Ubuntu/Debian): sudo apt-get install libsdl2-dev libsdl2-gfx-dev libsdl2-ttf-dev libsdl2-image-dev
-
Set up the project:
git clone <repository-url> cd snowid uv sync
-
Run the game:
uv run python project/main.py
That's it! You should see the Balls physics demo scene. Use A/D to move, W to jump, and Left Click to create balls.
For more details, see the Installation and Usage sections below.
SnowID is a lightweight game framework that provides:
- Game Engine: Core game loop, scene management, and rendering
- Physics Engine: Integration with pymunk for 2D physics simulation
- GUI System: Built-in GUI components and console
- Viewport System: Camera and viewport management
- Scene System: Modular scene-based game architecture
- Python 3.11 (required - project uses Python 3.11 features)
- uv - Fast Python package installer and resolver
- SDL2 libraries (SDL2, SDL2_gfx, SDL2_ttf, SDL2_image)
macOS:
brew install sdl2 sdl2_gfx sdl2_ttf sdl2_imageLinux (Ubuntu/Debian):
sudo apt-get install libsdl2-dev libsdl2-gfx-dev libsdl2-ttf-dev libsdl2-image-devWindows:
SDL2 DLL files should be placed in the lib/ directory. You can download them automatically:
make download-dlls
# or
uv run python download_sdl2_dlls.py- Install
uvif you haven't already:
curl -LsSf https://astral.sh/uv/install.sh | shOr via pip:
pip install uv- Install SDL2 libraries (see Requirements section above)
- Clone the repository:
git clone <repository-url>
cd snowid- Install dependencies using uv:
uv syncThis will create a virtual environment and install all dependencies.
- Activate the virtual environment:
source .venv/bin/activate # On macOS/Linux
# or
.venv\Scripts\activate # On WindowsYou can run the game in several ways:
# Using uv (recommended)
uv run python project/main.py
# Or as a module
uv run python -m project.main
# Or activate the virtual environment first
source .venv/bin/activate # On macOS/Linux
python project/main.pyFor debugging and development, you can use the interactive IPython shell:
uv run python -m project.shellsnowid/
├── lib/ # SDL2 DLL files (Windows)
├── stubs/ # Generated type stubs for sdl2 (not committed)
├── project/ # Main application code
│ ├── gamepart/ # Core game engine framework
│ │ ├── gui/ # GUI system components
│ │ ├── physics/ # Physics engine integration
│ │ └── viewport/ # Viewport and camera system
│ ├── scenes/ # Game scenes
│ │ └── balls/ # Example physics scene
│ ├── resources/ # Game assets (fonts, images)
│ ├── main.py # Entry point
│ └── game.py # Main game class
├── generate_stubs.py # Script to generate sdl2 type stubs
├── download_sdl2_dlls.py # Script to download SDL2 DLLs (Windows)
├── pyproject.toml # Project configuration and dependencies
├── mypy.ini # Type checking configuration
└── README.md # This file
This project uses several tools to maintain code quality:
- Black: Code formatter (line length: 88)
- mypy: Static type checking
- Ruff: Fast Python linter (replaces flake8)
- pytest: Testing framework
- pytest-cov: Coverage reporting
First, install dev dependencies:
uv sync --extra dev# Format code (check what would be changed)
uv run black --check project/
# Format code (apply changes)
uv run black project/
# Type checking
uv run mypy project/
# Linting (check)
uv run ruff check project/
# Linting (check and show fixes)
uv run ruff check --output-format=concise project/
# Linting (auto-fix)
uv run ruff check --fix project/
# Format imports (ruff can also format imports)
uv run ruff check --select I --fix project/
# Run all checks (format check, type check, lint)
uv run black --check project/ && uv run mypy project/ && uv run ruff check project/The project uses custom type stubs for the sdl2 module to enable better type checking. The stubs are generated and not committed to the repository. To generate them:
make stubs
# or
uv run python generate_stubs.pyThis generates type stubs in the stubs/ directory with proper types for SDL2 structures and functions.
To add a new dependency:
uv add <package-name>For development dependencies:
uv add --dev <package-name>LOG_LEVEL: Set logging level (default: 0). Use standard Python logging levels (10=DEBUG, 20=INFO, 30=WARNING, 40=ERROR, 50=CRITICAL)PYSDL2_DLL_PATH: Path to SDL2 DLL files (automatically set tolib/directory on Windows)
macOS/Linux: Make sure SDL2 libraries are installed via Homebrew/apt and are in your library path. You can verify with:
brew list sdl2 # macOS
dpkg -l | grep sdl2 # LinuxWindows: Ensure all required SDL2 DLL files are in the lib/ directory.
This project uses pymunk 7.x. If you encounter API compatibility issues, ensure you're using pymunk 7.0 or later. The project has been updated to work with pymunk 7.2.0.
The core game engine provides:
- Game: Main game loop and initialization
- Scene: Base class for game scenes with lifecycle management
- Context: Game context and state management
- SubSystem: Base class for game subsystems
- Time: FPS counter and time management
Physics integration using pymunk:
- World: Physics world and space management
- PhysicalObject: Base class for physics-enabled objects
- Vector: 2D vector utilities
- Category: Collision category management
- GfxRenderer: SDL2 graphics renderer wrapper
- ViewPort: Camera and viewport management
- GraphicalObject: Base class for renderable objects
- System: GUI system manager
- GUIObject: Base class for GUI elements
- Console: Debug console implementation
The project includes example scenes:
- Test Scene: Basic scene template (press F2 to switch)
- Balls Scene: Physics simulation with balls, player, and boundaries
- A/D: Move player left/right
- W: Jump
- E: Shoot
- Left Click: Create a ball at mouse position with velocity
- Right Click: Delete ball at mouse position
- Mouse Wheel: Zoom in/out
- F1: Toggle debug console
- F2: Switch to test scene
- F3: Toggle FPS display
[Add your license here]
Szymon Zmilczak