diff --git a/source/engine.cpp b/source/engine.cpp index 1eb4ea0..7e3d87a 100644 --- a/source/engine.cpp +++ b/source/engine.cpp @@ -733,22 +733,38 @@ void Engine::render() { } if (show_text_) { - // Obtener tema actual - int theme_idx = static_cast(current_theme_); - const ThemeColors& current = themes_[theme_idx]; + // Obtener datos del tema actual (estático o dinámico) + int text_color_r, text_color_g, text_color_b; + const char* theme_name_es = nullptr; + + if (dynamic_theme_active_ && current_dynamic_theme_index_ >= 0) { + // Tema dinámico activo + const DynamicTheme& dyn_theme = dynamic_themes_[current_dynamic_theme_index_]; + text_color_r = dyn_theme.text_color_r; + text_color_g = dyn_theme.text_color_g; + text_color_b = dyn_theme.text_color_b; + theme_name_es = dyn_theme.name_es; + } else { + // Tema estático + int theme_idx = static_cast(current_theme_); + const ThemeColors& current = themes_[theme_idx]; + text_color_r = current.text_color_r; + text_color_g = current.text_color_g; + text_color_b = current.text_color_b; + theme_name_es = current.name_es; + } // Texto del número de pelotas con color del tema - dbg_print(text_pos_, 8, text_.c_str(), current.text_color_r, current.text_color_g, current.text_color_b); + dbg_print(text_pos_, 8, text_.c_str(), text_color_r, text_color_g, text_color_b); // Mostrar nombre del tema en castellano debajo del número de pelotas - // (solo si text_ NO es ya el nombre del tema actual o destino, para evitar duplicación durante LERP) - const ThemeColors& target = themes_[static_cast(target_theme_)]; - if (text_ != current.name_es && text_ != target.name_es) { - int theme_text_width = static_cast(strlen(current.name_es) * 8); // 8 píxeles por carácter - int theme_x = (current_screen_width_ - theme_text_width) / 2; // Centrar horizontalmente + // (solo si text_ NO es ya el nombre del tema, para evitar duplicación) + if (theme_name_es != nullptr && text_ != theme_name_es) { + int theme_text_width = static_cast(strlen(theme_name_es) * 8); // 8 píxeles por carácter + int theme_x = (current_screen_width_ - theme_text_width) / 2; // Centrar horizontalmente // Texto del nombre del tema con el mismo color - dbg_print(theme_x, 24, current.name_es, current.text_color_r, current.text_color_g, current.text_color_b); + dbg_print(theme_x, 24, theme_name_es, text_color_r, text_color_g, text_color_b); } } @@ -789,7 +805,12 @@ void Engine::render() { } // Debug: Mostrar tema actual - std::string theme_text = std::string("THEME ") + themes_[static_cast(current_theme_)].name_en; + std::string theme_text; + if (dynamic_theme_active_ && current_dynamic_theme_index_ >= 0) { + theme_text = std::string("THEME ") + dynamic_themes_[current_dynamic_theme_index_].name_en; + } else { + theme_text = std::string("THEME ") + themes_[static_cast(current_theme_)].name_en; + } dbg_print(8, 64, theme_text.c_str(), 255, 255, 128); // Amarillo claro para tema // Debug: Mostrar modo de simulación actual @@ -844,10 +865,21 @@ void Engine::initBalls(int value) { const float X = (rand() % spawn_zone_width) + margin; // Posición inicial en X const float VX = (((rand() % 20) + 10) * 0.1f) * SIGN; // Velocidad en X const float VY = ((rand() % 60) - 30) * 0.1f; // Velocidad en Y - // Seleccionar color de la paleta del tema actual - ThemeColors& theme = themes_[static_cast(current_theme_)]; - int color_index = rand() % theme.ball_colors.size(); // Cantidad variable de colores por tema - const Color COLOR = theme.ball_colors[color_index]; + + // Seleccionar color de la paleta del tema actual (estático o dinámico) + Color COLOR; + if (dynamic_theme_active_ && current_dynamic_theme_index_ >= 0) { + // Tema dinámico: usar colores del keyframe actual + const DynamicTheme& dyn_theme = dynamic_themes_[current_dynamic_theme_index_]; + const DynamicThemeKeyframe& current_kf = dyn_theme.keyframes[current_keyframe_index_]; + int color_index = rand() % current_kf.ball_colors.size(); + COLOR = current_kf.ball_colors[color_index]; + } else { + // Tema estático + ThemeColors& theme = themes_[static_cast(current_theme_)]; + int color_index = rand() % theme.ball_colors.size(); + COLOR = theme.ball_colors[color_index]; + } // Generar factor de masa aleatorio (0.7 = ligera, 1.3 = pesada) 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_, current_screen_width_, current_screen_height_, current_ball_size_, current_gravity_, mass_factor));