Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brave Dave

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.

Gameplay

Gameplay

About

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.

Features

  • 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

Controls

  • A / D to move left and right
  • W to jump
  • Space to shoot (after picking up the gun)
  • Enter to start from the title screen

Technical Overview

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 GameObject and DynamicObject pointers
  • Exception handling around collision resolution and life loss, using std::vector::at and std::out_of_range
  • Bit fields for the player's boolean state flags
  • Delta-time based movement so speed is independent of frame rate

How to Run

The repository already includes SFML 2.5.1 under SFML/, so no extra downloads are needed.

  1. Open BraveDave_SFML.sln in Visual Studio 2022.
  2. Select the Debug configuration and the x64 platform.
  3. 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.

Technologies

  • C++
  • SFML 2.5.1 (graphics, window, audio)
  • Visual Studio 2022 (MSVC v143)

About

A 2D Platformer Game in C++ and SFML. Collect gems, grab the trophy, reach the door across three levels. OOP Project, 2023.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages