feat(debris): rebote contra los limites del playarea (restitution 0.7)

This commit is contained in:
2026-05-21 13:55:32 +02:00
parent ae1d1397b1
commit 7505de074c
2 changed files with 42 additions and 0 deletions
+4
View File
@@ -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
+38
View File
@@ -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;