feat(debris): rebote contra los limites del playarea (restitution 0.7)
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user