Axe Game is a simple, yet engaging, dodge game developed in C++ using the powerful and easy-to-use Raylib library. This project serves as a foundational exercise in game development, focusing on core mechanics such as player input, obstacle movement, and collision detection. Players control a purple circle, aiming to evade a vertically moving red axe for as long as possible.
- Intuitive Player Control: Move the purple circle (player character) smoothly across the screen using either the
W,A,S,Dkeys or theArrow Keysfor flexible input. - Dynamic Obstacle Movement: A red axe (enemy) moves vertically within the game window, demonstrating basic AI behavior and collision response by bouncing off screen edges.
- Precise Collision Detection: Implements accurate collision logic to detect contact between the player and the axe, triggering game-over conditions.
- Clear Game State Management: Transitions to a "Game Over" state immediately upon collision, providing clear feedback to the player.
- Basic Game Loop: Manages frame updates, drawing, and input processing within a simple, robust game loop.
- Start: Compile and run the game executable.
- Movement: Use
W,A,S,Dor theArrow Keysto control the purple circle. - Objective: Dodge the red axe for as long as you can. The game is a test of reflexes and endurance.
- Game Over: If the purple circle collides with the red axe, the game ends instantly.
- Exit: Press the
ESCkey at any time to close the game window.
This project relies on the Raylib library. Before attempting to compile, ensure that Raylib is properly installed and configured on your system.
- C++ Compiler: A modern C++ compiler such as
g++(GNU C++ Compiler),Clang, or MSVC (Microsoft Visual C++). Ensure it supports C++11 or newer standards. - Raylib Library: Download and install Raylib from its official website. Follow the specific installation instructions for your operating system and preferred development environment.
- Clone the repository:
git clone https://github.com/your-username/axe-game.git cd axe-game - Compile the code using the provided Makefile:
make
- The
Makefileis configured to usepkg-configfor locating Raylib's headers and libraries. Ensurepkg-configis installed and Raylib's.pcfile is accessible in your system'sPKG_CONFIG_PATH. - If you encounter linking errors, verify that Raylib is correctly installed and its libraries are discoverable by your compiler (e.g.,
-lraylibflag is properly resolved).
- The
- Run the game:
./axe_game
- Clone the repository.
- Set up Raylib in Visual Studio:
- Follow the comprehensive official Raylib guide for configuring a C++ project in Visual Studio. This typically involves setting up
Include Directories(for headers),Library Directories(for.libfiles), andAdditional Dependenciesin the Linker settings (e.g.,raylib.lib,winmm.lib,gdi32.lib).
- Follow the comprehensive official Raylib guide for configuring a C++ project in Visual Studio. This typically involves setting up
- Add
axe_game.cppto your project: Include the main source file in your Visual Studio project. - Build and run: Use Visual Studio's built-in build and run functionalities (
Ctrl+Shift+Bto build,F5to run).
- Clone the repository.
- Compile using the Makefile: If you are using a Unix-like terminal environment (e.g., Git Bash, MSYS2 MinGW-w64 shell) with MinGW-w64 installed, you can use the
makecommand:make
- Ensure your
PATHenvironment variable includes the MinGWbindirectory.
- Ensure your
- Manual Compilation (Alternative): Alternatively, compile directly using
g++:g++ axe_game.cpp -o axe_game -lraylib -lopengl32 -lgdi32 -lwinmm -static
- The
-lopengl32,-lgdi32, and-lwinmmflags are crucial for linking necessary Windows API libraries that Raylib depends on. The-staticflag can create a standalone executable.
- The
- Run the game:
./axe_game