A simple Pacman game built with Python and Tkinter. No external dependencies required!
- Classic Pacman gameplay with maze navigation
- Arrow key controls for smooth movement
- Three ghosts with basic AI (random movement and chase behavior)
- Pellet collection for scoring points
- Collision detection with walls and ghosts
- Win/Lose conditions with restart functionality
- Score tracking displayed in real-time
- Arrow Keys (↑ ↓ ← →): Move Pacman
- Spacebar: Restart game (after game over or win)
- Collect all the yellow pellets (dots) in the maze
- Avoid the colored ghosts (red, pink, cyan)
- Score 10 points for each pellet collected
- Win: Collect all pellets in the maze
- Lose: Get caught by a ghost
- Pacman cannot move through walls (blue blocks)
- Python 3.x (Tkinter is included with standard Python installation)
-
Navigate to the game directory:
cd pacman_game -
Run the game:
python pacman.py
Or on some systems:
python3 pacman.py
-
Start playing! Use arrow keys to move Pacman around the maze.
- Yellow Circle 🟡 - Pacman (you!)
- Blue Blocks 🟦 - Walls (cannot pass through)
- Yellow Dots ⚫ - Pellets (collect for points)
- Red Circle 🔴 - Ghost #1
- Pink Circle 🩷 - Ghost #2
- Cyan Circle 🔵 - Ghost #3
This game demonstrates several programming concepts:
- Object-Oriented Programming: Classes for Pacman, Ghost, and Game
- Game Loop: Continuous update and render cycle
- Collision Detection: Checking for wall and ghost collisions
- Event Handling: Keyboard input processing
- 2D Grid System: Maze representation using a matrix
- Basic AI: Ghost movement algorithms
You can easily customize the game by modifying these constants in pacman.py:
CELL_SIZE = 30 # Size of each grid cell
GRID_WIDTH = 20 # Maze width
GRID_HEIGHT = 20 # Maze height
GAME_SPEED = 150 # Game speed in milliseconds (lower = faster)You can also modify the MAZE layout to create your own custom levels!
pacman.py
├── Constants (colors, sizes, maze layout)
├── Pacman class (player character)
├── Ghost class (enemy AI)
├── PacmanGame class (main game logic)
└── main() function (entry point)
Issue: "No module named 'tkinter'"
- Solution: Tkinter should come with Python. If missing, install it:
- Ubuntu/Debian:
sudo apt-get install python3-tk - macOS: Tkinter is included with Python from python.org
- Windows: Tkinter is included with standard Python installation
- Ubuntu/Debian:
Issue: Game runs too fast or too slow
- Solution: Adjust the
GAME_SPEEDconstant in the code (higher = slower)
Have fun playing Pacman! Try to beat your high score and see how long you can survive against the ghosts.
Created with Python + Tkinter | No external dependencies required