๐ก PacMan Java Game A simple 2D Pac-Man clone built using Java Swing. This project includes basic mechanics such as:
Pac-Man movement
Ghosts with randomized AI
Wall collisions
Food collection
Life system and score tracking
Basic teleport logic (optional to implement further)
๐ฎ Features Custom tile map rendering with characters representing walls, food, Pac-Man, and ghosts
Smooth keyboard-controlled movement
Basic game loop with timer-based animation (20 FPS)
Ghosts move with randomized directions and can collide with walls
Collision detection for:
Walls
Food pellets
Ghosts (Pac-Man loses a life)
Automatic level reset when all food is eaten
Game over logic with restart on key press
๐งฉ Game Controls โ โ โ โ โ Move Pac-Man in the desired direction
On Game Over, pressing any arrow key will restart the game
๐บ๏ธ Tile Map Key Each character in the tileMap string array represents a tile:
Symbol Meaning X Wall (space) Food pellet P Pac-Man starting point b Blue ghost o Orange ghost p Pink ghost r Red ghost O Teleport zone (visual only currently)
๐ File Structure
bash
Copy code
.
โโโ App.java # Main entry point for launching the game
โโโ PacMan.java # Main game logic, rendering, and event handling
โโโ wall.png # Image for wall tiles
โโโ blueGhost.png # Ghost sprites
โโโ orangeGhost.png
โโโ pinkGhost.png
โโโ redGhost.png
โโโ pacmanUp.png # Pac-Man sprites (for direction changes)
โโโ pacmanDown.png
โโโ pacmanLeft.png
โโโ pacmanRight.png
๐ ๏ธ Technologies Used Java 8+
Java Swing (JFrame, JPanel, Timer, KeyListener)
Object-Oriented Programming (OOP) concepts
Basic game loop and rendering logic
๐ How to Run Compile the project: javac App.java PacMan.java
Run the game: java App
You can also run it from an IDE like IntelliJ IDEA or Eclipse. Just make sure resources (images) are correctly referenced in the classpath.
๐ง Future Improvements Add teleport logic for Pac-Man and ghosts when exiting map edges
Smarter ghost pathfinding (e.g., A* or BFS)
Add sound effects
Create a start menu and end screen
Save high scores
๐ท Screenshots: