diff --git a/source/core/entities/entity.hpp b/source/core/entities/entity.hpp index ff27c1b..83cdd68 100644 --- a/source/core/entities/entity.hpp +++ b/source/core/entities/entity.hpp @@ -1,5 +1,15 @@ // entity.hpp - Clase base abstracta para todas las entidades del juego // © 2025 Orni Attack - Arquitectura de entidades +// +// Cada Entity incluye un Physics::RigidBody como member. Las entidades que +// se simulen físicamente lo configuran en init() y registran en el +// PhysicsWorld del GameScene. Las que no, ignoran el body (queda con +// defaults inocuos: mass=1, radius=0). +// +// Flujo por frame (gestionado por GameScene): +// 1. entity.update(dt) — aplicar fuerzas, decidir lógica +// 2. world.update(dt) — integrar bodies, resolver colisiones +// 3. entity.postUpdate(dt) — sincronizar mirror (center_, angle_) #pragma once @@ -8,6 +18,7 @@ #include #include "core/graphics/shape.hpp" +#include "core/physics/rigid_body.hpp" #include "core/types.hpp" namespace Entities { @@ -16,31 +27,44 @@ class Entity { public: virtual ~Entity() = default; - // Interfície principal (virtual pur) + // Interfaz principal (virtual pur) virtual void init() = 0; virtual void update(float delta_time) = 0; virtual void draw() const = 0; [[nodiscard]] virtual bool isActive() const = 0; - // Interfície de colisión (override opcional) + // Sincronización post-física (override opcional). + // Llamado por GameScene tras world.update(). Default: no-op. + virtual void postUpdate(float /*delta_time*/) {} + + // Interfaz de colisión (override opcional) [[nodiscard]] virtual float getCollisionRadius() const { return 0.0F; } [[nodiscard]] virtual bool isCollidable() const { return false; } - // Getters comuns (inline, sin overhead) + // Getters comunes (inline, sin overhead) [[nodiscard]] const Vec2& getCenter() const { return center_; } [[nodiscard]] float getAngle() const { return angle_; } [[nodiscard]] float getBrightness() const { return brightness_; } [[nodiscard]] const std::shared_ptr& getShape() const { return shape_; } + // Acceso al cuerpo físico (Fase 6+). El PhysicsWorld lo registra + // por puntero; la entidad lo configura en init(). + [[nodiscard]] auto getBody() -> Physics::RigidBody& { return body_; } + [[nodiscard]] auto getBody() const -> const Physics::RigidBody& { return body_; } + protected: - // Estat comú (accés directe, sin overhead) + // Estado común (acceso directo, sin overhead) SDL_Renderer* renderer_; std::shared_ptr shape_; Vec2 center_; float angle_{0.0F}; float brightness_{1.0F}; - // Constructor protegit (clase abstracta) + // Cuerpo físico (Fase 6). Las entidades que se mueven por + // física actualizan center_/angle_ en postUpdate() desde body_. + Physics::RigidBody body_; + + // Constructor protegido (clase abstracta) Entity(SDL_Renderer* renderer = nullptr) : renderer_(renderer), center_({.x = 0.0F, .y = 0.0F}) {} diff --git a/source/game/scenes/game_scene.cpp b/source/game/scenes/game_scene.cpp index 418851d..c646ab7 100644 --- a/source/game/scenes/game_scene.cpp +++ b/source/game/scenes/game_scene.cpp @@ -131,6 +131,11 @@ void GameScene::init() { // Basat en el codi Pascal original: line 376 std::srand(static_cast(std::time(nullptr))); + // Configurar el mundo físico con los límites de la zona de juego. + // Las entidades se registrarán cada una al inicializarse (Fase 6c-e). + physics_world_.clear(); + physics_world_.setBounds(Defaults::Zones::PLAYAREA); + // [NEW] Load stage configuration (only once) if (!stage_config_) { stage_config_ = StageSystem::StageLoader::load("data/stages/stages.yaml"); diff --git a/source/game/scenes/game_scene.hpp b/source/game/scenes/game_scene.hpp index 1169d2b..6ce3164 100644 --- a/source/game/scenes/game_scene.hpp +++ b/source/game/scenes/game_scene.hpp @@ -10,6 +10,7 @@ #include #include "core/graphics/vector_text.hpp" +#include "core/physics/physics_world.hpp" #include "core/rendering/sdl_manager.hpp" #include "core/system/scene_context.hpp" #include "core/system/game_config.hpp" @@ -46,6 +47,9 @@ class GameScene { SceneManager::SceneContext& context_; GameConfig::MatchConfig match_config_; // Configuración de jugadors active + // Mundo físico (Fase 5) — integración cinemática + colisiones + Physics::PhysicsWorld physics_world_; + // Efectes visuals Effects::DebrisManager debris_manager_; Effects::FloatingScoreManager floating_score_manager_;