A classic PacMan arcade game built from scratch in Java using Swing.
- Navigate PacMan through the maze eating all the dots
- Avoid the 4 ghosts — Blue, Red, Pink, and Orange
- Eat all pellets to advance to the next level
- You start with 3 lives — lose them all and it's game over
- Press any arrow key after Game Over to restart
| Key | Action |
|---|---|
| ⬆️ Arrow Up | Move Up |
| ⬇️ Arrow Down | Move Down |
| ⬅️ Arrow Left | Move Left |
| ➡️ Arrow Right | Move Right |
| Any arrow key (on Game Over) | Restart game |
Requires Java 21 or later — Download Java
- Go to the Releases page
- Download
PacMan.jar - Run it:
Or simply double-click
java -jar PacMan.jar
PacMan.jarif Java is set as the default handler.
- Java 21+ JDK
make(comes pre-installed on macOS/Linux; on Windows use WSL or Git Bash)
# Clone the repo
git clone https://github.com/dev-kvt/pacman.git
cd pacman
# Compile and package
make jar
# Run
java -jar PacMan.jarOr run directly without packaging:
make build
java -cp bin AppPacMan/
├── src/
│ ├── App.java # Entry point — sets up JFrame
│ ├── PacMan.java # Game logic, rendering, input
│ └── assets/ # PNG sprites & icon
├── bin/ # Compiled .class files (git-ignored)
├── Makefile # Build & package commands
├── MANIFEST.MF # JAR entry point declaration
└── .gitignore
- HashSet used for walls, foods and ghosts for O(1) lookup
- javax.swing.Timer drives the 20 FPS game loop
- AABB collision detection for walls, ghosts and food
- Ghost AI: random direction changes on wall collisions; forced upward escape from spawn room
MIT — free to use, fork, and build upon.
Made with ☕ and Java by Divyansh