A classic PacMan arcade game implementation built with Java Swing. Navigate through the maze, collect dots, avoid ghosts, and rack up points in this nostalgic recreation of the timeless classic.
- ๐น๏ธ Classic Gameplay: Control PacMan with arrow keys through a maze filled with dots
- ๐ป Four Ghost Enemies: Red, Pink, Orange, and Blue ghosts with autonomous movement AI
- ๐ฏ Score Tracking: Earn 10 points for each dot collected
- โค๏ธ Lives System: Start with 3 lives - avoid the ghosts or lose a life
- โธ๏ธ Pause Functionality: Press 'P' to pause/resume the game
- ๐ Level Progression: Complete the maze to advance to the next level
- ๐จ Retro Graphics: Authentic pixel art sprites for PacMan and ghosts
- Java Development Kit (JDK) 8 or higher
- A Java IDE (IntelliJ IDEA, Eclipse, VS Code) or command line tools
git clone https://github.com/Carlsmeister/PacMan.git
cd PacMan- Open the project in IntelliJ IDEA
- Locate
src/Main.java - Right-click on the file and select "Run 'Main.main()'"
# Compile the Java files
javac src/*.java
# Run the game
java -cp src Main| Key | Action |
|---|---|
| โ | Move Up |
| โ | Move Down |
| โ | Move Left |
| โ | Move Right |
| P | Pause/Resume |
- Objective: Collect all the white dots in the maze while avoiding the four colored ghosts
- Scoring: Each dot is worth 10 points
- Lives: You start with 3 lives. Contact with a ghost costs one life
- Game Over: The game ends when all lives are lost. Press any key to restart
- Level Complete: Collecting all dots loads a new level with reset positions
- Plan your route to avoid getting cornered by ghosts
- Use the maze walls strategically to escape ghosts
- Watch the ghost movement patterns to predict their paths
PacMan/
โโโ src/
โ โโโ Main.java # Application entry point
โ โโโ MainFrame.java # JFrame window setup
โ โโโ PacMan.java # Main game logic and rendering
โ โโโ Block.java # Entity class (PacMan, ghosts, walls)
โ โโโ *.png # Game sprites and assets
โ โโโ ...
โโโ .idea/ # IntelliJ IDEA configuration
โโโ PacMan.iml # IntelliJ module file
โโโ .gitignore
- Main.java: Entry point that initializes the game window
- MainFrame.java: Sets up the JFrame with proper dimensions (608x672 pixels)
- PacMan.java: Core game engine handling:
- Game loop (50ms tick rate)
- Collision detection
- Score and lives management
- Rendering (Graphics2D)
- Keyboard input handling
- Block.java: Represents all game entities (PacMan, ghosts, walls, food) with position, velocity, and direction properties
- Board Size: 19 columns ร 21 rows
- Tile Size: 32ร32 pixels
- Game Resolution: 608ร672 pixels
- Frame Rate: ~20 FPS (50ms refresh)
- Ghost AI: Random direction changes with collision avoidance
The game features:
- A classic maze layout with walls and corridors
- Four distinctly colored ghosts (red, pink, orange, blue)
- Directional PacMan sprites that change based on movement
- Clean black background with white food pellets
- Score and lives display at the top
Potential improvements for the project:
- Power pellets that allow PacMan to eat ghosts temporarily
- Different ghost AI behaviors (chase, scatter, frightened modes)
- Sound effects and background music
- High score persistence
- Multiple maze layouts
- Difficulty levels
Contributions are welcome! If you'd like to improve the game:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Carlsmeister - GitHub Profile
- Inspired by the original PacMan arcade game by Namco (1980)
- Sprite assets created for this educational project
- Built as a Java Swing learning exercise
Enjoy the game! ๐ฎ๐พ