A small two‑player arcade style prototype built on SFML 2. Players control a rocket and a robot, earn points via collisions / attacks, and the game features animated sprites, sounds, music, and a simple start/end screen loop.
This repository originated from a Windows Visual Studio project (.vcxproj). This README focuses on building and running the code on macOS (Apple Silicon or Intel) using Homebrew + clang++, and optionally CMake or Xcode.
Note about SFML versions:
- Homebrew may install SFML 3 by default as of late 2025. This code works with SFML 2.x
AnimatedGameObject.* Sprite sheet animation helper
RegularGameObject.* Simple textured sprite wrapper
Game.* Core game loop, input handling, scoring, collisions
GameObject.h Base interface (implied by usage) for drawable/movable objects
main.cpp Start menu + end screen loop; calls Game::run()
resource_path.h Defines resource_path = "elements//" for asset loading
elements/ Asset root (images, audio, fonts, sprite sheets)
content/ (Present but unused in current code – legacy folder)
SkeletonCode.vcxproj* Legacy Visual Studio project files (not used on macOS)
All asset loads are performed via resource_path + filename, meaning the working directory must be the project root (so that elements/ resolves). If you run from another directory (e.g. inside build/), either copy the elements/ folder next to the executable or adjust resource_path.h.
The source includes and APIs from:
- Graphics (
#include <SFML/Graphics.hpp>) – windows, sprites, fonts, text - Audio (
sf::Music,sf::Sound,sf::SoundBuffer) - Window / Events (
sf::RenderWindow,sf::Event) - System (
sf::Clock,sf::Time)
You must link: sfml-graphics sfml-window sfml-system sfml-audio.
- Install Homebrew (if not installed):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"- Install SFML:
brew install sfml@2Homebrew places headers in /opt/homebrew/include or /opt/homebrew/opt/sfml (Apple Silicon) or /usr/local/include (Intel), and libs in the matching lib directory. Use brew --prefix sfml@2 to confirm.
From the project root (so elements/ is visible):
clang++ -std=c++17 \
main.cpp Game.cpp AnimatedGameObject.cpp RegularGameObject.cpp \
-I"$(brew --prefix sfml@2)/include" \
-L"$(brew --prefix sfml@2)/lib" \
-lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio \
-Wl,-rpath,"$(brew --prefix sfml@2)/lib" \
-O2 -o dungeon_game
./dungeon_gameEverything further is ai gerated and untested
mkdir -p build
cd build
clang++ -std=c++17 ../main.cpp ../Game.cpp ../AnimatedGameObject.cpp ../RegularGameObject.cpp \
-I"$(brew --prefix)/include" -L"$(brew --prefix)/lib" \
-lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio \
-Wl,-rpath,"$(brew --prefix)/lib" \
-O2 -o dungeon_game
# Copy assets or adjust resource_path
cp -R ../elements ./
./dungeon_gameAlternative: edit resource_path.h to "../elements//" when running from build/.
Create CMakeLists.txt in the repo root:
cmake_minimum_required(VERSION 3.15)
project(DungeonGame LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(SOURCES
main.cpp
Game.cpp
AnimatedGameObject.cpp
RegularGameObject.cpp
)
# Find SFML (Homebrew install). Accept either 2.x or 3.x
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};$(brew --prefix sfml)")
find_package(SFML REQUIRED COMPONENTS graphics window system audio)
add_executable(dungeon_game ${SOURCES})
target_link_libraries(dungeon_game PRIVATE sfml-graphics sfml-window sfml-system sfml-audio)
# Ensure runtime finds dylibs (embed rpath)
set_target_properties(dungeon_game PROPERTIES
INSTALL_RPATH "$(brew --prefix)/lib"
BUILD_RPATH "$(brew --prefix)/lib"
)Build:
mkdir -p build
cd build
cmake ..
cmake --build . --config Release
cp -R ../elements ./
./dungeon_gameIf find_package fails, supply hints:
cmake -DSFML_DIR="$(brew --prefix sfml)/lib/cmake/SFML" ..If you specifically need SFML 2.x, point SFML_DIR at the 2.x config dir you built/installed.
- Open Xcode, create a new macOS Command Line Tool project (C++).
- Add existing source files (
main.cpp, etc.) to the project. - Drag in the
elements/folder ("Create folder references" so PNG/TTF/WAV ship with build or copy manually later). - In Build Settings:
- Header Search Paths:
$(brew --prefix)/include - Library Search Paths:
$(brew --prefix)/lib
- Header Search Paths:
- In Build Phases > Link Binary With Libraries: Add
libsfml-graphics.dyliblibsfml-window.dyliblibsfml-system.dyliblibsfml-audio.dylib
- Set Runpath Search Paths (
LD_RUNPATH_SEARCH_PATHS):$(inherited) $(brew --prefix)/lib - Ensure working directory set to project root (Scheme > Run > Options) or resource paths updated accordingly.
resource_path.h hardcodes:
const std::string resource_path = "elements//";So the executable must see ./elements/… at runtime. Options:
- Run from repo root.
- Copy
elements/next to produced binary. - Change to an absolute path or use macOS bundle resource logic (future improvement).
Player 1 (Robot): Arrow keys (Right key triggers attack), Numpad 4/6/8/5 also mapped for movement. Player 2 (Rocket): WASD movement, Space triggers attack. Other keys:
Oslow down movement speed.Pspeed up movement speed.Kskip cooldown.Escapecloses the main game window.- Menu interactions: Mouse over Start/Quit images and click.
| Issue | Cause | Fix |
|---|---|---|
dyld: Library not loaded: libsfml-graphics.*.dylib |
Runtime loader can't locate SFML dylibs | Add runpath: compile with -Wl,-rpath,"$(brew --prefix)/lib" OR export DYLD_LIBRARY_PATH=$(brew --prefix)/lib. In CMake set INSTALL_RPATH. |
| Black / empty window | Asset load failure or wrong working dir | Run from repo root or confirm elements/ exists. Check console messages. |
| Fonts/music not found | Wrong resource path | Verify filenames & case (macOS is usually case‑insensitive but Git may differ). |
| High CPU usage | No frame limiting (game runs as fast as possible) | Add sf::sleep or setFramerateLimit(60) on the window. |
| Window scaled oddly / blurry on Retina | Default coordinate scaling | Optionally call window.setView(sf::View(sf::FloatRect(0,0,width,height))); or let macOS scale; adjust assets if blurry. |
| Input lag with key repeat | Using event + boolean toggles without handling key repeat intervals | Acceptable for prototype; to refine, handle KeyPressed vs KeyReleased distinctly and skip toggling on repeat. |
Start screen recursion (calling startgame() repeatedly) |
Design uses recursive call after closing end screen | Acceptable for small scope; for long sessions consider refactoring to a single main loop to avoid deep recursion. |
Additional diagnostics:
otool -L dungeon_game # List linked dylibs
brew info sfml # Confirm install paths- Introduce a unified game state loop (menu, play, end) rather than recursive
startgame()calls. - Replace hardcoded asset dimensions (sprite sheet frame calculations) with metadata.
- Add frame limiting or vertical sync (
m_window.setFramerateLimit(60)orm_window.setVerticalSyncEnabled(true)). - Convert to CMake + package config entirely and remove legacy
.vcxprojfiles. - Introduce error handling / asserts for failed loads beyond
std::coutmessages. - Bundle resources using an app bundle (
.app) and relativeResources/path for macOS distribution.
Fonts and other third‑party assets inside elements/ may carry their own licenses (e.g. SIL Open Font License). Review and preserve any included license files when distributing.
# Install dependencies
brew install sfml
# Build (simple)
clang++ -std=c++17 main.cpp Game.cpp AnimatedGameObject.cpp RegularGameObject.cpp \
-I"$(brew --prefix)/include" -L"$(brew --prefix)/lib" \
-lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio \
-Wl,-rpath,"$(brew --prefix)/lib" \
-o dungeon_game
# Run from project root
./dungeon_game
# If dylib not found
export DYLD_LIBRARY_PATH="$(brew --prefix)/lib"
./dungeon_game# 0. start clean
mkdir -p dist
cp dungeon_game dist/
cp -R elements dist/
cd dist
# 1. put bundled dylibs in a subfolder (e.g., libs)
mkdir -p libs
# 2. bundle & rewrite load paths to @executable_path/libs
# (note: no -oD on "." — we're using ./libs)
dylibbundler -b -x ./dungeon_game -d ./libs -p @executable_path/libs
# 3. sanity check: all non-system deps should point at @executable_path/libs
otool -L ./dungeon_game
otool -L ./libs/libsfml-graphics*.dylib
If the checks look good:
cd ..
zip -r dungeon_game_mac.zip dist