How alexdantas/sdl2-platformer works
Overall Project Layers & Components
• Game Engine Core: At the heart is the game loop (seen via main.cpp) with a state-driven design (look at GameStateGame, StateManager) handling transitions and game modes.
• Rendering & SDL Wrapper: The SDL.cpp/SDL.hpp files and Window.cpp/Window.hpp are responsible for SDL initialization, rendering, and window management.
• Physics and Collision: With PhysicsManager handling object motion and possibly stepping collisions (e.g., with Player, Bullet, Block).
• Audio Subsystem: Split into Music and SFX managers to deal with the SDL Mixer libraries, playing sound effects and background music.
• Asset Management: Beyond code, assets in directories (fonts, images, sounds) are fundamental – the config.ini and related helper classes may define asset paths and game configurations.
Relationships and Interactions
• The main game loop (in main.cpp) ties together the state management, input processing, physics simulation, and rendering.
• The StateManager dictates which GameState (like GameStateGame) is active; each GameState uses the SDL wrapper, InputManager, and PhysicsManager to update and render the game.
• InputManager receives events through the SDL wrapper and informs game objects (Player, FallingObject, Block, Bullet) about actions to take.
• PhysicsManager interacts with game objects (from classes like Block, Bullet, Player) to handle object movement, collisions, and game dynamics.
• Audio components (SFX and Music) listen to game events (player jumps, collisions) and are triggered via the game logic.
• The helper classes (Utils, Timer, TimerCounter, Log) support debugging, general utilities, and performance timing across the engine.
Architectural Patterns and Design Principles
• Modular design: Components are separated into distinct modules (Input, Physics, Audio, Render) making them reusable.
• State management and game loop: The separation of concerns between game states and the engine loop is a key design pattern.
• Encapsulation: Different types of game objects (DamageableObject, FallingObject, Bullet, Block, etc.) indicate an object-oriented hierarchy, promoting reusability and extendability.
• Use of configuration (config.ini) for decoupling game settings from code.
Relevant Technologies & Dependencies
• SDL 2.0 and its associated libraries (GFX, Image, Mixer, TTF) are central to the project’s execution.
• C++11 features are used, so modern C++ constructs and best practices for game engine development are applied.
• Doxygen comments in the source help document interactions, further justifying a design that clearly shows interfaces and interactions.