diff --git a/source/ball.cpp b/source/ball.cpp index 15c7884..7569fa9 100644 --- a/source/ball.cpp +++ b/source/ball.cpp @@ -22,9 +22,9 @@ float generateLateralLoss() { } // Constructor -Ball::Ball(float x, float vx, float vy, Color color, std::shared_ptr texture, int screen_width, int screen_height, int ball_size, GravityDirection gravity_dir, float mass_factor) +Ball::Ball(float x, float y, float vx, float vy, Color color, std::shared_ptr texture, int screen_width, int screen_height, int ball_size, GravityDirection gravity_dir, float mass_factor) : sprite_(std::make_unique(texture)), - pos_({x, 0.0f, static_cast(ball_size), static_cast(ball_size)}) { + pos_({x, y, static_cast(ball_size), static_cast(ball_size)}) { // Convertir velocidades de píxeles/frame a píxeles/segundo (multiplicar por 60) vx_ = vx * 60.0f; vy_ = vy * 60.0f; diff --git a/source/ball.h b/source/ball.h index a0545d2..432e3ac 100644 --- a/source/ball.h +++ b/source/ball.h @@ -31,7 +31,7 @@ class Ball { public: // Constructor - Ball(float x, float vx, float vy, Color color, std::shared_ptr texture, int screen_width, int screen_height, int ball_size, GravityDirection gravity_dir = GravityDirection::DOWN, float mass_factor = 1.0f); + Ball(float x, float y, float vx, float vy, Color color, std::shared_ptr texture, int screen_width, int screen_height, int ball_size, GravityDirection gravity_dir = GravityDirection::DOWN, float mass_factor = 1.0f); // Destructor ~Ball() = default; diff --git a/source/engine.cpp b/source/engine.cpp index de871e6..c356c2d 100644 --- a/source/engine.cpp +++ b/source/engine.cpp @@ -514,6 +514,12 @@ void Engine::changeScenario(int scenario_id, const char* notification_text) { // Si estamos en modo SHAPE, regenerar la figura con nuevo número de pelotas if (current_mode_ == SimulationMode::SHAPE) { generateShape(); + + // Activar atracción física en las bolas nuevas (crítico tras changeScenario) + auto& balls = scene_manager_->getBallsMutable(); + for (auto& ball : balls) { + ball->enableShapeAttraction(true); + } } showNotificationForAction(notification_text); diff --git a/source/scene/scene_manager.cpp b/source/scene/scene_manager.cpp index b1674c0..e731fa3 100644 --- a/source/scene/scene_manager.cpp +++ b/source/scene/scene_manager.cpp @@ -45,7 +45,7 @@ void SceneManager::changeScenario(int scenario_id, SimulationMode mode) { // Crear las bolas según el escenario for (int i = 0; i < BALL_COUNT_SCENARIOS[scenario_id]; ++i) { - float X, VX, VY; + float X, Y, VX, VY; // Inicialización según SimulationMode (RULES.md líneas 23-26) switch (mode) { @@ -55,6 +55,7 @@ void SceneManager::changeScenario(int scenario_id, SimulationMode mode) { const int margin = static_cast(screen_width_ * BALL_SPAWN_MARGIN); const int spawn_zone_width = screen_width_ - (2 * margin); X = (rand() % spawn_zone_width) + margin; + Y = 0.0f; // Parte superior VX = (((rand() % 20) + 10) * 0.1f) * SIGN; VY = ((rand() % 60) - 30) * 0.1f; break; @@ -63,6 +64,7 @@ void SceneManager::changeScenario(int scenario_id, SimulationMode mode) { case SimulationMode::SHAPE: { // SHAPE: Centro de pantalla, sin velocidad inicial X = screen_width_ / 2.0f; + Y = screen_height_ / 2.0f; // Centro vertical VX = 0.0f; VY = 0.0f; break; @@ -73,6 +75,7 @@ void SceneManager::changeScenario(int scenario_id, SimulationMode mode) { const int SIGN_X = ((rand() % 2) * 2) - 1; const int SIGN_Y = ((rand() % 2) * 2) - 1; X = static_cast(rand() % screen_width_); + Y = static_cast(rand() % screen_height_); // Posición Y aleatoria VX = (((rand() % 40) + 10) * 0.1f) * SIGN_X; // 1.0 - 5.0 px/frame VY = (((rand() % 40) + 10) * 0.1f) * SIGN_Y; break; @@ -84,6 +87,7 @@ void SceneManager::changeScenario(int scenario_id, SimulationMode mode) { const int margin = static_cast(screen_width_ * BALL_SPAWN_MARGIN); const int spawn_zone_width = screen_width_ - (2 * margin); X = (rand() % spawn_zone_width) + margin; + Y = 0.0f; // Parte superior VX = (((rand() % 20) + 10) * 0.1f) * SIGN; VY = ((rand() % 60) - 30) * 0.1f; break; @@ -97,7 +101,7 @@ void SceneManager::changeScenario(int scenario_id, SimulationMode mode) { float mass_factor = GRAVITY_MASS_MIN + (rand() % 1000) / 1000.0f * (GRAVITY_MASS_MAX - GRAVITY_MASS_MIN); balls_.emplace_back(std::make_unique( - X, VX, VY, COLOR, texture_, + X, Y, VX, VY, COLOR, texture_, screen_width_, screen_height_, current_ball_size_, current_gravity_, mass_factor ));