Skip to content

Repository files navigation

Pac-Man

A Pac-Man clone written in C++ with raylib, featuring BFS-based ghost pathfinding and a built-in map editor.

Overview

The game runs on a 20x15 grid of cells loaded from CSV map files. Pac-Man eats the pellets scattered across every road cell while four ghosts hunt him. Ghost movement is driven by a breadth-first search over the grid: the BFS builds a shortest path from each ghost's cell to its target, and the ghost steps toward the next cell on that path.

Features

  • 3 maps x 3 difficulties — maps are loaded from assets/Maps/map1.csvmap3.csv.
    • Easy/Medium: ghosts BFS toward random road cells and pick new targets on arrival.
    • Hard: ghosts BFS directly toward Pac-Man's current cell.
  • Map editor — draw your own maze with the mouse, then play it immediately.
  • BFS pathfinding — shortest-path search on the cell grid (Map::FindPath), with optional path coloring.
  • Top-3 high scores — persisted to assets/scores.txt and shown on the win/lose screens.
  • Resizable window — the grid, sprites and speeds rescale with the window.
  • Sound and sprites — background music, chomp effects, animated Pac-Man and ghost sprite sheets.

Tech stack

  • C++ (built with g++)
  • raylib — window, input, audio, 2D rendering
  • raygui — immediate-mode UI for the menus (bundled in raylib/include/raygui.h)

Getting started

Download (Linux)

Grab the latest tarball from the Releases page — raylib is linked statically, so nothing else needs installing:

tar -xzf pacman-v1.0.0-linux-x86_64.tar.gz
cd pacman-v1.0.0-linux-x86_64
./game

Prerequisites (building from source)

  • A C++ compiler (g++) and make
  • raylib installed system-wide — the build links with -lraylib and includes <raylib.h>. On Debian/Ubuntu: sudo apt install libraylib-dev, or build it from source.

Build and run (Linux)

make
./game

Run the binary from the repository root — assets are loaded via relative paths (assets/...).

Windows

Open ConsoleApplication1.sln in Visual Studio and build. The bundled raylib/raylib.lib and the headers in raylib/include/ are used for linking.

Usage

From the main menu:

Option What it does
START GAME Pick a difficulty row (Easy / Medium / Hard) and a level column (Level 1–3)
HOW TO PLAY In-game instructions
CREDITS The team behind the project
CREATE YOUR OWN MAP Draw a maze, then choose a difficulty and play it

In-game controls

  • Arrow keys — move Pac-Man
  • Q or Esc — quit the level (your score is saved)

Map editor controls

  • Left click — place a wall
  • Right click — erase a wall back to road
  • Q — finish drawing and start the game

Each pellet is worth 10 points. Eat them all to win; get caught by a ghost and you lose.

Project structure

Source_files/              Implementation (.cpp)
Header_files/              Headers (.h)
assets/                    Sprites, fonts, sounds, maps (CSV), scores.txt
raylib/                    Bundled raylib/raygui headers + raylib.lib for the Windows build
Makefile                   Linux build
ConsoleApplication1.sln    Visual Studio solution (Windows build)

Key pieces: Map (grid, BFS, pathfinding), Pacman and Ghost (movement, collision, animation), Level (game loop), Menu (raygui screens), mapmaker (map editor), FileIO (map + score persistence).

License

MIT

About

Pac-Man clone in C++ with raylib: 3 maps x 3 difficulties, BFS ghost pathfinding, a built-in map editor, and a top-3 high-score board.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages