diff --git a/source/engine.cpp b/source/engine.cpp index 324bce5..dc7c1bb 100644 --- a/source/engine.cpp +++ b/source/engine.cpp @@ -1504,21 +1504,7 @@ void Engine::executeRandomizeOnDemoStart(bool is_lite) { } else { // DEMO COMPLETO: Randomizar TODO - // 1. Escenario (excluir índices 0, 6, 7) - int valid_scenarios[] = {1, 2, 3, 4, 5}; - int new_scenario = valid_scenarios[rand() % 5]; - scene_manager_->changeScenario(new_scenario, current_mode_); - - // 2. Tema (elegir entre TODOS los 15 temas) - int random_theme_index = rand() % 15; - theme_manager_->switchToTheme(random_theme_index); - - // 3. Sprite - if (rand() % 2 == 0) { - switchTextureInternal(false); // Suprimir notificación al activar modo DEMO - } - - // 4. Física o Figura + // 1. Física o Figura (decidir PRIMERO antes de cambiar escenario) if (rand() % 2 == 0) { // Modo física if (current_mode_ == SimulationMode::SHAPE) { @@ -1527,20 +1513,83 @@ void Engine::executeRandomizeOnDemoStart(bool is_lite) { } else { // Modo figura: elegir figura aleatoria (excluir PNG_SHAPE - es logo especial) ShapeType shapes[] = {ShapeType::SPHERE, ShapeType::LISSAJOUS, ShapeType::HELIX, ShapeType::TORUS, ShapeType::CUBE, ShapeType::CYLINDER, ShapeType::ICOSAHEDRON, ShapeType::ATOM}; - activateShapeInternal(shapes[rand() % 8]); + ShapeType selected_shape = shapes[rand() % 8]; - // 5. Profundidad (solo si estamos en figura) + // Configurar figura SIN generar puntos (changeScenario lo hará después) + last_shape_type_ = selected_shape; + current_shape_type_ = selected_shape; + current_mode_ = SimulationMode::SHAPE; + + // Crear instancia de la figura sin generar puntos todavía + switch (selected_shape) { + case ShapeType::SPHERE: + active_shape_ = std::make_unique(); + break; + case ShapeType::CUBE: + active_shape_ = std::make_unique(); + break; + case ShapeType::HELIX: + active_shape_ = std::make_unique(); + break; + case ShapeType::TORUS: + active_shape_ = std::make_unique(); + break; + case ShapeType::LISSAJOUS: + active_shape_ = std::make_unique(); + break; + case ShapeType::CYLINDER: + active_shape_ = std::make_unique(); + break; + case ShapeType::ICOSAHEDRON: + active_shape_ = std::make_unique(); + break; + case ShapeType::ATOM: + active_shape_ = std::make_unique(); + break; + default: + active_shape_ = std::make_unique(); + break; + } + + // Profundidad (solo si estamos en figura) if (rand() % 2 == 0) { depth_zoom_enabled_ = !depth_zoom_enabled_; } - // 6. Escala de figura (aleatoria entre 0.5x y 2.0x) + // Escala de figura (aleatoria entre 0.5x y 2.0x) shape_scale_factor_ = 0.5f + (rand() % 1500) / 1000.0f; clampShapeScale(); - generateShape(); + + // NOTA: NO llamar a generateShape() ni activar atracción aquí + // changeScenario() creará las pelotas y luego llamará a generateShape() } - // 7. Gravedad: dirección + ON/OFF + // 2. Escenario (excluir índices 0, 6, 7) - AHORA con current_mode_ ya establecido correctamente + int valid_scenarios[] = {1, 2, 3, 4, 5}; + int new_scenario = valid_scenarios[rand() % 5]; + scene_manager_->changeScenario(new_scenario, current_mode_); + + // Si estamos en modo SHAPE, generar la figura y activar atracción + if (current_mode_ == SimulationMode::SHAPE) { + generateShape(); + + // Activar atracción física en las bolas nuevas + auto& balls = scene_manager_->getBallsMutable(); + for (auto& ball : balls) { + ball->enableShapeAttraction(true); + } + } + + // 3. Tema (elegir entre TODOS los 15 temas) + int random_theme_index = rand() % 15; + theme_manager_->switchToTheme(random_theme_index); + + // 4. Sprite + if (rand() % 2 == 0) { + switchTextureInternal(false); // Suprimir notificación al activar modo DEMO + } + + // 5. Gravedad: dirección + ON/OFF GravityDirection new_direction = static_cast(rand() % 4); scene_manager_->changeGravityDirection(new_direction); if (rand() % 3 == 0) { // 33% probabilidad de desactivar gravedad