El game_text dels items ja son textures generades i precarregades

This commit is contained in:
2024-10-29 16:04:14 +01:00
parent e2abf835f9
commit d83c05bad4
12 changed files with 48 additions and 30 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 399 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 453 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 392 B

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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"));
}
}
// 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<NameAndText> 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<Text>(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 ]");
}
}

View File

@@ -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

View File

@@ -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<Texture> Text::writeToTexture(int x, int y, const std::string &text, int kerning)
std::shared_ptr<Texture> Text::writeToTexture(const std::string &text, int kerning)
{
auto renderer = Screen::get()->getRenderer();
auto texture = std::make_shared<Texture>(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);

View File

@@ -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<Texture> writeToTexture(int x, int y, const std::string &text, int kerning = 1);
std::shared_ptr<Texture> 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);