This is a C++ implementation of the classic PacMan game using the SFML library. The game includes features such as ghost AI, collision detection, and game state management.
The main motivation behind this project was to explore game development using C++, one of the most widely used programming languages for game development, and SFML, a library that simplifies multimedia tasks such as graphics rendering, audio management, and window handling. This project also provided an opportunity to learn about and implement essential game development concepts like:
- Game loops
- Event handling
- Collision detection
- Basic AI (for enemy movement)
The ultimate goal was to create a fully functional game that could be packaged and released, while focusing on scalability and code structure for future expansion or improvements.
- CMake 3.10 or higher
- SFML 2.5
- A C++ compiler that supports C++14
-
Clone the repository:
git clone https://github.com/YashPatel04/PacMan.git cd PacMan -
Set up SFML:
- Download and install SFML from SFML's official website.
- Set the
SFML_DIRinCMakeLists.txtto the path where SFML is installed. - Add
./your_saved_location/SFML/binto your run configuration or as your environment variable.
-
Build the project:
mkdir build cd build cmake .. make
After building the project, you can run the game executable:
./PacMan- Arrow Keys: Move PacMan
- Enter: Start the game
- Movement: Controlled by the arrow keys.
- Objective: Collect all pellets and avoid ghosts.
- AI: Ghosts have different behaviors based on their type.
- Frightened Mode: Ghosts turn blue and can be eaten by PacMan when an energizer is collected.
- Win: Collect all pellets.
- Lose: Collide with a ghost when it is not in frightened.
main.cpp: Entry point of the game.Pacman.cppandPacman.h: Contains the logic for PacMan's behavior.Ghost.cppandGhost.h: Contains the logic for the ghosts' behavior.Map.cppandMap.h: Manages the game map and pellets.collision.cppandcollision.h: Handles collision detection.Text.cppandText.h: Manages text rendering in the game.
The CMakeLists.txt file is used to configure the build process. It includes paths to SFML and lists all source files.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Commit your changes (
git commit -m 'Add some feature'). - Push to the branch (
git push origin feature-branch). - Open a pull request.
This project serves as a strong foundation for learning game development principles using C++ and SFML. It replicates the classic gameplay of Pac-Man while leaving room for expansion and additional features. Whether you're an experienced programmer or a beginner looking to get into game development, this project offers valuable insights into how games are built from scratch, the challenges involved, and the satisfaction of watching your game come to life.
This project is licensed under GNU GPL LICENSE
. See the LICENSE file for details.
