From d83c05bad4f79ee68c1c4026dac621426d48e9f7 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 29 Oct 2024 16:04:14 +0100 Subject: [PATCH] El game_text dels items ja son textures generades i precarregades --- data/gfx/game_text/game_text_1000_points.png | Bin 295 -> 0 bytes data/gfx/game_text/game_text_2500_points.png | Bin 371 -> 0 bytes data/gfx/game_text/game_text_5000_points.png | Bin 332 -> 0 bytes data/gfx/game_text/game_text_one_hit.png | Bin 399 -> 0 bytes data/gfx/game_text/game_text_powerup.png | Bin 453 -> 0 bytes data/gfx/game_text/game_text_stop.png | Bin 392 -> 0 bytes source/director.cpp | 9 ---- source/game.cpp | 12 ++--- source/resource.cpp | 45 ++++++++++++++----- source/resource.h | 5 ++- source/text.cpp | 5 ++- source/text.h | 2 +- 12 files changed, 48 insertions(+), 30 deletions(-) delete mode 100644 data/gfx/game_text/game_text_1000_points.png delete mode 100644 data/gfx/game_text/game_text_2500_points.png delete mode 100644 data/gfx/game_text/game_text_5000_points.png delete mode 100644 data/gfx/game_text/game_text_one_hit.png delete mode 100644 data/gfx/game_text/game_text_powerup.png delete mode 100644 data/gfx/game_text/game_text_stop.png diff --git a/data/gfx/game_text/game_text_1000_points.png b/data/gfx/game_text/game_text_1000_points.png deleted file mode 100644 index 3ef241e9f5ea3650be87de15c5723cb783fd4270..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 295 zcmV+?0oeYDP)Px#;Ymb6R5*>bk|7SlKoCV=2^XkndV@+tO{=g3RoNg>oQWeKE3v3z5XdGKl}(c+ z=>--+cCsxSl1;;^KX3l-WU@a1$aaMWxL>OP$1(l6$Cs1s3aymVN-1rdTz%W)%YQ!R z>e(J&4zPL+J^RCPvQ3iaUmMOnzC1~Dy=oq{^Pm24)<%ru=rq`TiJlB=+g4y0#gZtS zFVT}>UDpXbl?4FjOC|hN788#z2MFMky6q+b;Pz~=H6XQNuc0T5VlOVkk~G(06a&Zw tqXDUH=F6K$9Y_*gaW|%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002ovPDHLkV1hV`vKjyY diff --git a/data/gfx/game_text/game_text_powerup.png b/data/gfx/game_text/game_text_powerup.png deleted file mode 100644 index bb99a89a939d5f301b456fae3d1a7a9ddd77e3bf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 453 zcmV;$0XqJPP)Px$e@R3^R7i=vQlV~xP!v5Z{6Iz1KR`}khMHYaNPIGyL(VxSa%bW`_4V*-t+Fm0)VHNpaYA;F1PT{K^_jf+~WC7QPVWa zCogmF;2vZ?rn7b6cC&^b#U0-QaNWevmgL5CFKYVAV|>NDAH~>i){2my{V49}a&#Wb zIgjgg*qC`8pDyrVB9vzn?OYz`(`$^Hr|_fLXn@qxH>aoMJFeF$zm4e@riA$I{oOwjE?uCAgr_Px$LPbRI6&lKomV$@&geee-K%*W>(b>RU<=XRb1;T`T-SnTNhPXB3IQ{ zty)nN2t-5<0~yE`)k5X#iY`AI$-P zlu)LgAMXJGPcN?+hQVvHhQ)kcQwol%egN>RSPB5+I069biW%RwCCue$ziAJqQI;2| zD`s#hI8rG%n)ZO}tJ07^zxuPk?7Hr(X^i9MF4af?pxo|MmKPqOKOGZ07Q^k>TCT>; mJ$6r|eXH$Q47Z#7rN%c00Zadd(prefix + "/data/gfx/game/game_sky_colors.png", AssetType::BITMAP); } - { // Game Text - Asset::get()->add(prefix + "/data/gfx/game_text/game_text_1000_points.png", AssetType::BITMAP); - Asset::get()->add(prefix + "/data/gfx/game_text/game_text_2500_points.png", AssetType::BITMAP); - Asset::get()->add(prefix + "/data/gfx/game_text/game_text_5000_points.png", AssetType::BITMAP); - Asset::get()->add(prefix + "/data/gfx/game_text/game_text_powerup.png", AssetType::BITMAP); - Asset::get()->add(prefix + "/data/gfx/game_text/game_text_one_hit.png", AssetType::BITMAP); - Asset::get()->add(prefix + "/data/gfx/game_text/game_text_stop.png", AssetType::BITMAP); - } - { // Intro Asset::get()->add(prefix + "/data/gfx/intro/intro.png", AssetType::BITMAP); } diff --git a/source/game.cpp b/source/game.cpp index 7ab8ee5..4739176 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -118,12 +118,12 @@ void Game::setResources() // Texturas - Game_text { - game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_1000_points.png")); - game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_2500_points.png")); - game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_5000_points.png")); - game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_powerup.png")); - game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_one_hit.png")); - game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_stop.png")); + game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_1000_points")); + game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_2500_points")); + game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_5000_points")); + game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_powerup")); + game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_one_hit")); + game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_stop")); } // Texturas - Globos diff --git a/source/resource.cpp b/source/resource.cpp index 3e4fe34..c38c544 100644 --- a/source/resource.cpp +++ b/source/resource.cpp @@ -5,6 +5,7 @@ #include "asset.h" // Para Asset, AssetType #include "jail_audio.h" // Para JA_LoadMusic, JA_LoadSound #include "screen.h" // Para Screen +#include "text.h" // Para Text struct JA_Music_t; struct JA_Sound_t; @@ -40,19 +41,10 @@ Resource::Resource() loadAnimations(); loadDemoData(); addPalettes(); + createTextures(); std::cout << "\n** RESOURCES LOADED" << std::endl; } -// Destructor -Resource::~Resource() -{ - sounds_.clear(); - musics_.clear(); - textures_.clear(); - text_files_.clear(); - animations_.clear(); -} - // Obtiene el sonido a partir de un nombre JA_Sound_t *Resource::getSound(const std::string &name) { @@ -230,4 +222,35 @@ void Resource::addPalettes() // Fuentes getTexture("smb2.gif")->addPaletteFromFile(Asset::get()->get("smb2_palette1.pal")); -} \ No newline at end of file +} + +// Crea texturas +void Resource::createTextures() +{ + struct NameAndText + { + std::string name; + std::string text; + + // Constructor + NameAndText(const std::string &name_init, const std::string &text_init) + : name(name_init), text(text_init) {} + }; + + std::vector strings = { + NameAndText("game_text_1000_points", "1.000"), + NameAndText("game_text_2500_points", "2.500"), + NameAndText("game_text_5000_points", "5.000"), + NameAndText("game_text_powerup", "PowerUp"), + NameAndText("game_text_one_hit", "+1 Hit"), + NameAndText("game_text_stop", "Stop!")}; + + auto text = std::make_unique(getTexture("04b_25.png"), getTextFile("04b_25.txt")); + + std::cout << "\n>> CREATING TEXTURES" << std::endl; + for (const auto &s : strings) + { + textures_.emplace_back(ResourceTexture(s.name, text->writeToTexture(s.text, -2))); + printWithDots("Texture : ", s.name, "[ DONE ]"); + } +} diff --git a/source/resource.h b/source/resource.h index 34da948..9e7fad6 100644 --- a/source/resource.h +++ b/source/resource.h @@ -99,13 +99,16 @@ private: // Añade paletas a las texturas void addPalettes(); + // Crea texturas + void createTextures(); + // [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos resource desde fuera // Constructor Resource(); // Destructor - ~Resource(); + ~Resource() = default; public: // [SINGLETON] Crearemos el objeto resource con esta función estática diff --git a/source/text.cpp b/source/text.cpp index 45dfbbf..703c359 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -140,12 +140,13 @@ void Text::write(int x, int y, const std::string &text, int kerning, int lenght) } // Escribe el texto en una textura -std::shared_ptr Text::writeToTexture(int x, int y, const std::string &text, int kerning) +std::shared_ptr Text::writeToTexture(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->createBlank(width, box_height_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET); + texture->setBlendMode(SDL_BLENDMODE_BLEND); texture->setAsRenderTarget(renderer); write(0, 0, text, kerning); diff --git a/source/text.h b/source/text.h index 8bb588f..ae22c45 100644 --- a/source/text.h +++ b/source/text.h @@ -52,7 +52,7 @@ public: 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); + std::shared_ptr writeToTexture(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);