diff --git a/source/core/defaults/border.hpp b/source/core/defaults/border.hpp index 57f6a04..2524281 100644 --- a/source/core/defaults/border.hpp +++ b/source/core/defaults/border.hpp @@ -22,4 +22,8 @@ namespace Defaults::Border { constexpr float BUMP_VELOCITY_REFERENCE = 120.0F; // px/s donen strength 1.0 constexpr float BUMP_MIN_VELOCITY = 20.0F; // sota d'açò no genera bump (filtrar fregaments) + // Bump generat per explosions properes a la paret. + constexpr float EXPLOSION_FALLOFF_PX = 80.0F; // més enllà d'aquesta distància, sense bump + constexpr float EXPLOSION_BASE_STRENGTH = 0.7F; // strength màxim (a 0 px de la paret) + } // namespace Defaults::Border diff --git a/source/game/effects/debris_manager.cpp b/source/game/effects/debris_manager.cpp index 9b8cc3f..12f4cbc 100644 --- a/source/game/effects/debris_manager.cpp +++ b/source/game/effects/debris_manager.cpp @@ -65,6 +65,11 @@ namespace Effects { // Reproducir sonido de explosión Audio::get()->playSound(sound, Audio::Group::GAME); + // Notificar als subscriptors (border, playfield, etc.). + if (explosion_callback_) { + explosion_callback_(centro); + } + const Vec2& shape_centre = shape->getCenter(); // Multiplier: cada segment s'emet N vegades amb direccions aleatòries diff --git a/source/game/effects/debris_manager.hpp b/source/game/effects/debris_manager.hpp index 6681deb..f5b9c97 100644 --- a/source/game/effects/debris_manager.hpp +++ b/source/game/effects/debris_manager.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -22,8 +23,17 @@ namespace Effects { // Manté un pool de objectes Debris i gestiona el seu cicle de vida class DebrisManager { public: + // Notificació opcional cada vegada que es genera una explosió. El + // consumidor pot usar-la per fer reaccionar elements del fons (border + // bumps, pulse del playfield, etc.). + using ExplosionCallback = std::function; + explicit DebrisManager(Rendering::Renderer* renderer); + void setExplosionCallback(ExplosionCallback callback) { + explosion_callback_ = std::move(callback); + } + // Crear explosión a partir de una shape // - shape: shape vectorial a explode // - centro: posición del centro de l'objecte @@ -66,6 +76,7 @@ namespace Effects { private: Rendering::Renderer* renderer_; + ExplosionCallback explosion_callback_; // Pool de fragments (màxim concurrent) // Pentàgon 5 línies × 15 enemics × multiplier 3 = 225 trossos només d'enemics. diff --git a/source/game/scenes/game_scene.cpp b/source/game/scenes/game_scene.cpp index 6b1c36e..3a8e2f5 100644 --- a/source/game/scenes/game_scene.cpp +++ b/source/game/scenes/game_scene.cpp @@ -75,6 +75,21 @@ GameScene::GameScene(SDLManager& sdl, SceneContext& context) border_.bumpAt(hit.contact_point, STRENGTH); }); + // Explosions properes a una paret també generen bump (falloff lineal amb la distància). + debris_manager_.setExplosionCallback([this](Vec2 center) { + const SDL_FRect& zona = Defaults::Zones::PLAYAREA; + const float DIST_LEFT = std::abs(center.x - zona.x); + const float DIST_RIGHT = std::abs((zona.x + zona.w) - center.x); + const float DIST_TOP = std::abs(center.y - zona.y); + const float DIST_BOTTOM = std::abs((zona.y + zona.h) - center.y); + const float MIN_DIST = std::min({DIST_LEFT, DIST_RIGHT, DIST_TOP, DIST_BOTTOM}); + if (MIN_DIST > Defaults::Border::EXPLOSION_FALLOFF_PX) { + return; + } + const float FALLOFF = 1.0F - (MIN_DIST / Defaults::Border::EXPLOSION_FALLOFF_PX); + border_.bumpAt(center, Defaults::Border::EXPLOSION_BASE_STRENGTH * FALLOFF); + }); + // Load stage configuration stage_config_ = StageSystem::StageLoader::load("data/stages/stages.yaml"); if (!stage_config_) {