diff --git a/source/balloon_formations.cpp b/source/balloon_formations.cpp index 643ae33..4ab2b4c 100644 --- a/source/balloon_formations.cpp +++ b/source/balloon_formations.cpp @@ -1,10 +1,9 @@ #include "balloon_formations.h" -#include // Para size_t - #include // Para max #include // Para array #include // Para isdigit +#include // Para size_t #include // Para exception #include // Para basic_istream, basic_ifstream, ifstream, istringstream #include // Para map, operator== diff --git a/source/sections/intro.cpp b/source/sections/intro.cpp index 785240b..f8bdde2 100644 --- a/source/sections/intro.cpp +++ b/source/sections/intro.cpp @@ -54,76 +54,9 @@ void Intro::checkEvents() { #ifdef DEBUG if (event.type == SDL_EVENT_KEY_DOWN && static_cast(event.key.repeat) == 1) { static Color color_ = param.intro.bg_color; - switch (event.key.key) { - case SDLK_A: - if (color_.r < 255) { - ++color_.r; - } - break; - - case SDLK_Z: - if (color_.r > 0) { - --color_.r; - } - break; - - case SDLK_S: - if (color_.g < 255) { - ++color_.g; - } - break; - - case SDLK_X: - if (color_.g > 0) { - --color_.g; - } - break; - - case SDLK_D: - if (color_.b < 255) { - ++color_.b; - } - break; - - case SDLK_C: - if (color_.b > 0) { - --color_.b; - } - break; - - case SDLK_F: - if (color_.r < 255) { - ++color_.r; - } - if (color_.g < 255) { - ++color_.g; - } - if (color_.b < 255) { - ++color_.b; - } - break; - - case SDLK_V: - if (color_.r > 0) { - --color_.r; - } - if (color_.g > 0) { - --color_.g; - } - if (color_.b > 0) { - --color_.b; - } - break; - - default: - break; - } + handleDebugColorKeys(event.key.key, color_); tiled_bg_->setColor(color_); - std::cout << "#" - << std::hex << std::setw(2) << std::setfill('0') << (int)color_.r - << std::setw(2) << std::setfill('0') << (int)color_.g - << std::setw(2) << std::setfill('0') << (int)color_.b - << std::endl; + printColorDebugInfo(color_); } #endif GlobalEvents::check(event); @@ -139,139 +72,152 @@ void Intro::checkInput() { // Actualiza las escenas de la intro void Intro::updateScenes() { switch (scene_) { - case 0: { - // Primera imagen - UPV - card_sprites_.at(0)->enable(); - shadow_sprites_.at(0)->enable(); - - // Primer texto de la primera imagen - if (card_sprites_.at(0)->hasFinished() && !texts_.at(0)->hasFinished()) { - texts_.at(0)->setEnabled(true); - } - - // Segundo texto de la primera imagen - if (texts_.at(0)->hasFinished() && !texts_.at(1)->hasFinished()) { - texts_.at(0)->setEnabled(false); - texts_.at(1)->setEnabled(true); - } - - // Tercer texto de la primera imagen - if (texts_.at(1)->hasFinished() && !texts_.at(2)->hasFinished()) { - texts_.at(1)->setEnabled(false); - texts_.at(2)->setEnabled(true); - } - - // Fin de la primera escena - if (texts_.at(2)->hasFinished()) { - texts_.at(2)->setEnabled(false); - scene_++; - } + case 0: + updateScene0(); break; - } - - case 1: { - // Segunda imagen - Máquina - card_sprites_.at(1)->enable(); - shadow_sprites_.at(1)->enable(); - - // Primer texto de la segunda imagen - if (card_sprites_.at(1)->hasFinished() && !texts_.at(3)->hasFinished()) { - texts_.at(3)->setEnabled(true); - } - - // Fin de la segunda escena - if (texts_.at(3)->hasFinished()) { - texts_.at(3)->setEnabled(false); - scene_++; - } + case 1: + updateScene1(); break; - } - - case 2: { - // Tercera imagen junto con primer texto - GRITO - if (!texts_.at(4)->hasFinished()) { - card_sprites_.at(2)->enable(); - shadow_sprites_.at(2)->enable(); - - texts_.at(4)->setEnabled(true); - } - - // Fin de la tercera escena - if (card_sprites_.at(2)->hasFinished() && texts_.at(4)->hasFinished()) { - texts_.at(4)->setEnabled(false); - scene_++; - } + case 2: + updateScene2(); break; - } - - case 3: { - // Cuarta imagen junto con primer texto - Reflexión - card_sprites_.at(3)->enable(); - shadow_sprites_.at(3)->enable(); - - if (!texts_.at(5)->hasFinished()) { - texts_.at(5)->setEnabled(true); - } - - // Segundo texto de la cuarta imagen - if (texts_.at(5)->hasFinished() && !texts_.at(6)->hasFinished()) { - texts_.at(5)->setEnabled(false); - texts_.at(6)->setEnabled(true); - } - - // Fin de la cuarta escena - if (card_sprites_.at(3)->hasFinished() && texts_.at(6)->hasFinished()) { - texts_.at(6)->setEnabled(false); - scene_++; - } + case 3: + updateScene3(); break; - } - - case 4: { - // Quinta imagen - Patada - card_sprites_.at(4)->enable(); - shadow_sprites_.at(4)->enable(); - - // Primer texto de la quinta imagen - if (!texts_.at(7)->hasFinished()) { - texts_.at(7)->setEnabled(true); - } - - // Fin de la quinta escena - if (card_sprites_.at(4)->hasFinished() && texts_.at(7)->hasFinished()) { - texts_.at(7)->setEnabled(false); - scene_++; - } + case 4: + updateScene4(); break; - } - - case 5: { - // Sexta imagen junto con texto - Globos de café - card_sprites_.at(5)->enable(); - shadow_sprites_.at(5)->enable(); - - if (!texts_.at(8)->hasFinished()) { - texts_.at(8)->setEnabled(true); - } - - // Acaba el último texto - if (texts_.at(8)->hasFinished()) { - texts_.at(8)->setEnabled(false); - } - - // Acaba la ultima imagen - if (card_sprites_.at(5)->hasFinished() && texts_.at(8)->hasFinished()) { - state_ = IntroState::POST; - state_start_time_ = SDL_GetTicks(); - } + case 5: + updateScene5(); break; - } - default: break; } } +void Intro::updateScene0() { + // Primera imagen - UPV + enableCardAndShadow(0); + + // Primer texto de la primera imagen + if (card_sprites_.at(0)->hasFinished() && !texts_.at(0)->hasFinished()) { + texts_.at(0)->setEnabled(true); + } + + // Segundo texto de la primera imagen + if (texts_.at(0)->hasFinished() && !texts_.at(1)->hasFinished()) { + switchText(0, 1); + } + + // Tercer texto de la primera imagen + if (texts_.at(1)->hasFinished() && !texts_.at(2)->hasFinished()) { + switchText(1, 2); + } + + // Fin de la primera escena + if (texts_.at(2)->hasFinished()) { + texts_.at(2)->setEnabled(false); + scene_++; + } +} + +void Intro::updateScene1() { + // Segunda imagen - Máquina + enableCardAndShadow(1); + + // Primer texto de la segunda imagen + if (card_sprites_.at(1)->hasFinished() && !texts_.at(3)->hasFinished()) { + texts_.at(3)->setEnabled(true); + } + + // Fin de la segunda escena + if (texts_.at(3)->hasFinished()) { + texts_.at(3)->setEnabled(false); + scene_++; + } +} + +void Intro::updateScene2() { + // Tercera imagen junto con primer texto - GRITO + if (!texts_.at(4)->hasFinished()) { + enableCardAndShadow(2); + texts_.at(4)->setEnabled(true); + } + + // Fin de la tercera escena + if (card_sprites_.at(2)->hasFinished() && texts_.at(4)->hasFinished()) { + texts_.at(4)->setEnabled(false); + scene_++; + } +} + +void Intro::updateScene3() { + // Cuarta imagen junto con primer texto - Reflexión + enableCardAndShadow(3); + + if (!texts_.at(5)->hasFinished()) { + texts_.at(5)->setEnabled(true); + } + + // Segundo texto de la cuarta imagen + if (texts_.at(5)->hasFinished() && !texts_.at(6)->hasFinished()) { + switchText(5, 6); + } + + // Fin de la cuarta escena + if (card_sprites_.at(3)->hasFinished() && texts_.at(6)->hasFinished()) { + texts_.at(6)->setEnabled(false); + scene_++; + } +} + +void Intro::updateScene4() { + // Quinta imagen - Patada + enableCardAndShadow(4); + + // Primer texto de la quinta imagen + if (!texts_.at(7)->hasFinished()) { + texts_.at(7)->setEnabled(true); + } + + // Fin de la quinta escena + if (card_sprites_.at(4)->hasFinished() && texts_.at(7)->hasFinished()) { + texts_.at(7)->setEnabled(false); + scene_++; + } +} + +void Intro::updateScene5() { + // Sexta imagen junto con texto - Globos de café + enableCardAndShadow(5); + + if (!texts_.at(8)->hasFinished()) { + texts_.at(8)->setEnabled(true); + } + + // Acaba el último texto + if (texts_.at(8)->hasFinished()) { + texts_.at(8)->setEnabled(false); + } + + // Acaba la ultima imagen + if (card_sprites_.at(5)->hasFinished() && texts_.at(8)->hasFinished()) { + state_ = IntroState::POST; + state_start_time_ = SDL_GetTicks(); + } +} + +// Helper methods to reduce code duplication +void Intro::enableCardAndShadow(int index) { + card_sprites_.at(index)->enable(); + shadow_sprites_.at(index)->enable(); +} + +void Intro::switchText(int fromIndex, int toIndex) { + texts_.at(fromIndex)->setEnabled(false); + texts_.at(toIndex)->setEnabled(true); +} + // Actualiza las variables del objeto void Intro::update() { if (SDL_GetTicks() - ticks_ > param.game.speed) { @@ -588,4 +534,60 @@ void Intro::renderTextRect() { static SDL_FRect rect_ = {0.0F, param.game.height - param.intro.text_distance_from_bottom - HEIGHT, param.game.width, HEIGHT * 3}; SDL_SetRenderDrawColor(Screen::get()->getRenderer(), param.intro.shadow_color.r, param.intro.shadow_color.g, param.intro.shadow_color.b, param.intro.shadow_color.a); SDL_RenderFillRect(Screen::get()->getRenderer(), &rect_); -} \ No newline at end of file +} + +#ifdef DEBUG +// Helper functions for color adjustment +void Intro::adjustColorComponent(uint8_t &component, bool increase) { + if (increase && component < 255) { + ++component; + } else if (!increase && component > 0) { + --component; + } +} + +void Intro::adjustAllColorComponents(Color &color, bool increase) { + adjustColorComponent(color.r, increase); + adjustColorComponent(color.g, increase); + adjustColorComponent(color.b, increase); +} + +void Intro::handleDebugColorKeys(SDL_Keycode key, Color &color) { + switch (key) { + case SDLK_A: + adjustColorComponent(color.r, true); + break; + case SDLK_Z: + adjustColorComponent(color.r, false); + break; + case SDLK_S: + adjustColorComponent(color.g, true); + break; + case SDLK_X: + adjustColorComponent(color.g, false); + break; + case SDLK_D: + adjustColorComponent(color.b, true); + break; + case SDLK_C: + adjustColorComponent(color.b, false); + break; + case SDLK_F: + adjustAllColorComponents(color, true); + break; + case SDLK_V: + adjustAllColorComponents(color, false); + break; + default: + break; + } +} + +void Intro::printColorDebugInfo(const Color &color) { + std::cout << "#" + << std::hex << std::setw(2) << std::setfill('0') << (int)color.r + << std::setw(2) << std::setfill('0') << (int)color.g + << std::setw(2) << std::setfill('0') << (int)color.b + << std::endl; +} +#endif \ No newline at end of file diff --git a/source/sections/intro.h b/source/sections/intro.h index 85c33db..a15c465 100644 --- a/source/sections/intro.h +++ b/source/sections/intro.h @@ -69,4 +69,22 @@ class Intro { void renderTexts(); // Dibuja los textos static void renderTextRect(); // Dibuja el rectangulo de fondo del texto; void updatePostState(); // Actualiza el estado POST +#ifdef DEBUG + void adjustColorComponent(uint8_t& component, bool increase); + void adjustAllColorComponents(Color& color, bool increase); + void handleDebugColorKeys(SDL_Keycode key, Color& color); + void printColorDebugInfo(const Color& color); +#endif + + // --- Métodos para manejar cada escena individualmente --- + void updateScene0(); + void updateScene1(); + void updateScene2(); + void updateScene3(); + void updateScene4(); + void updateScene5(); + + // --- Métodos auxiliares para reducir duplicación de código --- + void enableCardAndShadow(int index); + void switchText(int fromIndex, int toIndex); };