diff --git a/source/ball.cpp b/source/ball.cpp index 0733db0..2d4b448 100644 --- a/source/ball.cpp +++ b/source/ball.cpp @@ -39,7 +39,15 @@ void Ball::update(float deltaTime) // Actualiza la posición en función de la velocidad (píxeles/segundo) pos_.x += vx_ * deltaTime; - pos_.y += vy_ * deltaTime; + if (!on_floor_) + { + pos_.y += vy_ * deltaTime; + } + else + { + // Si está en el suelo, mantenerla ahí + pos_.y = SCREEN_HEIGHT - pos_.h; + } // Comprueba las colisiones con el lateral izquierdo if (pos_.x < 0) @@ -67,7 +75,7 @@ void Ball::update(float deltaTime) { pos_.y = SCREEN_HEIGHT - pos_.h; vy_ = -vy_ * loss_; - if (std::fabs(vy_) < 0.1f) + if (std::fabs(vy_) < 6.0f) // Convertir 0.1f frame-based a 6.0f time-based { vy_ = 0.0f; on_floor_ = true; @@ -77,8 +85,13 @@ void Ball::update(float deltaTime) // Aplica rozamiento al rodar por el suelo if (on_floor_) { - vx_ = vx_ * 0.97f; - if (std::fabs(vx_) < 0.1f) + // Convertir rozamiento de frame-based a time-based + // 0.97f por frame equivale a pow(0.97f, 60 * deltaTime) + float friction_factor = pow(0.97f, 60.0f * deltaTime); + vx_ = vx_ * friction_factor; + + // Umbral de parada ajustado para velocidades en píxeles/segundo + if (std::fabs(vx_) < 6.0f) // ~0.1f * 60 para time-based { vx_ = 0.0f; stopped_ = true;