feat(debris): rebote contra los limites del playarea (restitution 0.7)
This commit is contained in:
@@ -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 = 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;
|
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)
|
// Herència de velocity angular (trayectorias curvas)
|
||||||
constexpr float FACTOR_HERENCIA_MIN = 0.7F; // Mínimo 70% del drotacio heredat
|
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
|
constexpr float FACTOR_HERENCIA_MAX = 1.0F; // Màxim 100% del drotacio heredat
|
||||||
|
|||||||
@@ -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) {
|
void DebrisManager::update(float delta_time) {
|
||||||
for (auto& debris : debris_pool_) {
|
for (auto& debris : debris_pool_) {
|
||||||
if (!debris.active) {
|
if (!debris.active) {
|
||||||
@@ -292,6 +327,9 @@ namespace Effects {
|
|||||||
centro.x += debris.velocity.x * delta_time;
|
centro.x += debris.velocity.x * delta_time;
|
||||||
centro.y += debris.velocity.y * 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
|
// 5. Actualitzar rotación VISUAL
|
||||||
debris.angle_rotacio += debris.velocitat_rot_visual * delta_time;
|
debris.angle_rotacio += debris.velocitat_rot_visual * delta_time;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user