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 3ef241e..0000000 Binary files a/data/gfx/game_text/game_text_1000_points.png and /dev/null differ diff --git a/data/gfx/game_text/game_text_2500_points.png b/data/gfx/game_text/game_text_2500_points.png deleted file mode 100644 index 0620e34..0000000 Binary files a/data/gfx/game_text/game_text_2500_points.png and /dev/null differ diff --git a/data/gfx/game_text/game_text_5000_points.png b/data/gfx/game_text/game_text_5000_points.png deleted file mode 100644 index acdb157..0000000 Binary files a/data/gfx/game_text/game_text_5000_points.png and /dev/null differ diff --git a/data/gfx/game_text/game_text_one_hit.png b/data/gfx/game_text/game_text_one_hit.png deleted file mode 100644 index 739b3b0..0000000 Binary files a/data/gfx/game_text/game_text_one_hit.png and /dev/null differ 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 bb99a89..0000000 Binary files a/data/gfx/game_text/game_text_powerup.png and /dev/null differ diff --git a/data/gfx/game_text/game_text_stop.png b/data/gfx/game_text/game_text_stop.png deleted file mode 100644 index dcca8d8..0000000 Binary files a/data/gfx/game_text/game_text_stop.png and /dev/null differ diff --git a/source/director.cpp b/source/director.cpp index 88d8498..336b75c 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -427,15 +427,6 @@ void Director::setFileList() Asset::get()->add(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);