Skip to main content
2015 Java JOGL OpenGL

Pac-Man

Arcade-faithful clone with per-ghost personality AI and A* pathfinding

Pac-Man screenshot

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.

Code Highlights

Inky's vector-doubling AI
@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