A 2D platformer game built with Python and Pygame, featuring state management, multiple enemy types, collectible items, and level progression.
This platformer game implements classic side-scrolling gameplay with modern software architecture patterns. The game features a state management system for handling different game screens (menu, gameplay, game over), player combat mechanics with projectiles, various enemy AI behaviors, collectible items for health and progression, and a save/load system for game progress.
- State Management System: Clean separation between menu, gameplay, and game over states
- Player Mechanics:
- Movement and jumping physics
- Shooting system with bullet projectiles
- Health system with visual indicators
- Enemy Types:
- Walking enemies with patrol behavior
- Ghost enemies with unique movement patterns
- Collectibles:
- Hearts for health restoration
- Keys for unlocking areas/progression
- Level completion portals
- Level System:
- Multiple levels with custom maps
- Save/load functionality for game progress
- Asset Management: Organized sprite and image assets for all game entities
- Python 3.x
- Pygame - Game development framework for graphics, input handling, and game loop
python-platformer/
├── PythonGame/
│ └── src/
│ ├── main.py # Entry point and game loop
│ ├── save_data.json # Player progress save file
│ ├── player/
│ │ ├── player.py # Player character controller
│ │ └── bullet.py # Projectile mechanics
│ ├── enemies/
│ │ ├── walking_enemy.py # Ground-based enemy AI
│ │ └── ghost_enemy.py # Flying enemy AI
│ ├── pickups/
│ │ ├── heart.py # Health pickup item
│ │ ├── key.py # Key collectible
│ │ └── next_level.py # Level transition portal
│ ├── levels/
│ │ └── level.py # Level loader and manager
│ ├── misc/
│ │ ├── global_settings.py # Game configuration (resolution, FPS)
│ │ ├── state_manager.py # State machine controller
│ │ ├── game_state.py # Base state interface
│ │ ├── menu_state.py # Main menu implementation
│ │ ├── play_state.py # Active gameplay state
│ │ └── gameover_state.py # Game over screen
│ └── assets/
│ ├── player/ # Player sprite sheets
│ ├── walking_enemy/ # Walking enemy sprites
│ ├── ghost_enemy/ # Ghost enemy sprites
│ ├── bullets/ # Projectile graphics
│ ├── pickups/ # Collectible item sprites
│ ├── platforms/ # Platform tile graphics
│ ├── maps/ # Level map data
│ ├── map_test.png # Test level image
│ └── map_test_2.png # Second test level
└── README.md
- Clone the repository:
git clone https://github.com/a1fut/python-platformer.git
cd python-platformer-
Install Python 3.x (if not already installed):
- Download from python.org
-
Install Pygame:
pip install pygameRun the game from the project directory:
cd PythonGame/src
python main.py- Arrow Keys / A/D - Move left/right
- Space - Jump
- Mouse Click / Shoot Key - Fire projectiles
- ESC - Pause/Menu
The game uses a State Pattern for managing different game screens:
StateManager: Handles state transitions and delegates eventsMenuState: Main menu interfacePlayState: Active gameplay with player, enemies, and level managementGameOverState: End screen with restart options
Game settings (screen dimensions, FPS, colors) are centralized in global_settings.py for easy configuration.
Player progress is automatically saved to save_data.json, tracking:
- Current level
- Health status
- Keys collected
- Game completion status