Graphics & Simulation
Pac-Man
Arcade-faithful clone with per-ghost personality AI and A* pathfinding
Overview
A fully playable Pac-Man clone built from scratch in Java using JOGL for hardware-accelerated 2D rendering, with faithful ghost AI implementing the exact scatter/chase/frightened finite state machine from the original arcade's Pac-Man Dossier. Features A* pathfinding for ghost navigation, per-ghost personality targeting algorithms (Blinky, Pinky, Inky, Clyde), TMX-format level loading, and corner-cutting collision for responsive controls.
Key concepts
Per-Ghost Personality AI
Four targeting algorithms faithful to the arcade: Blinky (direct A* to Pac-Man), Pinky (targets 4 tiles ahead for ambush), Inky (vector-doubling between Blinky and a 2-tile offset creating unpredictable flanking), and Clyde (Euclidean distance threshold -- chases when far, retreats when within 8 tiles).
Code highlights
@Override
protected void AI() {
int tx = target.getX(), ty = target.getY();
int td = target.getDirection();
// 2-tile offset in Pac-Man's facing direction
if (td == 2) { tx += Math.min(2, world.getWidth() - 2 - tx); }
else if (td == 1) { tx -= Math.min(2, tx - 1); }
else if (td == 3) { ty -= Math.min(2, ty - 1); }
else if (td == 4) { ty += Math.min(2, world.getHeight() - 2 - ty); }
// Vector from Blinky to offset, doubled
int v_x = blinky.getX() + (tx - blinky.getX()) * 2;
int v_y = blinky.getY() + (ty - blinky.getY()) * 2;
path = solver.solveMaze(x, y, v_x, v_y);
}Highlights
- — Implemented authentic Pac-Man ghost AI with per-ghost personality targeting algorithms (direct pursuit, 4-tile ambush, vector-doubling flanking, distance-threshold retreat) faithfully matching the original arcade's documented behavior
- — Built A* pathfinding from scratch with Manhattan-distance heuristic, priority-queue expansion, and pre-computed maze grid for real-time navigation of 4 ghosts at 60 FPS
- — Designed a complete game engine architecture with entity hierarchy, time-driven game loop, finite state machine, dual-coordinate movement system, and data-driven TMX level loading
- — Engineered responsive controls via corner-cutting collision -- a per-corner AABB nudge system replicating the original Pac-Man's slide-around-corners feel
Related projects
Monte Carlo Path Tracer + Spline Engine
Physically-based renderer with importance sampling and a functorial spline animation system
View →3D Rendering Engine with Shadow Mapping
Custom OpenGL engine comparing four shadow mapping algorithms with runtime switching
View →Tossing Balls
High school graduation project - 2D physics puzzle game with Box2D integration and data-driven level loading
View →