Make uniques en intro.cpp
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32, Uint8
|
||||
#include <vector> // for vector
|
||||
#include <memory>
|
||||
class Asset;
|
||||
class Input;
|
||||
class Screen;
|
||||
class SmartSprite;
|
||||
class Text;
|
||||
class Texture;
|
||||
#include "texture.h"
|
||||
#include "text.h"
|
||||
class Writer;
|
||||
struct JA_Music_t;
|
||||
|
||||
@@ -23,13 +24,15 @@ class Intro
|
||||
private:
|
||||
// Objetos y punteros
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
Texture *texture; // Textura con los graficos
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||
Input *input; // Objeto pata gestionar la entrada
|
||||
|
||||
std::unique_ptr<Texture> texture; // Textura con los graficos
|
||||
std::unique_ptr<SDL_Event> eventHandler; // Manejador de eventos
|
||||
std::unique_ptr<Text> text; // Textos de la intro
|
||||
|
||||
std::vector<SmartSprite *> bitmaps; // Vector con los sprites inteligentes para los dibujos de la intro
|
||||
std::vector<Writer *> texts; // Textos de la intro
|
||||
Text *text; // Textos de la intro
|
||||
|
||||
// Variables
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
@@ -60,7 +63,7 @@ public:
|
||||
Intro(JA_Music_t *music);
|
||||
|
||||
// Destructor
|
||||
~Intro();
|
||||
~Intro() = default;
|
||||
|
||||
// Bucle principal
|
||||
void run();
|
||||
|
||||
Reference in New Issue
Block a user