From 7505de074c9a5a5575e5ed9a2836d0a62c791e16 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 21 May 2026 13:55:32 +0200 Subject: [PATCH] feat(debris): rebote contra los limites del playarea (restitution 0.7) --- source/core/defaults/physics.hpp | 4 +++ source/game/effects/debris_manager.cpp | 38 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/source/core/defaults/physics.hpp b/source/core/defaults/physics.hpp index 96cc9a9..ec64ede 100644 --- a/source/core/defaults/physics.hpp +++ b/source/core/defaults/physics.hpp @@ -35,6 +35,10 @@ namespace Defaults::Physics { constexpr float MIN_SPEED_TO_DIE = 5.0F; // px/s — al cuadrat per evitar sqrt en update constexpr float MIN_SPEED_TO_DIE_SQ = MIN_SPEED_TO_DIE * MIN_SPEED_TO_DIE; + // Rebot contra els límits del PLAYAREA (mateix patró que enemics/ship). + // 0.7 = 70% de l'energia conservada al rebot. + constexpr float RESTITUTION_BOUNDS = 0.7F; + // Herència de velocity angular (trayectorias curvas) constexpr float FACTOR_HERENCIA_MIN = 0.7F; // Mínimo 70% del drotacio heredat constexpr float FACTOR_HERENCIA_MAX = 1.0F; // Màxim 100% del drotacio heredat diff --git a/source/game/effects/debris_manager.cpp b/source/game/effects/debris_manager.cpp index 0c263e0..9d6bdfc 100644 --- a/source/game/effects/debris_manager.cpp +++ b/source/game/effects/debris_manager.cpp @@ -212,6 +212,41 @@ namespace Effects { } } + // Rebot del fragment contra els límits del PLAYAREA (mateix patró que + // PhysicsWorld::resolveBoundsCollisions per a enemics i ships). + static void bounceOffPlayArea(Vec2& centro, Vec2& velocity) { + const auto& bounds = Defaults::Zones::PLAYAREA; + const float MIN_X = bounds.x; + const float MAX_X = bounds.x + bounds.w; + const float MIN_Y = bounds.y; + const float MAX_Y = bounds.y + bounds.h; + constexpr float REST = Defaults::Physics::Debris::RESTITUTION_BOUNDS; + if (centro.x < MIN_X) { + centro.x = MIN_X; + if (velocity.x < 0.0F) { + velocity.x = -velocity.x * REST; + } + } + if (centro.x > MAX_X) { + centro.x = MAX_X; + if (velocity.x > 0.0F) { + velocity.x = -velocity.x * REST; + } + } + if (centro.y < MIN_Y) { + centro.y = MIN_Y; + if (velocity.y < 0.0F) { + velocity.y = -velocity.y * REST; + } + } + if (centro.y > MAX_Y) { + centro.y = MAX_Y; + if (velocity.y > 0.0F) { + velocity.y = -velocity.y * REST; + } + } + } + void DebrisManager::update(float delta_time) { for (auto& debris : debris_pool_) { if (!debris.active) { @@ -292,6 +327,9 @@ namespace Effects { centro.x += debris.velocity.x * delta_time; centro.y += debris.velocity.y * delta_time; + // 4b. Rebot contra els límits del PLAYAREA. + bounceOffPlayArea(centro, debris.velocity); + // 5. Actualitzar rotación VISUAL debris.angle_rotacio += debris.velocitat_rot_visual * delta_time;