Investigations

Pac-Man TypeScript

TypeScript December 2025

A faithful recreation of the classic 1980 Pac-Man arcade game built with TypeScript, WebGL rendering, and 190 TDD tests.

I've always thought Pac-Man was the perfect game to reimplement — it's simple enough that everyone knows the rules, but the ghost AI is surprisingly deep once you dig into it. So I built the whole thing from scratch in TypeScript with WebGL rendering.

The maze is the original 28x31 grid, and all four ghosts have their authentic personalities. Blinky chases you directly, Pinky tries to ambush by targeting 4 tiles ahead of you, Inky calculates an erratic target using Blinky's position as a reference point, and Clyde gets shy and retreats to his corner when he's too close. The scatter/chase mode cycling matches the original arcade timing.

The rendering uses custom WebGL shaders for GPU-accelerated graphics with batched draw calls. Sound is synthesised via the Web Audio API — no audio files, just waveforms that capture that retro feel. Controls have responsive cornering with input buffering so you can queue up turns before reaching an intersection.

The entire project was built with strict TDD. There are 190 passing tests covering vector math, maze navigation, Pac-Man movement and animation, ghost AI behaviours, collision detection, and the rendering system. I find TDD works especially well for game logic — each ghost personality is independently testable.

What this project demonstrates

Faithful recreation of original Pac-Man with 28x31 maze
WebGL GPU-accelerated rendering with custom shaders
All 4 ghost AI personalities: Blinky, Pinky, Inky, Clyde
Scatter/chase mode cycling with power pellet mechanics
190 passing TDD tests covering all game systems
Synthesised retro sound via Web Audio API

Technologies

WebGLGameTDDVitestArcade

© 2026 Jonathan Leahy · v0.8.1-31-g196fa14