Stack: C++ โข SFML
PacAttack is a modern take on the classic Pac-Man arcade experience, built in C++ using SFML. Featuring advanced Ghost AI behaviors, intelligent pathfinding, dynamic audio cues, precise collision detection, and an adaptive scoring & level progression system, PacAttack aims to deliver both nostalgia and fresh gameplay twists that increase replay value and player engagement.
-
Unique Ghost AI Behaviors
Each ghost has its own decision-making logic and dynamic state changes (chase, scatter, frightened, adaptive), making the maze challenge more engaging and less predictable. -
Intelligent Pathfinding Algorithms
Efficient pathfinding (e.g., A* or BFS with heuristics) ensures ghosts navigate the maze effectively, adapting routes based on player position, level, and game state. -
Dynamic Audio Cues
Contextual sound effects and music transitions (e.g., escalating tension as player collects more points, alert cues when ghosts switch behaviors) enhance immersion and feedback. -
Precise Collision Detection
Robust collision logic calibrates hitboxes for the player (Paccy), ghosts, pellets, power-ups, and walls, ensuring smooth interactions and minimizing glitches. -
Progressive Scoring & Level Progression
An adaptive difficulty system scales Ghost AI aggressiveness and speed based on player performance, unlocking new levels or tweaks (e.g., faster ghost speed, smarter chase patterns) to maintain challenge and retention. -
Cross-Platform Build
Tested on Windows and Linux. Uses C++17 threading and memory management to keep the rendering loop responsive and thread-safe.
The repository is organized into logical modules for readability and maintainability. Example structure:
PacAttack/
โโโ assets/
โ โโโ images/ # Maze layouts, sprites, UI elements
โ โโโ audio/ # Sound effects and music tracks
โ โโโ levels/ # Level definitions (map data, enemy configs)
โโโ src/
โ โโโ main.cpp # Entry point
โ โโโ Paccy.cpp/.hpp # Player character implementation
โ โโโ Ghosts.cpp/.hpp # Ghost class definitions & behaviors
โ โโโ GhostManager.cpp/.hpp # Ghost AI manager, state transitions
โ โโโ MapCollision.cpp/.hpp # Maze collision logic
โ โโโ DrawMap.cpp/.hpp # Rendering maze layout
โ โโโ DrawText.cpp/.hpp # UI text rendering (score, lives, etc.)
โ โโโ ConvertSketch.cpp/.hpp # (Optional) Tools to convert sketchmaps to tilemaps
โ โโโ Chronometer.hpp # Timing utilities (frame timing, AI timers)
โ โโโ AudioManager.cpp/.hpp # Loading & playing audio cues
โ โโโ LevelManager.cpp/.hpp # Handles level loading, progression logic
โ โโโ ScoreManager.cpp/.hpp # Tracks scoring, combos, power-up effects
โ โโโ global.hpp # Global constants, enums, configuration
โโโ images-github/ # Screenshots for README/GitHub display
โ โโโ FileStructure.png
โ โโโ start\_screen.png
โ โโโ gameplay\_1.png
โ โโโ gameplay\_2.png
โโโ Build/ # (Generated) build outputs
โโโ CMakeLists.txt # Build configuration
โโโ README.md # This file
Note: Adjust paths or filenames if your repository layout differs.
- A C++17 (or newer) compiler (e.g., g++, clang++, MSVC).
- SFML (if building from source; note: the project may include static linking of SFML for easier distribution).
- CMake (minimum version 3.10+ recommended).
git clone https://github.com/deepencoding/PacAttack.git
cd PacAttack-
Create a build directory
mkdir build cd build -
Run CMake configuration
cmake ..
-
If SFML is installed system-wide, CMake will find it.
-
If using custom SFML location, set
SFML_DIRor appropriate CMake variables:cmake -DSFML_DIR=/path/to/SFML/lib/cmake/SFML ..
-
-
Build the project
cmake --build .This produces the executable (e.g.,
PacAttackorPacAttack.exe).
From the build directory:
./PacAttack- The game window should open with the start screen.
- Control Paccy through the maze, collect pellets, avoid or chase ghosts when powered up.
- Arrow Keys / WASD: Move Paccy (up/down/left/right).
- P: Pause / Resume game.
- M: Toggle mute audio.
- ESC / Q: Quit to desktop.
(Adjust controls in code or config if different.)
-
Maze Layouts & Levels:
- Level definitions can be stored as text/map files under
assets/levels/. Modify tile representations or add new level files to expand gameplay. - Ghost speed, scatter/chase durations, power-up timings can be tweaked in
global.hppor a dedicated config struct.
- Level definitions can be stored as text/map files under
-
Ghost AI Parameters:
- Tweak pathfinding heuristics (e.g., weight factors) in
GhostManager. - Adjust state transition thresholds (e.g., when ghosts switch from chase to scatter) based on level or score.
- Tweak pathfinding heuristics (e.g., weight factors) in
-
Audio Settings:
- Audio files are in
assets/audio/. Replace or add cues for new events (e.g., level-up jingle, extra life sound). - Volume levels and transition logic live in
AudioManager.
- Audio files are in
-
Rendering & Performance:
- Frame rate cap and timing logic in
Chronometer.hpp. - Sprite sheets or textures can be updated in
assets/images/; ensure collision boxes align with new visuals.
- Frame rate cap and timing logic in
-
State Machine: Each ghost cycles through states (Scatter, Chase, Frightened, Eaten). Transitions depend on timers, player actions (e.g., eating power pellet), and adaptive difficulty.
-
Adaptive Difficulty: Monitor player performance (e.g., pellet collection rate, lives remaining). If player excels, increase ghost speed or reduce scatter time to raise challenge; if struggling, ease parameters.
-
Pathfinding:
- Implement A* (or BFS with heuristics) on the maze graph: nodes represent tile centers, edges represent valid moves.
- Heuristics may include Manhattan distance or more advanced cost functions factoring in dynamic obstacles.
-
Dynamic Audio Integration:
- When ghosts enter certain AI states (e.g., near-catch, frightened ending), trigger distinct audio cues for player feedback.
- Background music tempo may shift subtly as player nears completion of level or power-up expiration.
-
Tile-Based vs. Pixel-Based:
- Use tile grid for coarse collision detection (walls vs. entities).
- Use bounding boxes/circles for finer collisions (e.g., Paccy vs. ghost when closeness threshold met).
-
Smooth Movement:
- When turning corners, allow buffered inputs so player doesnโt feel โstuckโ on grid intersections.
- Ghosts use similar buffering for path recalculation.
- Pellet & Power-Up Scoring: Each pellet adds to score; power pellets trigger frightened mode and bonus scoring when eating ghosts.
- Combo Tracking: Track consecutive ghost-eatings within a single power-up for exponential score multipliers.
- Level Advancement: After clearing all pellets, transition to next maze layout. Increase difficulty by adjusting ghost speed, AI aggressiveness, or introducing new map elements.
- High Scores: Optionally store high scores locally or via simple file I/O. (Extendable to online leaderboards.)
- Prebuilt Binaries:
Check the Releases page to download precompiled binaries (e.g.,
PacAttack-binaries-v1.0.0.zip). Unzip and run the executable directlyโno SFML install needed if statically linked. - Building from Source: Follow the Getting Started section above. Ensure SFML dependency is satisfied.
- New Ghost Types: Add classes with custom behaviors (e.g., ambusher, ambivalent ghost).
- Power-Ups & Items: Introduce new power-ups (speed boost, temporary shield) and handle their integration in AI and scoring.
- Multiplayer Mode: Experiment with local co-op or networked play (requires networking layer and sync logic).
- Theming & Graphics: Swap sprite sets or add animations (e.g., animated mouth, ghost sprites), adjust UI overlays.
- Analytics & Metrics: Log gameplay stats to fine-tune difficulty curves or for player feedback dashboards.
- Fork the repository.
- Create a branch:
git checkout -b feature/awesome-ghost-ai. - Commit changes with clear messages.
- Open a Pull Request against
main. - Ensure code compiles on supported platforms; add/update tests or demo scenes if applicable.
- Follow the existing style and architecture patterns.
We welcome improvements in AI, new levels, art assets, audio design, performance optimizations, and more!
This project is released under the MIT License. See LICENSE for details.
@deepencoding โ Passionate about game development, AI behaviors, and delivering smooth, engaging gameplay experiences. Feel free to open issues or discuss feature ideas!


