A high-performance 2D arcade shooter built from scratch using C++ and SDL2. This project serves as a practical implementation of game engine architecture, design patterns, and vector-based physics.
demo.mp4
Designed for an intuitive, mouse-driven arcade experience:
- Aiming: Rotate the cannon in a 360-degree radius by moving the Mouse.
- Firing: Launch projectiles by clicking the Left Mouse Button.
- Movement: The cannon's orientation is calculated in real-time based on your cursor's position.
- Factory Method Pattern: Utilized
clsChickenFactoryandclsShotFactoryto encapsulate object creation. This decouples the game loop from entity instantiation, allowing for scalable waves of enemies. - Manager Pattern: The
clsGameFieldacts as the central engine, coordinating physics updates, collision detection, and the rendering subsystem. - Game Loop & Timing: Implemented
SDL_GetTicks()to manage frame-independent logic, ensuring consistent fire rates and smooth entity updates regardless of CPU speed.
-
Vector-Based Movement: A custom
clsVectorclass serves as the mathematical foundation for all position and velocity updates. -
Trigonometric Trajectories: Projectile paths are calculated using
atan2,sin, andcosto map mouse coordinates to precise firing vectors. -
AABB Collision Detection: Implemented Axis-Aligned Bounding Box (AABB) checks via
SDL_HasIntersectionfor efficient$O(n \times m)$ hit detection.
-
Node-Based Entity Management: Built using
std::list<T*>to ensure$O(1)$ complexity for frequent insertions and deletions. This approach avoids the "shifting" overhead of contiguous arrays, making it ideal for high-speed arcade shooters. - Fragmentation Resistance: By utilizing a linked list, the game maintains stable performance during intense gameplay by avoiding memory fragmentation and reallocations common in dynamic arrays.
- Manual Lifecycle Control: Carefully managed heap-allocated objects through a list of pointers. This allows for polymorphic behavior (supporting different chicken types) while ensuring manual memory cleanup to prevent leaks.
Ensure you have the SDL2 development libraries installed on your Ubuntu/Linux system:
sudo apt update
sudo apt install libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev - Clone the repository:
git clone https://github.com/Ahmed-Gamal24/Chicken-Invaders-Game.git
cd Chicken-Invaders-Game- Compile the project
make - Run the game:
./chicken_invaders