./setup.sh./run.shOr manually:
source venv/bin/activate
python main.pyAlways activate the virtual environment before working:
source venv/bin/activate # macOS/Linux
# or
venv\Scripts\activate # Windowsdeactivatepip install <package-name>
pip freeze > requirements.txt # Update requirements fileAlways add type hints to function signatures:
def my_function(x: int, y: str) -> bool:
return TrueUse Google-style docstrings:
def example_function(param1: int, param2: str) -> None:
"""Brief description of function.
Args:
param1: Description of param1.
param2: Description of param2.
"""
pass- Use specific imports, not wildcard imports
- Group imports: standard library, third-party, local
- One import per line
# Good
import os
import pygame
from Constants import SCREEN_WIDTH, SCREEN_HEIGHT
# Avoid
from Constants import *- Use UPPER_CASE for constants
- Add type hints with Final
from typing import Final
SCREEN_WIDTH: Final[int] = 800- Classes: PascalCase (e.g.,
GameLoop,EnemyManager) - Functions/methods: snake_case (e.g.,
update_position,check_collision) - Constants: UPPER_SNAKE_CASE (e.g.,
PLAYER_SPEED,MAX_HEALTH) - Private methods: _leading_underscore (e.g.,
_internal_method)
- main.py: Entry point, initializes pygame and starts game loop
- GameLoop.py: Main game loop, handles game state
- Player.py: Player character with movement and combat
- EnemyManager.py: Spawns and manages all enemies
- LevelLoader.py: Loads levels from ASCII maps
- CollisionManager.py: Handles collision detection
- Extend the
Enemyclass - Register in
EnemyManager.spawn() - Add to level ASCII map key
- Create new weapon class extending
pygame.Rect - Add to
Playerclass - Update
Controllerfor input handling
- Create ASCII map string in
LevelLoader - Add level number case in
load()method
Currently no automated tests. To test:
- Run the game
- Test all controls
- Test weapon switching
- Test enemy interactions
- Test level scrolling
ImportError: Make sure virtual environment is activated
source venv/bin/activateMissing Assets: Ensure asset files (_.wav, _.jpg) are in project root
pygame.error: Check pygame version
pip install --upgrade pygameUse proper logging instead of print:
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
logger.debug(f"Player position: {self.x}, {self.y}")- Minimize object creation in game loop
- Use sprite groups for batch rendering
- Cache loaded images
- Profile with cProfile if needed
- Test the game runs without errors
- Check no venv/ files are being committed
- Update requirements.txt if dependencies changed
type: Brief description
Longer description if needed
Types: feat, fix, docs, style, refactor, test, chore
feat: Add double jump mechanic
- Added jump counter to Player class
- Updated jump logic in update_jump()
- Added constant MAX_JUMPS = 2