diff --git a/data/font/04b_25.png b/data/font/04b_25.png index dfc7409..a87d2a9 100644 Binary files a/data/font/04b_25.png and b/data/font/04b_25.png differ diff --git a/data/lang/ba_BA.txt b/data/lang/ba_BA.txt index 3fe701a..07911aa 100644 --- a/data/lang/ba_BA.txt +++ b/data/lang/ba_BA.txt @@ -32,7 +32,7 @@ IDIOMA [ CANCELAR ] ## 11 - INSTRUCCIONES -OBJECTIU +Objectiu ## 12 - INSTRUCCIONES HAS D'EXPLOTAR @@ -47,7 +47,7 @@ LA DIFICULTAT AUGMENTA A MESURA QUE VAS PUNTUANT ## 16 - INSTRUCCIONES -OBJECTES +Objectes ## 17 - INSTRUCCIONES 1.000 PUNTS diff --git a/source/game.cpp b/source/game.cpp index ba0669b..3b4fe85 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -283,6 +283,13 @@ void Game::updateStage() createMessage(paths, text->writeToTexture(caption, 1, -4)); } } + + // Modifica el color de fondo al llegar a la Fase 10 + if (Stage::number == 9) + { + background_->setColor(Color(0xdd, 0x19, 0x1d).darken()); + background_->setAlpha(96); + } } } @@ -365,6 +372,7 @@ void Game::updateGameStateCompleted() balloon_manager_->destroyAllBalloons(); // Destruye a todos los globos destroyAllItems(); // Destruye todos los items Stage::power = 0; // Vuelve a dejar el poder a cero, por lo que hubiera podido subir al destruir todos los globos + background_->setAlpha(0); // Elimina el tono rojo de las últimas pantallas } // Comienza las celebraciones @@ -1261,7 +1269,8 @@ void Game::checkEvents() { auto_pop_balloons_ = !auto_pop_balloons_; Notifier::get()->showText({"auto advance: " + boolToString(auto_pop_balloons_)}); - balloon_manager_->destroyAllBalloons(); + if (auto_pop_balloons_) + balloon_manager_->destroyAllBalloons(); balloon_manager_->setDeployBalloons(!auto_pop_balloons_); break; } diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index b697ef1..3bf6b11 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -4,23 +4,28 @@ #include // Para SDL_PIXELFORMAT_RGBA8888 #include // Para SDL_GetTicks #include // Para SDL_WINDOWEVENT_SIZE_CHANGED +#include // Para rand #include // Para max +#include // Para function #include // Para vector #include "background.h" // Para Background #include "fade.h" // Para Fade, FadeMode, FadeType -#include "global_inputs.h" // Para check +#include "global_inputs.h" // Para check, update #include "input.h" // Para Input #include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state #include "lang.h" // Para getText #include "manage_hiscore_table.h" // Para HiScoreEntry +#include "mouse.h" // Para handleEvent #include "options.h" // Para Options, OptionsGame, options #include "param.h" // Para Param, param, ParamGame, ParamFade +#include "path_sprite.h" // Para PathSprite, Path, PathType #include "resource.h" // Para Resource #include "screen.h" // Para Screen -#include "section.h" // Para Name, name, Options, options -#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW -#include "utils.h" // Para Color, Zone, fade_color, orange_color -#include "mouse.h" +#include "section.h" // Para Name, name, Options, options, Attr... +#include "sprite.h" // Para Sprite +#include "text.h" // Para Text, TEXT_COLOR, TEXT_SHADOW +#include "texture.h" // Para Texture +#include "utils.h" // Para Color, easeOutQuint, fade_color // Constructor HiScoreTable::HiScoreTable() @@ -28,30 +33,17 @@ HiScoreTable::HiScoreTable() backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)), fade_(std::make_unique()), background_(std::make_unique()), - text_(Resource::get()->getText("smb2")), counter_(0), ticks_(0), view_area_({0, 0, param.game.width, param.game.height}), - fade_mode_(FadeMode::IN) + fade_mode_(FadeMode::IN), + background_fade_color_(Color(0, 0, 0)) { - // Inicializa el resto de variables + // Inicializa el resto section::name = section::Name::HI_SCORE_TABLE; - - // Inicializa objetos SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND); - background_->setPos(param.game.game_area.rect); - background_->setCloudsSpeed(-0.1f); - background_->setGradientNumber(1); - background_->setTransition(0.8f); - background_->setSunProgression(1.0f); - background_->setMoonProgression(0.6f); - fade_->setColor(fade_color.r, fade_color.g, fade_color.b); - fade_->setType(FadeType::RANDOM_SQUARE); - fade_->setPostDuration(param.fade.post_duration); - fade_->setMode(fade_mode_); - fade_->activate(); - - // Crea los sprites con los textos + initFade(); + initBackground(); createSprites(); } @@ -97,7 +89,7 @@ void HiScoreTable::update() if (counter_ == 150) { - background_->setColor(Color(0, 0, 0)); + background_->setColor(background_fade_color_.darken()); background_->setAlpha(96); } @@ -161,8 +153,6 @@ void HiScoreTable::render() // Recarga todas las texturas void HiScoreTable::reloadTextures() { - text_->reLoadTexture(); - fillTexture(); } // Comprueba los eventos @@ -268,6 +258,9 @@ std::string HiScoreTable::format(int number) // Crea los sprites con los textos void HiScoreTable::createSprites() { + auto header_text = Resource::get()->getText("04b_25"); + auto entry_text = Resource::get()->getText("smb2"); + // Obtiene el tamaño de la textura int backbuffer_width; int backbuffer_height; @@ -276,32 +269,34 @@ void HiScoreTable::createSprites() // Hay 27 letras - 7 de puntos quedan 20 caracteres 20 - name_lenght 0 num_dots constexpr int max_names = 10; constexpr int space_between_header = 32; - const int space_between_lines = text_->getCharacterSize() * 2; - const int size = space_between_header + space_between_lines * (max_names - 1) + text_->getCharacterSize(); + const int space_between_lines = entry_text->getCharacterSize() * 2; + const int size = space_between_header + space_between_lines * (max_names - 1) + entry_text->getCharacterSize(); const int first_line = (param.game.height - size) / 2; // Crea el sprite para el texto de cabecera - header_ = std::make_unique(text_->writeDXToTexture(TEXT_COLOR | TEXT_SHADOW, lang::getText(42), 1, orange_color, 1, shdw_txt_color)); + header_ = std::make_unique(header_text->writeDXToTexture(TEXT_COLOR, lang::getText(42), -2, background_fade_color_.getInverse().lighten(25))); header_->setPosition(param.game.game_area.center_x - (header_->getWidth() / 2), first_line); // Crea los sprites para las entradas en la tabla de puntuaciones + const int animation = rand() % 4; for (int i = 0; i < max_names; ++i) { - const auto name_lenght = options.game.hi_score_table.at(i).name.length(); + const auto table_position = (i + 1 >= 10) ? format(i + 1) + ". " : " " + format(i + 1) + ". "; const auto score = format(options.game.hi_score_table.at(i).score); - const auto score_lenght = score.size(); - const auto num_dots = 25 - name_lenght - score_lenght; + const auto num_dots = 25 - table_position.size() - options.game.hi_score_table.at(i).name.size() - score.size(); std::string dots; for (int j = 0; j < (int)num_dots; ++j) { dots = dots + "."; } - const auto line = options.game.hi_score_table.at(i).name + dots + score; + const auto line = table_position + options.game.hi_score_table.at(i).name + dots + score; - entry_names_.emplace_back(std::make_shared(text_->writeDXToTexture(TEXT_SHADOW, line, 1, orange_color, 1, shdw_txt_color))); - if (false) + entry_names_.emplace_back(std::make_shared(entry_text->writeDXToTexture(TEXT_SHADOW, line, 1, orange_color, 1, shdw_txt_color))); + switch (animation) { - if (i % 1 == 0) + case 0: // Ambos lados alternativamente + { + if (i % 2 == 0) { entry_names_.back()->addPath( -entry_names_.back()->getWidth(), @@ -325,9 +320,38 @@ void HiScoreTable::createSprites() 0); entry_names_.back()->setPosition(backbuffer_width, 0); } + break; } - if (true) + case 1: // Entran por la izquierda + { + entry_names_.back()->addPath( + -entry_names_.back()->getWidth(), + (backbuffer_width - entry_names_.back()->getWidth()) / 2, + PathType::HORIZONTAL, + (i * space_between_lines) + first_line + space_between_header, + 80, + easeOutQuint, + 0); + entry_names_.back()->setPosition(-entry_names_.back()->getWidth(), 0); + break; + } + + case 2: // Entran por la derecha + { + entry_names_.back()->addPath( + backbuffer_width, + (backbuffer_width - entry_names_.back()->getWidth()) / 2, + PathType::HORIZONTAL, + (i * space_between_lines) + first_line + space_between_header, + 80, + easeOutQuint, + 0); + entry_names_.back()->setPosition(backbuffer_width, 0); + break; + } + + case 3: // Entran desde la parte inferior { entry_names_.back()->addPath( backbuffer_height, @@ -339,14 +363,18 @@ void HiScoreTable::createSprites() 0); entry_names_.back()->setPosition(0, backbuffer_height); } + + default: + break; + } } } // Actualiza las posiciones de los sprites de texto void HiScoreTable::updateSprites() { - constexpr int init_counter = 220; - const int counter_between_entries = text_->getCharacterSize() * 2; + constexpr int init_counter = 190; + const int counter_between_entries = 16; if (counter_ >= init_counter) { const int counter2 = counter_ - init_counter; @@ -363,4 +391,59 @@ void HiScoreTable::updateSprites() { entry->update(); } +} + +// Inicializa el fade +void HiScoreTable::initFade() +{ + fade_->setColor(fade_color.r, fade_color.g, fade_color.b); + fade_->setType(FadeType::RANDOM_SQUARE); + fade_->setPostDuration(param.fade.post_duration); + fade_->setMode(fade_mode_); + fade_->activate(); +} + +// Inicializa el fondo +void HiScoreTable::initBackground() +{ + background_->setPos(param.game.game_area.rect); + background_->setCloudsSpeed(-0.1f); + + const int lucky = rand() % 3; + //const int lucky = 2; + switch (lucky) + { + case 0: // Fondo verde + { + background_->setGradientNumber(2); + background_->setTransition(0.0f); + background_->setSunProgression(1.0f); + background_->setMoonProgression(0.4f); + background_fade_color_ = Color(0x00, 0x79, 0x6b); + break; + } + + case 1: // Fondo naranja + { + background_->setGradientNumber(1); + background_->setTransition(0.0f); + background_->setSunProgression(0.65f); + background_->setMoonProgression(0.0f); + background_fade_color_ = Color(0xff, 0x6b, 0x97); + break; + } + + case 2: // Fondo azul + { + background_->setGradientNumber(0); + background_->setTransition(0.0f); + background_->setSunProgression(0.0f); + background_->setMoonProgression(0.0f); + background_fade_color_ = Color(0x02, 0x88, 0xd1); + break; + } + + default: + break; + } } \ No newline at end of file diff --git a/source/hiscore_table.h b/source/hiscore_table.h index 024ac4a..cd8828e 100644 --- a/source/hiscore_table.h +++ b/source/hiscore_table.h @@ -1,16 +1,18 @@ #pragma once -#include // para SDL_Rect -#include // para SDL_Renderer, SDL_Texture -#include // para Uint16, Uint32, Uint8 -#include // para unique_ptr -#include // para string -#include "sprite.h" -#include "path_sprite.h" -class Background; // lines 8-8 -class Fade; // lines 9-9 -class Text; // lines 10-10 -enum class FadeMode : Uint8; // lines 11-11 +#include // Para SDL_Rect +#include // Para SDL_Renderer, SDL_Texture +#include // Para Uint16, Uint32, Uint8 +#include // Para unique_ptr, shared_ptr +#include // Para string +#include // Para vector +#include "utils.h" +class Background; // lines 10-10 +class Fade; // lines 11-11 +class PathSprite; +class Sprite; +enum class FadeMode : Uint8; // lines 13-13 +struct Path; /* Esta clase gestiona un estado del programa. Se encarga de mostrar la tabla con las puntuaciones @@ -35,16 +37,16 @@ private: std::unique_ptr fade_; // Objeto para renderizar fades std::unique_ptr background_; // Objeto para dibujar el fondo del juego - std::shared_ptr text_; // Objeto para escribir texto std::unique_ptr header_; // Sprite con la cabecera del texto std::vector> entry_names_; // Lista con los spritres de cada uno de los nombres de la tabla de records std::vector paths_; // Vector con los recorridos precalculados // Variables - Uint16 counter_; // Contador - Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa - SDL_Rect view_area_; // Parte de la textura que se muestra en pantalla - FadeMode fade_mode_; // Modo de fade a utilizar + Uint16 counter_ = 0; // Contador + Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa + SDL_Rect view_area_; // Parte de la textura que se muestra en pantalla + FadeMode fade_mode_; // Modo de fade a utilizar + Color background_fade_color_; // Color de atenuación del fondo // Actualiza las variables void update(); @@ -76,6 +78,12 @@ private: // Actualiza las posiciones de los sprites de texto void updateSprites(); + // Inicializa el fade + void initFade(); + + // Inicializa el fondo + void initBackground(); + public: // Constructor HiScoreTable(); diff --git a/source/instructions.cpp b/source/instructions.cpp index 886420d..3c9bd51 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -159,7 +159,6 @@ void Instructions::fillTexture() text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor2, lang::getText(16), 1, orange_color, 1, shdw_txt_color); const int anchor3 = anchor2 + space_post_header; - // const int anchor4 = anchor3 + ((param.game.item_size + text->getCharacterSize()) / 2); text_->writeShadowed(anchor_item + desp_x, anchor3 + space_between_item_lines * 0, lang::getText(17), shdw_txt_color); text_->writeShadowed(anchor_item + desp_x, anchor3 + space_between_item_lines * 1, lang::getText(18), shdw_txt_color); text_->writeShadowed(anchor_item + desp_x, anchor3 + space_between_item_lines * 2, lang::getText(19), shdw_txt_color); diff --git a/source/tabe.cpp b/source/tabe.cpp index efb26ac..149d302 100644 --- a/source/tabe.cpp +++ b/source/tabe.cpp @@ -2,6 +2,7 @@ #include "tabe.h" #include // Para SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE #include // Para rand, abs +#include // Para max #include "jail_audio.h" // Para JA_PlaySound #include "param.h" // Para Param, ParamGame, param #include "resource.h" // Para Resource diff --git a/source/tabe.h b/source/tabe.h index 6a93bb1..a8ed9cc 100644 --- a/source/tabe.h +++ b/source/tabe.h @@ -1,7 +1,8 @@ #pragma once -#include "animated_sprite.h" -#include +#include // Para SDL_Rect +#include // Para unique_ptr +#include "animated_sprite.h" // Para AnimatedSprite enum class TabeDirection : int { diff --git a/source/text.cpp b/source/text.cpp index 3bf499d..1a7888a 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -178,7 +178,7 @@ std::shared_ptr Text::writeDXToTexture(Uint8 flags, const std::string & { auto renderer = Screen::get()->getRenderer(); auto texture = std::make_shared(renderer); - auto width = Text::lenght(text, kerning); + auto width = Text::lenght(text, kerning) + shadow_distance; auto height = box_height_ + shadow_distance; auto temp = SDL_GetRenderTarget(renderer); texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET); diff --git a/source/texture.cpp b/source/texture.cpp index c906622..20f7dd5 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -164,6 +164,10 @@ void Texture::setColor(Uint8 red, Uint8 green, Uint8 blue) { SDL_SetTextureColorMod(texture_, red, green, blue); } +void Texture::setColor(Color color) +{ + SDL_SetTextureColorMod(texture_, color.r, color.g, color.b); +} // Establece el blending void Texture::setBlendMode(SDL_BlendMode blending) diff --git a/source/texture.h b/source/texture.h index 37bfd73..16cc4e6 100644 --- a/source/texture.h +++ b/source/texture.h @@ -1,13 +1,14 @@ #pragma once -#include // para SDL_BlendMode -#include // para SDL_PIXELFORMAT_RGBA8888, SDL_PixelF... -#include // para SDL_Point, SDL_Rect -#include // para SDL_Renderer, SDL_FLIP_NONE, SDL_TEX... -#include // para Uint8, Uint32, Uint16 -#include // para string, basic_string -#include // para vector -#include +#include // Para SDL_BlendMode +#include // Para SDL_PIXELFORMAT_RGBA8888, SDL_PixelF... +#include // Para SDL_Point, SDL_Rect +#include // Para SDL_Renderer, SDL_FLIP_NONE, SDL_TEX... +#include // Para Uint8, Uint16, Uint32 +#include // Para shared_ptr +#include // Para string +#include // Para vector +struct Color; // Definiciones de tipos struct Surface @@ -65,6 +66,7 @@ public: // Establece el color para la modulacion void setColor(Uint8 red, Uint8 green, Uint8 blue); + void setColor(Color color); // Establece el blending void setBlendMode(SDL_BlendMode blending); diff --git a/source/utils.cpp b/source/utils.cpp index 23d750f..a1dbfde 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -23,6 +23,7 @@ const Color scoreboard_hard_color = Color(0x76, 0x42, 0x8A); const Color flash_color = Color(0xFF, 0xFF, 0xFF); const Color fade_color = Color(0x27, 0x27, 0x36); const Color orange_color = Color(0xFF, 0x7A, 0x00); +const Color orange_soft_color = Color(0xFF, 0xA0, 0x33); // Calcula el cuadrado de la distancia entre dos puntos double distanceSquared(int x1, int y1, int x2, int y2) diff --git a/source/utils.h b/source/utils.h index 05a8515..81961b6 100644 --- a/source/utils.h +++ b/source/utils.h @@ -44,6 +44,30 @@ struct Color Uint8 r, g, b; constexpr Color() : r(0), g(0), b(0) {} explicit constexpr Color(int red, int green, int blue) : r(red), g(green), b(blue) {} + + // Método para obtener el color inverso + constexpr Color getInverse() const + { + return Color(255 - r, 255 - g, 255 - b); + } + + // Método para aclarar el color + Color lighten(int amount = 50) const + { + return Color( + std::min(255, r + amount), + std::min(255, g + amount), + std::min(255, b + amount)); + } + + // Método para oscurecer el color + Color darken(int amount = 50) const + { + return Color( + std::max(0, r - amount), + std::max(0, g - amount), + std::max(0, b - amount)); + } }; // Posiciones de las notificaciones @@ -177,4 +201,5 @@ extern const Color scoreboard_normal_color; extern const Color scoreboard_hard_color; extern const Color flash_color; extern const Color fade_color; -extern const Color orange_color; \ No newline at end of file +extern const Color orange_color; +extern const Color orange_soft_color; \ No newline at end of file