How daverlon/candy2d works
Project Type and Purpose
• This project is a 2D game engine intended to simplify game development.
• It makes use of SDL2 (and its related libraries) and is designed around the ECS pattern—with entities holding components and systems operating on them—to provide a flexible, modular approach for game development.
Main Components
• Core Game Loop – represented by the src/main.cpp, src/Game.cpp, and src/Game.h files. This component initializes the engine, processes game state, and drives the update-render loop.
• ECS Architecture – Break this down into three main groups:
– Entities: Represented in src/GameClasses/Entity.h and src/GameClasses/EntityManager.h.
– Components: Include various components like Animator, Collider, EnemyAI, Player, SkullBullet, Sprite, Tilemap, Transform (found under src/Components) as well as UI components (under src/UI).
– Systems: Found in src/Systems (e.g., AnimatorSystem, ColliderSystem, etc.). Each manages a specific aspect of the game such as rendering (SpriteSystem), collision detection, enemy AI, and more.
• Scenes – Represented by files in src/Scenes (BaseScene, MainScene). These control what is active during different parts of the game.
• Game Classes and Utilities – Other supporting modules such as GameCamera, GameTime, GameViewPort (src/GameClasses) and utility functions (src/Utils) that handle debugging and math.
• External Resources and Setup – The dependencies folder (with the setup script), compile scripts, and bin directory output illustrate how the engine is built and run.
Relationships and Interactions
• That the main game loop (src/main.cpp) initializes the game and enters a loop, which continuously delegates tasks to various systems.
• That the EntityManager handles the creation and lifecycle of entities, which aggregate one or more components.
• Systems (like AnimatorSystem, PlayerSystem, ColliderSystem, etc.) query and manipulate these entities based on the components they hold.
• Scenes determine which entities and systems are active at any given moment, controlling rendering and input flow.
• Also, note that the UI components are managed separately within the UI module to maintain a clear separation from game logic.
Key Architectural Patterns and Design Principles
• The separation between game logic (e.g., systems and components) and rendering/input (handled maybe by SDL2 via Game and UI subsystems).
• The modular approach (each system/component is designed to be extensible and replaceable).
Specific Elements
– Core Engine/Bootstrapping (Game.cpp, main.cpp)
– ECS elements (Components, Entities, Systems)
– UI layers and support utilities.