A 2D side-scrolling platformer written in C++ with SFML. You play as Dave, running and jumping across three levels to collect gems, grab the trophy and reach the exit door while avoiding hazards.
Brave Dave was built as a university Object-Oriented Programming project. The goal was to write a small but complete game loop from scratch: a class hierarchy for game entities, an axis-aligned collision system, gravity and jumping, sprite-sheet animation, and level loading, using SFML only for windowing, rendering, input and audio.
Everything in the game is driven by a small set of classes. GameObject wraps a sprite, texture and collider; DynamicObject extends it with movement, gravity and animation; Player adds health, score and abilities. Level owns the entities for each stage and runs collision checks, scoring and level transitions.
- Three hand-built levels, each with its own layout and background music
- Running, jumping and gravity with per-face collision resolution against platforms
- Blue and red gems worth different point values, plus a trophy worth a large bonus
- The trophy acts as the key: once collected, the exit door opens and ends the level
- Hazards (weeds and fire) and a patrolling monster that cost the player hearts
- A gun pickup in the final level that lets Dave shoot and destroy the monster
- Moving platforms in the second level
- Sprite-sheet animation for walking and jumping, with footstep, pickup and collect sounds
- On-screen HUD showing score, current level and remaining lives
A/Dto move left and rightWto jumpSpaceto shoot (after picking up the gun)Enterto start from the title screen
The code is organised around a three-level inheritance chain, GameObject to DynamicObject to Player, with encapsulated state exposed through getters and setters. Behaviour that is not a natural "is-a" relationship is composed instead: every GameObject owns a Collider, and every DynamicObject owns a Gravity component and a vector of Animation objects. Collider and Gravity have private constructors and declare their owner as a friend class, so they can only be created as part of the object they belong to.
Other concepts used in the implementation:
- Operator overloading:
Collider::operator^performs a collision test and returns which faces are touching - Constructor and function overloading, plus a user-defined copy constructor for
DynamicObject - Dynamic allocation and STL containers, with levels stored as vectors of
GameObjectandDynamicObjectpointers - Exception handling around collision resolution and life loss, using
std::vector::atandstd::out_of_range - Bit fields for the player's boolean state flags
- Delta-time based movement so speed is independent of frame rate
The repository already includes SFML 2.5.1 under SFML/, so no extra downloads are needed.
- Open
BraveDave_SFML.slnin Visual Studio 2022. - Select the
Debugconfiguration and thex64platform. - Build and run.
A prebuilt binary is also included. Run x64/Debug/BraveDave_SFML.exe directly, keeping it in that folder so it can find the Resources directory and the SFML DLLs next to it.
- C++
- SFML 2.5.1 (graphics, window, audio)
- Visual Studio 2022 (MSVC v143)
