diff --git a/data/font/04b_25.png b/data/font/04b_25.png new file mode 100644 index 0000000..dfc7409 Binary files /dev/null and b/data/font/04b_25.png differ diff --git a/data/font/nokia2.txt b/data/font/04b_25.txt similarity index 81% rename from data/font/nokia2.txt rename to data/font/04b_25.txt index 8b54d71..6fc925b 100644 --- a/data/font/nokia2.txt +++ b/data/font/04b_25.txt @@ -1,194 +1,194 @@ # box width -10 +14 # box height -10 +14 # 32 espacio ( ) -5 +8 # 33 ! -4 +5 # 34 " -5 -# 35 # -7 +8 +# 35 +10 # 36 $ -7 +10 # 37 % -8 +9 # 38 & -8 +11 # 39 ' -3 +5 # 40 ( -5 +7 # 41 ) -5 +7 # 42 * -7 +7 # 43 + -7 +9 # 44 , -4 +5 # 45 - -6 +9 # 46 . -4 +5 # 47 / -5 +12 # 48 0 -7 -# 49 1 -5 -# 50 2 -7 -# 51 3 -7 -# 52 4 -7 -# 53 5 -7 -# 54 6 -7 -# 55 7 -7 -# 56 8 -7 -# 57 9 -7 -# 58 : -4 -# 59 ; -4 -# 60 < -6 -# 61 = -6 -# 62 > -6 -# 63 ? -7 -# 64 @ 8 -# 65 A -7 -# 66 B -7 -# 67 C -7 -# 68 D -7 -# 69 E -7 -# 70 F -7 -# 71 G -7 -# 72 H -7 -# 73 I -4 -# 74 J +# 49 1 6 +# 50 2 +8 +# 51 3 +8 +# 52 4 +8 +# 53 5 +8 +# 54 6 +8 +# 55 7 +8 +# 56 8 +8 +# 57 9 +8 +# 58 : +5 +# 59 ; +5 +# 60 < +8 +# 61 = +8 +# 62 > +8 +# 63 ? +8 +# 64 @ +11 +# 65 A +8 +# 66 B +8 +# 67 C +8 +# 68 D +8 +# 69 E +8 +# 70 F +8 +# 71 G +8 +# 72 H +8 +# 73 I +5 +# 74 J +8 # 75 K 8 # 76 L -6 +8 # 77 M -9 +11 # 78 N 8 # 79 O 8 # 80 P -7 +8 # 81 Q 8 # 82 R -7 -# 83 S -6 -# 84 T 8 +# 83 S +8 +# 84 T +9 # 85 U -7 +8 # 86 V 8 # 87 W -9 +11 # 88 X 8 # 89 Y 8 # 90 Z -7 -# 91 [ -4 -# 92 \ -5 -# 93 ] -4 -# 94 ^ -5 -# 95 _ 8 +# 91 [ +7 +# 92 \ +11 +# 93 ] +7 +# 94 ^ +6 +# 95 _ +7 # 96 ` -4 +6 # 97 a -7 +8 # 98 b -7 +8 # 99 c -6 +8 # 100 d -7 +8 # 101 e -7 +8 # 102 f -5 +8 # 103 g -7 +8 # 104 h -7 +8 # 105 i -4 +5 # 106 j -5 +8 # 107 k -7 +8 # 108 l -4 +8 # 109 m -10 +11 # 110 n -7 +8 # 111 o -7 +8 # 112 p -7 +8 # 113 q -7 +8 # 114 r -6 +8 # 115 s -6 +8 # 116 t -5 -# 117 u -7 -# 118 v -7 -# 119 w 9 +# 117 u +8 +# 118 v +8 +# 119 w +11 # 120 x -7 +8 # 121 y -7 +8 # 122 z -7 -# 123 { -> ñ -7 -# 124 | -> ç -7 +8 +# 123 { +1 +# 124 | +1 # 125 } -0 +1 # 126 ~ -0 \ No newline at end of file +1 \ No newline at end of file diff --git a/data/font/nokia.png b/data/font/nokia.png index 6f9d351..7e40857 100644 Binary files a/data/font/nokia.png and b/data/font/nokia.png differ diff --git a/data/font/nokia2.png b/data/font/nokia2.png deleted file mode 100644 index 7e40857..0000000 Binary files a/data/font/nokia2.png and /dev/null differ diff --git a/data/font/nokia_big2.png b/data/font/nokia_big2.png deleted file mode 100644 index 1b660fd..0000000 Binary files a/data/font/nokia_big2.png and /dev/null differ diff --git a/data/font/nokia_big2.txt b/data/font/nokia_big2.txt deleted file mode 100644 index 499ba1e..0000000 --- a/data/font/nokia_big2.txt +++ /dev/null @@ -1,194 +0,0 @@ -# box width -20 -# box height -20 -# 32 espacio ( ) -8 -# 33 ! -8 -# 34 " -10 -# 35 # -14 -# 36 $ -14 -# 37 % -16 -# 38 & -16 -# 39 ' -6 -# 40 ( -10 -# 41 ) -10 -# 42 * -14 -# 43 + -14 -# 44 , -8 -# 45 - -12 -# 46 . -8 -# 47 / -10 -# 48 0 -14 -# 49 1 -10 -# 50 2 -14 -# 51 6 -14 -# 52 8 -14 -# 53 10 -14 -# 54 12 -14 -# 55 14 -14 -# 56 16 -14 -# 57 18 -14 -# 58 : -8 -# 59 ; -8 -# 60 < -12 -# 61 = -12 -# 62 > -12 -# 63 ? -14 -# 64 @ -16 -# 65 A -14 -# 66 B -14 -# 67 C -14 -# 68 D -14 -# 69 E -14 -# 70 F -14 -# 71 G -14 -# 72 H -14 -# 73 I -8 -# 74 J -12 -# 75 K -16 -# 76 L -12 -# 77 M -18 -# 78 N -16 -# 79 O -16 -# 80 P -14 -# 81 Q -16 -# 82 R -14 -# 83 S -12 -# 84 T -16 -# 85 U -14 -# 86 V -16 -# 87 W -18 -# 88 X -16 -# 89 Y -16 -# 90 Z -14 -# 91 [ -8 -# 92 \ -10 -# 93 ] -8 -# 94 ^ -10 -# 95 _ -16 -# 96 ` -8 -# 97 a -14 -# 98 b -14 -# 99 c -12 -# 100 d -14 -# 101 e -14 -# 102 f -10 -# 103 g -14 -# 104 h -14 -# 105 i -8 -# 106 j -10 -# 107 k -14 -# 108 l -8 -# 109 m -20 -# 110 n -14 -# 111 o -14 -# 112 p -14 -# 113 q -14 -# 114 r -12 -# 115 s -12 -# 116 t -10 -# 117 u -14 -# 118 v -14 -# 119 w -18 -# 120 x -14 -# 121 y -14 -# 122 z -14 -# 123 { -> ñ -14 -# 124 | -> ç -14 -# 125 } -0 -# 126 ~ -0 \ No newline at end of file diff --git a/data/font/smb2_big.png b/data/font/smb2_big.png deleted file mode 100644 index c4c3051..0000000 Binary files a/data/font/smb2_big.png and /dev/null differ diff --git a/data/font/smb2_big.txt b/data/font/smb2_big.txt deleted file mode 100644 index 3b51a2e..0000000 --- a/data/font/smb2_big.txt +++ /dev/null @@ -1,194 +0,0 @@ -# box width -16 -# box height -16 -# 32 espacio ( ) -16 -# 33 ! -16 -# 34 " -16 -# 35 # -16 -# 36 $ -16 -# 37 % -16 -# 38 & -16 -# 39 ' -16 -# 40 ( -16 -# 41 ) -16 -# 42 * -16 -# 43 + -16 -# 44 , -16 -# 45 - -16 -# 46 . -16 -# 47 / -16 -# 48 0 -16 -# 49 1 -16 -# 50 2 -16 -# 51 3 -16 -# 52 4 -16 -# 53 5 -16 -# 54 6 -16 -# 55 7 -16 -# 56 8 -16 -# 57 9 -16 -# 58 : -16 -# 59 ; -16 -# 60 < -16 -# 61 = -16 -# 62 > -16 -# 63 ? -16 -# 64 @ -16 -# 65 A -16 -# 66 B -16 -# 67 C -16 -# 68 D -16 -# 69 E -16 -# 70 F -16 -# 71 G -16 -# 72 H -16 -# 73 I -16 -# 74 J -16 -# 75 K -16 -# 76 L -16 -# 77 M -16 -# 78 N -16 -# 79 O -16 -# 80 P -16 -# 81 Q -16 -# 82 R -16 -# 83 S -16 -# 84 T -16 -# 85 U -16 -# 86 V -16 -# 87 W -16 -# 88 X -16 -# 89 Y -16 -# 90 Z -16 -# 91 [ -16 -# 92 \ -16 -# 93 ] -16 -# 94 ^ -16 -# 95 _ -16 -# 96 ` -16 -# 97 a -16 -# 98 b -16 -# 99 c -16 -# 100 d -16 -# 101 e -16 -# 102 f -16 -# 103 g -16 -# 104 h -16 -# 105 i -16 -# 106 j -16 -# 107 k -16 -# 108 l -16 -# 109 m -16 -# 110 n -16 -# 111 o -16 -# 112 p -16 -# 113 q -16 -# 114 r -16 -# 115 s -16 -# 116 t -16 -# 117 u -16 -# 118 v -16 -# 119 w -16 -# 120 x -16 -# 121 y -16 -# 122 z -16 -# 123 { -16 -# 124 | -16 -# 125 } -16 -# 126 ~ -16 \ No newline at end of file diff --git a/source/director.cpp b/source/director.cpp index f74e7bd..88d8498 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -495,16 +495,12 @@ void Director::setFileList() Asset::get()->add(prefix + "/data/font/8bithud.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/font/8bithud.txt", AssetType::FONT); Asset::get()->add(prefix + "/data/font/nokia.png", AssetType::BITMAP); - Asset::get()->add(prefix + "/data/font/nokia_big2.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/font/nokia.txt", AssetType::FONT); - Asset::get()->add(prefix + "/data/font/nokia2.png", AssetType::BITMAP); - Asset::get()->add(prefix + "/data/font/nokia2.txt", AssetType::FONT); - Asset::get()->add(prefix + "/data/font/nokia_big2.txt", AssetType::FONT); - Asset::get()->add(prefix + "/data/font/smb2_big.png", AssetType::BITMAP); - Asset::get()->add(prefix + "/data/font/smb2_big.txt", AssetType::FONT); Asset::get()->add(prefix + "/data/font/smb2.gif", AssetType::BITMAP); Asset::get()->add(prefix + "/data/font/smb2_palette1.pal", AssetType::PALETTE); Asset::get()->add(prefix + "/data/font/smb2.txt", AssetType::FONT); + Asset::get()->add(prefix + "/data/font/04b_25.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/font/04b_25.txt", AssetType::FONT); // Textos Asset::get()->add(prefix + "/data/lang/es_ES.txt", AssetType::LANG); diff --git a/source/game.cpp b/source/game.cpp index 6f172d5..7ab8ee5 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -205,9 +205,9 @@ void Game::setResources() // Texto { text_ = std::make_unique(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt")); - text_big_ = std::make_unique(Resource::get()->getTexture("smb2_big.png"), Resource::get()->getTextFile("smb2_big.txt")); - text_nokia2_ = std::make_unique(Resource::get()->getTexture("nokia2.png"), Resource::get()->getTextFile("nokia2.txt")); - text_nokia2_big_ = std::make_unique(Resource::get()->getTexture("nokia_big2.png"), Resource::get()->getTextFile("nokia_big2.txt")); + text_nokia2_ = std::make_unique(Resource::get()->getTexture("nokia.png"), Resource::get()->getTextFile("nokia.txt")); + text_nokia2_big_ = std::make_unique(Resource::get()->getTexture("nokia.png"), Resource::get()->getTextFile("nokia.txt")); + text_04b_25_ = std::make_unique(Resource::get()->getTexture("04b_25.png"), Resource::get()->getTextFile("04b_25.txt")); } } diff --git a/source/game.h b/source/game.h index ae06967..b2791b1 100644 --- a/source/game.h +++ b/source/game.h @@ -145,7 +145,7 @@ private: std::vector> explosions_animations_; // Vector con las animaciones de las explosiones std::unique_ptr text_; // Fuente para los textos del juego - std::unique_ptr text_big_; // Fuente de texto grande + std::unique_ptr text_04b_25_; // Fuente de texto grande std::unique_ptr text_nokia2_; // Otra fuente de texto para mensajes std::unique_ptr text_nokia2_big_; // Y la versión en grande diff --git a/source/intro.cpp b/source/intro.cpp index f2df9b8..95cb2ea 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -139,9 +139,7 @@ Intro::Intro() texts_[8]->setSpeed(16); for (auto &text : texts_) - { text->center(param.game.game_area.center_x); - } } // Recarga todas las texturas @@ -171,9 +169,7 @@ void Intro::checkEvents() case SDL_WINDOWEVENT: { if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) - { reloadTextures(); - } break; } diff --git a/source/text.cpp b/source/text.cpp index 9c4b167..45dfbbf 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -4,6 +4,7 @@ #include // Para cerr #include // Para runtime_error #include "sprite.h" // Para Sprite +#include "screen.h" // Para Screen #include "texture.h" // Para Texture #include "utils.h" // Para Color, getFileName, printWithDots @@ -122,26 +123,35 @@ Text::Text(std::shared_ptr texture, std::shared_ptr text_file // Escribe texto en pantalla void Text::write(int x, int y, const std::string &text, int kerning, int lenght) { - auto shift = 0; + int shift = 0; if (lenght == -1) - { lenght = text.length(); - } sprite_->setY(y); - const auto width = sprite_->getWidth(); - const auto height = sprite_->getHeight(); for (int i = 0; i < lenght; ++i) { - const auto index = static_cast(text[i]); - sprite_->setSpriteClip(offset_[index].x, offset_[index].y, width, height); + auto index = static_cast(text[i]); + sprite_->setSpriteClip(offset_[index].x, offset_[index].y, box_width_, box_height_); sprite_->setX(x + shift); sprite_->render(); - shift += fixed_width_ ? box_width_ : (offset_[int(text[i])].w + kerning); + shift += offset_[static_cast(text[i])].w + kerning; } } +// Escribe el texto en una textura +std::shared_ptr Text::writeToTexture(int x, int y, const std::string &text, int kerning) +{ + auto renderer = Screen::get()->getRenderer(); + auto texture = std::make_shared(renderer); + auto width = lenght(text, kerning); + texture->createBlank(width, box_height_); + texture->setAsRenderTarget(renderer); + write(0, 0, text, kerning); + + return texture; +} + // Escribe el texto con colores void Text::writeColored(int x, int y, const std::string &text, Color color, int kerning, int lenght) { @@ -211,12 +221,9 @@ void Text::writeDX(Uint8 flags, int x, int y, const std::string &text, int kerni // Obtiene la longitud en pixels de una cadena int Text::lenght(const std::string &text, int kerning) const { - auto shift = 0; - - for (int i = 0; i < (int)text.length(); ++i) - { - shift += (offset_[int(text[i])].w + kerning); - } + int shift = 0; + for (size_t i = 0; i < text.length(); ++i) + shift += (offset_[static_cast(text[i])].w + kerning); // Descuenta el kerning del último caracter return shift - kerning; diff --git a/source/text.h b/source/text.h index 4fac5ec..8bb588f 100644 --- a/source/text.h +++ b/source/text.h @@ -51,6 +51,9 @@ public: // Escribe el texto en pantalla void write(int x, int y, const std::string &text, int kerning = 1, int lenght = -1); + // Escribe el texto en una textura + std::shared_ptr writeToTexture(int x, int y, const std::string &text, int kerning = 1); + // Escribe el texto con colores void writeColored(int x, int y, const std::string &text, Color color, int kerning = 1, int lenght = -1); diff --git a/source/texture.cpp b/source/texture.cpp index 1c88c91..de85f08 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -60,6 +60,9 @@ Texture::~Texture() // Carga una imagen desde un fichero bool Texture::loadFromFile(const std::string &file_path) { + if (file_path.empty()) + return false; + int req_format = STBI_rgb_alpha; int width, height, orig_format; unsigned char *data = stbi_load(file_path.c_str(), &width, &height, &orig_format, req_format);