This repository contains the maze game code for the 1000 coursework.
This code is for a maze game where a player must navigate through a procedurally generated maze to reach an exit door while avoiding enemies. The game features:
- Maze Generation: A maze is generated with walls, a player starting position, an exit door, and enemy positions. some walls are randomly removed for easier navigation in the game and avoiding one path to the exit/player.
- Player Movement: The player can move up, down, left, or right using keyboard input.
- Enemy AI: Enemies move towards the player using a A* pathfinding algorithm.
- Apples: Apples are scattered throughout the maze, and collecting them rewards the player.Apples also stop enemies for 8 seconds.
- Time Limit: The player must complete the level within a time limit.
- Difficulty Levels: The game has multiple difficulty levels, which affect the maze size, enemy speed, and time limit.
- Game Over: The game ends if the player is caught by an enemy or the time limit expires.
- Level Completion: The player completes a level by reaching the exit door, and their progress is saved and are reworded based on the time of completion and amount of apples eaten.
- Main Menu: The game has a main menu with options to start a new game, resume a saved game, change difficulty or quit.
Below is a short preview of the gameplay:
Screen.Recording.2025-01-04.at.23.20.59.mov
This is a university game project that can be set up and run on Windows or Mac using Visual Studio or VS Code. This guide provides detailed instructions for configuring the project and running it successfully.
-
- Download the SFML SDK for Windows.
- Extract the zip file to a directory, e.g.,
C:\SFML. - Add
C:\SFML\binto your system's PATH:- Right-click on "This PC" or "Computer" and select Properties.
- Go to Advanced system settings > Environment Variables.
- Under System Variables, edit the
Pathvariable:- Click New and add
C:\SFML\bin. - Click OK to save.
- Click New and add
-
Install Visual Studio:
- Download and install Visual Studio.
-
Clone the Repository:
- Open Visual Studio and select Clone a repository.
- Enter the repository URL:
https://github.com/mzst-26/PLymouth-Uni-Maze-Game
-
Create a New Project:
- Go to File > New > Project....
- Choose Visual C++ > Empty Project, and name it (e.g.,
Maze Escape).
-
Add SFML to the Project:
- In Solution Explorer, right-click the project and select Properties.
- Configure the following:
- C/C++ > General: Add the include path:
C:\SFML\include - Linker > General: Add the library path:
C:\SFML\lib
- C/C++ > General: Add the include path:
-
Build and Run:
- Right-click the project in Solution Explorer and select Build.
- Once built, select Debug > Start Debugging to run the game.
-
Install SFML:
- Follow the steps in the Install SFML section.
-
Install the C/C++ Extension:
- Open VS Code and click on the Extensions view (or press
Ctrl+Shift+X). - Search for C/C++ and click Install.
- Open VS Code and click on the Extensions view (or press
-
Clone the Repository:
- Open a terminal in VS Code (press
Ctrl+`) and run:git clone https://github.com/mzst-26/PLymouth-Uni-Maze-Game cd PLymouth-Uni-Maze-Game
- Open a terminal in VS Code (press
-
Configure Build Tasks:
- Open the Command Palette (
Ctrl+Shift+P) and select Configure Build Task. - Edit
tasks.jsonas follows:{ "version": "2.0.0", "tasks": [ { "label": "Build Maze Escape", "type": "shell", "command": "g++", "args": [ "-o", "${fileDirname}/${fileBasenameNoExtension}", "${file}", "-I", "C:/SFML/include", "-L", "C:/SFML/lib", "-lsfml-graphics", "-lsfml-window", "-lsfml-system" ], "group": { "kind": "build", "isDefault": true }, "problemMatcher": ["$gcc"] } ] }
- Open the Command Palette (
-
Build and Run:
- Open
main.cpp, then pressCtrl+Shift+Bto build. - Run the executable from the terminal:
or your own build file name
./main.exe
./myBuildFileName.exe
- Open
-
Install SFML:
- Run the following command:
brew install sfml
- Run the following command:
-
Install the C/C++ Extension:
- Search C++ Extension on the apps within VS code.
-
Clone the Repository:
- Open a terminal in VS Code and run:
git clone https://github.com/mzst-26/PLymouth-Uni-Maze-Game cd PLymouth-Uni-Maze-Game
- Open a terminal in VS Code and run:
OR
Download it manually from SFML website: Then follow the instructions on this video:
Screen.Recording.2025-01-05.at.20.35.36.1.1.mov
-
Configure Build Tasks:
-
Edit
tasks.jsonas follows:{ "version": "2.0.0", "tasks": [ { "label": "Build Maze Escape", "type": "shell", "command": "g++", "args": [ "-o", "${fileDirname}/${fileBasenameNoExtension}", "${file}", "-I", "/usr/local/include", "-L", "/usr/local/lib", "-lsfml-graphics", "-lsfml-window", "-lsfml-system" ], "group": { "kind": "build", "isDefault": true }, "problemMatcher": ["$gcc"] } ] } -
Here is my example of
tasks.json:{ "version": "2.0.0", "tasks": [ { "label": "build", "type": "shell", "command": "g++", "args": [ "-std=c++17", "-g", "-I/opt/homebrew/include", "-L/opt/homebrew/lib", "-lsfml-graphics", "-lsfml-window", "-lsfml-system", "-lsfml-audio", "src/maze.cpp", "src/main.cpp", "src/player.cpp", "src/enemy.cpp", "src/a_star.cpp", "src/game.cpp", "src/button.cpp", "src/settingsPopup.cpp", "src/escapeDoor.cpp", "src/levelManager.cpp", "src/winOrLooseWindow.cpp", "src/home.cpp", "src/stars.cpp", "src/scoreBoard.cpp", "src/modules.cpp", "src/apples.cpp", "-o", "build/MysteryMaze" ], "group": { "kind": "build", "isDefault": true }, "problemMatcher": ["$gcc"], "detail": "Compile all source files with SFML" } ] } -
And this is my example of
c_cpp_properties.json:
{ "version": 4, "configurations": [ { "name": "macos-clang-arm64", "includePath": [ "${workspaceFolder}/**" ], "defines": [], "compilerPath": "/usr/bin/clang", "intelliSenseMode": "macos-clang-arm64", "browse": { "path": [ "${workspaceFolder}", "${workspaceFolder}/include", "${workspaceFolder}/include/SFML" ], "limitSymbolsToIncludedHeaders": true }, "cStandard": "${default}", "cppStandard": "${default}" } ] }- And
c_cpp_properties:
{ "version": "0.2.0", "configurations": [ { "type": "lldb", "request": "launch", "name": "Debug", "program": "${workspaceFolder}/build/MysteryMaze", "args": [], "cwd": "${workspaceFolder}", "preLaunchTask": "build" }, { "name": "C/C++ Runner: Debug Session", "type": "lldb", "request": "launch", "args": [], "cwd": "/Users/mobinzaki/Documents/GitHub/PLymouth-Uni-Maze-Game/src", "program": "/Users/mobinzaki/Documents/GitHub/PLymouth-Uni-Maze-Game/src/build/Debug/outDebug" } ] }- All of this configuration files would be in .vscode directory.
-
-
Build and Run:
- Open
main.cpp, then pressCtrl+Shift+Bto build. - Run the executable from the terminal:
or ./yourOwnBuildFileName
./main
- Open
- SFML Issues: Verify that the paths to SFML libraries and headers are correctly set.
- Compilation Errors: Ensure the g++ command or project settings match your setup.
- Additional Help: Refer to the SFML documentation.