diff --git a/source/intro.cpp b/source/intro.cpp index c4f1791..0490781 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -19,18 +19,15 @@ struct JA_Music_t; // Constructor -Intro::Intro(JA_Music_t *music):music(music) +Intro::Intro(JA_Music_t *music) : music(music) { // Copia los punteros - input = Input::get(); - asset = Asset::get(); - screen = Screen::get(); - SDL_Renderer *renderer = screen->getRenderer(); + SDL_Renderer *renderer = Screen::get()->getRenderer(); // Reserva memoria para los objetos eventHandler = std::make_unique(); - texture = std::make_unique(renderer, asset->get("intro.png")); - text = std::make_unique(asset->get("nokia.png"), asset->get("nokia.txt"), renderer); + texture = std::make_unique(renderer, Asset::get()->get("intro.png")); + text = std::make_unique(Asset::get()->get("nokia.png"), Asset::get()->get("nokia.txt"), renderer); // Inicializa variables section::name = section::NAME_INTRO; @@ -49,7 +46,7 @@ Intro::Intro(JA_Music_t *music):music(music) ss->setEnabledCounter(20); ss->setDestX(param.game.gameArea.centerX - 64); ss->setDestY(param.game.gameArea.firstQuarterY - 24); - bitmaps.push_back(ss.get()); + bitmaps.push_back(std::move(ss)); } bitmaps[0]->setPosX(-128); @@ -111,7 +108,7 @@ Intro::Intro(JA_Music_t *music):music(music) w->setKerning(-1); w->setEnabled(false); w->setEnabledCounter(180); - texts.push_back(w.get()); + texts.push_back(std::move(w)); } // Un dia qualsevol de l'any 2000 @@ -150,7 +147,7 @@ Intro::Intro(JA_Music_t *music):music(music) texts[8]->setCaption(lang::getText(35)); texts[8]->setSpeed(16); - for (auto text : texts) + for (auto &text : texts) { text->center(param.game.gameArea.centerX); } @@ -191,7 +188,7 @@ void Intro::checkEvents() void Intro::checkInput() { // Comprueba si se ha pulsado cualquier botón (de los usados para jugar) - if (input->checkAnyButtonPressed()) + if (Input::get()->checkAnyButtonPressed()) { JA_StopMusic(); section::name = section::NAME_TITLE; @@ -200,7 +197,7 @@ void Intro::checkInput() } // Comprueba el input para el resto de objetos - screen->checkInput(); + Screen::get()->checkInput(); // Comprueba los inputs que se pueden introducir en cualquier sección del juego globalInputs::check(); @@ -371,15 +368,15 @@ void Intro::update() ticks = SDL_GetTicks(); // Actualiza el objeto screen - screen->update(); + Screen::get()->update(); // Actualiza los objetos - for (auto bitmap : bitmaps) + for (auto &bitmap : bitmaps) { bitmap->update(); } - for (auto text : texts) + for (auto &text : texts) { text->update(); } @@ -393,24 +390,24 @@ void Intro::update() void Intro::render() { // Prepara para empezar a dibujar en la textura de juego - screen->start(); + Screen::get()->start(); // Limpia la pantalla - screen->clean(bgColor); + Screen::get()->clean(bgColor); // Dibuja los objetos - for (auto bitmap : bitmaps) + for (auto &bitmap : bitmaps) { bitmap->render(); } - for (auto text : texts) + for (auto &text : texts) { text->render(); } // Vuelca el contenido del renderizador en pantalla - screen->blit(); + Screen::get()->blit(); } // Bucle principal diff --git a/source/intro.h b/source/intro.h index ee64343..760de64 100644 --- a/source/intro.h +++ b/source/intro.h @@ -1,16 +1,13 @@ #pragma once -#include // for SDL_Event -#include // for Uint32, Uint8 -#include // for vector +#include // for SDL_Event +#include // for Uint32, Uint8 +#include // for vector #include -class Asset; -class Input; -class Screen; -class SmartSprite; +#include "smart_sprite.h" #include "texture.h" #include "text.h" -class Writer; +#include "writer.h" struct JA_Music_t; /* @@ -22,17 +19,13 @@ struct JA_Music_t; class Intro { private: - // Objetos y punteros - Screen *screen; // Objeto encargado de dibujar en pantalla - Asset *asset; // Objeto que gestiona todos los ficheros de recursos - Input *input; // Objeto pata gestionar la entrada - - std::unique_ptr texture; // Textura con los graficos - std::unique_ptr eventHandler; // Manejador de eventos - std::unique_ptr text; // Textos de la intro - - std::vector bitmaps; // Vector con los sprites inteligentes para los dibujos de la intro - std::vector texts; // Textos de la intro + // Objetos + std::unique_ptr texture; // Textura con los graficos + std::unique_ptr eventHandler; // Manejador de eventos + std::unique_ptr text; // Textos de la intro + + std::vector> bitmaps; // Vector con los sprites inteligentes para los dibujos de la intro + std::vector> texts; // Textos de la intro // Variables Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa diff --git a/source/smart_sprite.h b/source/smart_sprite.h index 2f211ce..66f8b3c 100644 --- a/source/smart_sprite.h +++ b/source/smart_sprite.h @@ -1,6 +1,6 @@ #pragma once -#include "animated_sprite.h" // for AnimatedSprite +#include "animated_sprite.h" // for AnimatedSprite class Texture; // Clase SmartSprite @@ -25,6 +25,9 @@ public: // Constructor SmartSprite(Texture *texture); + // Destructor + ~SmartSprite() = default; + // Inicializa el objeto void init(); diff --git a/source/writer.cpp b/source/writer.cpp index 137ea6b..ffbd81c 100644 --- a/source/writer.cpp +++ b/source/writer.cpp @@ -2,11 +2,8 @@ #include "text.h" // for Text // Constructor -Writer::Writer(Text *text) +Writer::Writer(Text *text) : text(text) { - // Copia los punteros - this->text = text; - // Inicializa variables posX = 0; posY = 0; @@ -28,7 +25,8 @@ void Writer::update() if (enabled) { if (!completed) - { // No completado + { + // No completado if (writingCounter > 0) { writingCounter--; @@ -46,8 +44,9 @@ void Writer::update() } } - if (completed) - { // Completado + else + { + // Completado if (enabledCounter > 0) { enabledCounter--; @@ -108,7 +107,7 @@ void Writer::setEnabled(bool value) } // Obtiene el valor de la variable -bool Writer::IsEnabled() +bool Writer::IsEnabled() const { return enabled; } @@ -120,7 +119,7 @@ void Writer::setEnabledCounter(int time) } // Obtiene el valor de la variable -int Writer::getEnabledCounter() +int Writer::getEnabledCounter() const { return enabledCounter; } @@ -132,7 +131,7 @@ void Writer::center(int x) } // Obtiene el valor de la variable -bool Writer::hasFinished() +bool Writer::hasFinished() const { return finished; } \ No newline at end of file diff --git a/source/writer.h b/source/writer.h index d8eae81..c8bee28 100644 --- a/source/writer.h +++ b/source/writer.h @@ -28,6 +28,9 @@ public: // Constructor Writer(Text *text); + // Destructor + ~Writer() = default; + // Actualiza el objeto void update(); @@ -53,17 +56,17 @@ public: void setEnabled(bool value); // Obtiene el valor de la variable - bool IsEnabled(); + bool IsEnabled() const; // Establece el valor de la variable void setEnabledCounter(int time); // Obtiene el valor de la variable - int getEnabledCounter(); + int getEnabledCounter() const; // Centra la cadena de texto a un punto X void center(int x); // Obtiene el valor de la variable - bool hasFinished(); + bool hasFinished() const; }; \ No newline at end of file