How tahreem7926/subway-surfers-2d works
Purpose and Entry Point
This is a native C++17/SFML 2D endless-runner game. The executable starts in main.cpp, which hands application control to the central game coordinator in GameEngine.cpp / GameEngine.h. CMake builds the binary and copies runtime assets such as asset/song.wav.
Game Engine and State Control
GameEngine.cpp / GameEngine.h owns the SFML window, event polling, frame update loop, rendering, and high-level screens such as menu, active gameplay, pause, and leaderboard. It is the primary boundary between SFML input/window/audio APIs and game-domain objects. Theme.h centralizes visual, layout, and gameplay constants consumed across this layer.
Player Simulation
Player.cpp / Player.h models the runner’s three-lane movement and jump/slide state. The engine translates keyboard input into player actions, then updates player physics each frame. Player state is consumed by collision checks, rendering, and temporary power-up behavior.
Track Generation and Object Lifecycle
TrackManager.cpp / TrackManager.h manages the scrolling world: spawning, advancing, culling, and retaining obstacles, coins, and power-ups. It forms the runtime object-lifecycle boundary, coordinating domain entities held through the custom container in GameList.h. Spawned objects move toward the player as gameplay speed increases.
Interactive World Entities
Obstacle.cpp / Obstacle.h defines train, barrier, cone, and fence behavior and collision requirements. Coin.cpp / Coin.h implements collectible scoring objects and magnet attraction. PowerUp.cpp / PowerUp.h represents timed abilities—magnet, jetpack, shield, double-coin, and score booster—and applies their effects to player, collection, collision, or scoring rules.
Scoring and Persistence
ScoreManager.cpp / ScoreManager.h owns current-score progression, high-score comparison, and local top-three leaderboard persistence. Gameplay events flow from collection, survival, and modifiers into this manager; leaderboard UI reads its stored results through the engine.
Presentation, Audio, and Build Runtime
Rendering is SFML-based, with shared text/shape helpers in UIUtils.cpp / UIUtils.h and menu interactions in Button.cpp / Button.h. The repository includes a bundled font under lilita-one/ and music at asset/song.wav. CMakeLists.txt and CMakePresets.json define CMake-based builds against SFML 2.6 graphics, window, audio, and system libraries.
Main entry points: GameEngine.cpp Game Engine · TrackManager.cpp Track Manager · Player.cpp Player · PowerUp.cpp Power-Ups
Components 16
Game Runtime
- Application Entry
main.cpp - Game Engine · Owns the SFML window, frame loop, screens, input, and rendering.
GameEngine.cpp - Theme Constants
Theme.h - Score Manager · Tracks score and persists the local top-three leaderboard.
ScoreManager.cpp
World Simulation
- Player · Maintains lane movement, jump, slide, and physics state.
Player.cpp - Track Manager · Spawns, advances, culls, and retains scrolling world objects.
TrackManager.cpp - Game List · Stores active world entities.
GameList.h - Obstacles · Trains, barriers, cones, and fences with collision behavior.
Obstacle.cpp - Coins · Provide score and support magnet attraction.
Coin.cpp - Power-Ups · Applies magnet, jetpack, shield, and score modifiers.
PowerUp.cpp
Presentation
- UI Utilities
UIUtils.cpp - Buttons
Button.cpp - Bundled Font
- Background Music
asset/song.wav
Other components
- CMake Build · Builds the C++17 executable with SFML and copies runtime assets.
CMakeLists.txt - SFML 2.6 · Graphics, window, audio, and system APIs.
Connections 24
- CMake Build → Application Entry: builds
- CMake Build → SFML 2.6: links
- CMake Build → Background Music: copies asset
- Application Entry → Game Engine: starts
- Game Engine → SFML 2.6: uses window/input/audio
- Game Engine → Theme Constants: uses
- Game Engine → Player: drives input and updates
- Game Engine → Track Manager: updates and renders
- Game Engine → Score Manager: updates and reads leaderboard
- Game Engine → UI Utilities: renders with
- Game Engine → Buttons: handles menu actions
- Game Engine → Bundled Font: loads
- Game Engine → Background Music: plays
- Track Manager → Game List: retains entities
- Track Manager → Obstacles: spawns and advances
- Track Manager → Coins: spawns and advances
- Track Manager → Power-Ups: spawns and advances
- Obstacles → Player: collision checks
- Coins → Player: collects / attracts
- Coins → Score Manager: awards score
- Power-Ups → Player: modifies state
- Power-Ups → Coins: enables magnet
- Power-Ups → Score Manager: modifies scoring
- Player → Score Manager: survival scoring