A browser-based clone of the classic Pacman game built with HTML, CSS, and JavaScript. The game features a playable Pacman character, ghost enemies with AI behavior, a complete map, scoring, and lives.
- Responsive canvas-based rendering
- Playable Pacman character that moves smoothly on a grid
- Ghosts with:
- Random wandering behavior
- Pathfinding AI using Breadth-First Search (BFS) when Pacman is within detection range
- Food pellets scattered across the map
- Score tracking and lives system
- "Game Over" screen with automatic restart after delay
- Keyboard controls (Arrow keys / WASD)
├── assets/
│ ├── animations.gif <- GIF animation for Pacman
│ └── ghost.png <- Ghost images
├── index.html <- Main HTML file
├── css/
│ └── styles.css <- Styling for canvas and UI
├── js/
│ ├── ghost.js <- Ghost enemy AI and movement logic
│ ├── main.js <- Game loop, rendering, and initialization
│ └── pacman.js <- Pacman character logic-
Clone the repository:
git clone https://github.com/trigologiaa/pacman-in-javascript.git cd pacman-in-javascript -
Open the game:
Open
index.htmlin your preferred web browser.
| Key | Action |
|---|---|
| Arrow Keys | Move Pacman |
| WASD | Move Pacman |
- Wandering: Ghosts select random targets from 4 preset map corners.
- Chasing: When Pacman enters their detection range, ghosts use BFS to calculate the shortest path toward Pacman.
You can modify the game map, speed, or ghost behaviors by editing js/main.js and js/ghost.js:
- Change
maparray to redesign levels - Adjust
oneBlockSizefor scaling - Tweak ghost speed or range for difficulty
This project is licensed under the MIT License. See LICENSE for details.
- For questions or contributions, please open an issue or contact the author.
This project is an unofficial, fan-made clone inspired by the classic Pac-Man game.
It is created for educational purposes only and is not affiliated with or endorsed by Namco or Bandai Namco Entertainment.
All original Pac-Man trademarks, graphics, and sounds belong to their respective owners.