This is a simple Pacman clone made as a learning project using Java and JPanel.
It is not a full-featured Pacman game, but a basic attempt to recreate some of the gameplay using Java Swing.
- Basic Pacman movement with arrow keys
- Four ghosts with random movement
- Food pellets to collect
- Score and lives tracking
- Game over and restart functionality
- Java (JDK 8+)
- Java Swing (
JPanel,JFrame,Timer) - Custom image assets for Pacman, ghosts, and walls
-
Requirements:
- Java JDK installed (version 8 or higher)
-
Compile the code:
Open a terminal in thesrcdirectory and run:javac App.java Pacman.java -
Run the game:
java App -
Controls:
- Use the arrow keys to move Pacman.
- Collect all the food pellets to win.
- Avoid the ghosts. If you lose all lives, the game is over.
- Press any arrow key after game over to restart.
This project is a simple try and not as good as the real Pacman game you may have played.
It was made for learning purposes using only Java and basic Swing components.
- The game board is defined by a string array (
tileMap), where each character represents a wall, food, ghost, or Pacman. - The main game logic is handled in the
Pacmanclass, which extendsJPaneland uses ajavax.swing.Timerfor the game loop. - All game objects (Pacman, ghosts, walls, food) are represented as instances of an inner
Blockclass. - Movement and collision detection are handled manually in the code.
- Ghosts move randomly and change direction when hitting a wall.
- The game is rendered by overriding
paintComponent(Graphics g)and drawing all elements each frame. - Keyboard input is handled with the
KeyListenerinterface to control Pacman and restart the game after game over.
Enjoy!