Make uniques en intro.cpp

This commit is contained in:
2024-10-07 17:28:34 +02:00
parent 6305a67c84
commit 0330fe6b74
2 changed files with 20 additions and 35 deletions

View File

@@ -19,19 +19,18 @@
struct JA_Music_t;
// Constructor
Intro::Intro(JA_Music_t *music)
Intro::Intro(JA_Music_t *music):music(music)
{
// Copia los punteros
this->music = music;
input = Input::get();
asset = Asset::get();
screen = Screen::get();
SDL_Renderer *renderer = screen->getRenderer();
// Reserva memoria para los objetos
eventHandler = new SDL_Event();
texture = new Texture(renderer, asset->get("intro.png"));
text = new Text(asset->get("nokia.png"), asset->get("nokia.txt"), renderer);
eventHandler = std::make_unique<SDL_Event>();
texture = std::make_unique<Texture>(renderer, asset->get("intro.png"));
text = std::make_unique<Text>(asset->get("nokia.png"), asset->get("nokia.txt"), renderer);
// Inicializa variables
section::name = section::NAME_INTRO;
@@ -41,16 +40,16 @@ Intro::Intro(JA_Music_t *music)
scene = 1;
// Inicializa los bitmaps de la intro
const int totalBitmaps = 6;
constexpr int totalBitmaps = 6;
for (int i = 0; i < totalBitmaps; ++i)
{
SmartSprite *ss = new SmartSprite(texture);
auto ss = std::make_unique<SmartSprite>(texture.get());
ss->setWidth(128);
ss->setHeight(96);
ss->setEnabledCounter(20);
ss->setDestX(param.game.gameArea.centerX - 64);
ss->setDestY(param.game.gameArea.firstQuarterY - 24);
bitmaps.push_back(ss);
bitmaps.push_back(ss.get());
}
bitmaps[0]->setPosX(-128);
@@ -103,16 +102,16 @@ Intro::Intro(JA_Music_t *music)
bitmaps[5]->setSpriteClip(128, 192, 128, 96);
// Inicializa los textos de la intro
const int totalTexts = 9;
constexpr int totalTexts = 9;
for (int i = 0; i < totalTexts; ++i)
{
Writer *w = new Writer(text);
auto w = std::make_unique<Writer>(text.get());
w->setPosX(BLOCK * 0);
w->setPosY(param.game.height - (BLOCK * 6));
w->setKerning(-1);
w->setEnabled(false);
w->setEnabledCounter(180);
texts.push_back(w);
texts.push_back(w.get());
}
// Un dia qualsevol de l'any 2000
@@ -157,23 +156,6 @@ Intro::Intro(JA_Music_t *music)
}
}
// Destructor
Intro::~Intro()
{
delete eventHandler;
delete texture;
for (auto bitmap : bitmaps)
{
delete bitmap;
}
for (auto text : texts)
{
delete text;
}
}
// Recarga todas las texturas
void Intro::reloadTextures()
{
@@ -185,7 +167,7 @@ void Intro::reloadTextures()
void Intro::checkEvents()
{
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(eventHandler) != 0)
while (SDL_PollEvent(eventHandler.get()) != 0)
{
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)