diff --git a/source/ball.cpp b/source/ball.cpp index 8cf7147..c4db21a 100644 --- a/source/ball.cpp +++ b/source/ball.cpp @@ -223,4 +223,28 @@ void Ball::setGravityDirection(GravityDirection direction) { gravity_direction_ = direction; on_surface_ = false; // Ya no está en superficie al cambiar dirección stopped_ = false; // Reactivar movimiento +} + +// Aplica un pequeño empuje lateral aleatorio +void Ball::applyRandomLateralPush() { + // Generar velocidad lateral aleatoria (nunca 0) + float lateral_speed = GRAVITY_CHANGE_LATERAL_MIN + (rand() % 1000) / 1000.0f * (GRAVITY_CHANGE_LATERAL_MAX - GRAVITY_CHANGE_LATERAL_MIN); + + // Signo aleatorio (+ o -) + int sign = ((rand() % 2) * 2) - 1; + lateral_speed *= sign; + + // Aplicar según la dirección de gravedad actual + switch (gravity_direction_) { + case GravityDirection::UP: + case GravityDirection::DOWN: + // Gravedad vertical -> empuje lateral en X + vx_ += lateral_speed * 60.0f; // Convertir a píxeles/segundo + break; + case GravityDirection::LEFT: + case GravityDirection::RIGHT: + // Gravedad horizontal -> empuje lateral en Y + vy_ += lateral_speed * 60.0f; // Convertir a píxeles/segundo + break; + } } \ No newline at end of file diff --git a/source/ball.h b/source/ball.h index 5559f86..f971e7a 100644 --- a/source/ball.h +++ b/source/ball.h @@ -43,6 +43,9 @@ class Ball { // Cambia la direcci\u00f3n de gravedad void setGravityDirection(GravityDirection direction); + // Aplica un peque\u00f1o empuje lateral aleatorio + void applyRandomLateralPush(); + // Getters para debug float getVelocityY() const { return vy_; } float getVelocityX() const { return vx_; } diff --git a/source/defines.h b/source/defines.h index f0ee55d..e3cc884 100644 --- a/source/defines.h +++ b/source/defines.h @@ -20,6 +20,10 @@ constexpr float LATERAL_LOSS_PERCENT = 0.02f; // ±2% pérdida lateral en r constexpr float GRAVITY_MASS_MIN = 0.7f; // Factor mínimo de masa (pelota ligera - 70% gravedad) constexpr float GRAVITY_MASS_MAX = 1.3f; // Factor máximo de masa (pelota pesada - 130% gravedad) +// Configuración de velocidad lateral al cambiar gravedad (muy sutil) +constexpr float GRAVITY_CHANGE_LATERAL_MIN = 0.04f; // Velocidad lateral mínima (2.4 px/s) +constexpr float GRAVITY_CHANGE_LATERAL_MAX = 0.08f; // Velocidad lateral máxima (4.8 px/s) + struct Color { int r, g, b; }; diff --git a/source/engine.cpp b/source/engine.cpp index b0fbd23..41379ec 100644 --- a/source/engine.cpp +++ b/source/engine.cpp @@ -388,6 +388,7 @@ void Engine::changeGravityDirection(GravityDirection direction) { current_gravity_ = direction; for (auto &ball : balls_) { ball->setGravityDirection(direction); + ball->applyRandomLateralPush(); // Aplicar empuje lateral aleatorio } }