diff --git a/source/define_buttons.cpp b/source/define_buttons.cpp index 26d6cb7..c620b00 100644 --- a/source/define_buttons.cpp +++ b/source/define_buttons.cpp @@ -7,8 +7,8 @@ #include "utils.h" // for op_controller_t, options_t, param_t, paramGame_t // Constructor -DefineButtons::DefineButtons(Text *text) - : text(text) +DefineButtons::DefineButtons(std::unique_ptr text) + : text(std::move(text)) { // Copia punteros a los objetos input = Input::get(); @@ -54,14 +54,6 @@ DefineButtons::DefineButtons(Text *text) } } -// Actualiza las variables del objeto -void DefineButtons::update() -{ - if (enabled) - { - } -} - // Dibuja el objeto en pantalla void DefineButtons::render() { diff --git a/source/define_buttons.h b/source/define_buttons.h index 0312481..6effa30 100644 --- a/source/define_buttons.h +++ b/source/define_buttons.h @@ -5,7 +5,8 @@ #include // for string, basic_string #include // for vector #include "input.h" // for inputs_e -class Text; +#include "text.h" +#include struct db_button_t { @@ -20,7 +21,7 @@ class DefineButtons private: // Objetos Input *input; // Objeto pata gestionar la entrada - Text *text; // Objeto para escribir texto + std::shared_ptr text; // Objeto para escribir texto // Variables bool enabled; // Indica si el objeto está habilitado @@ -45,14 +46,11 @@ private: public: // Constructor - DefineButtons(Text *text); + DefineButtons(std::unique_ptr text); // Destructor ~DefineButtons() = default; - // Actualiza las variables del objeto - void update(); - // Dibuja el objeto en pantalla void render(); diff --git a/source/explosions.cpp b/source/explosions.cpp index de91d7e..843a1c8 100644 --- a/source/explosions.cpp +++ b/source/explosions.cpp @@ -41,7 +41,7 @@ void Explosions::addTexture(int size, std::shared_ptr texture, std::vec { explosion_texture_t temp; temp.size = size; - temp.texture = texture.get(); + temp.texture = texture; temp.animation = animation; textures.push_back(temp); } diff --git a/source/explosions.h b/source/explosions.h index 3df5121..290d8f3 100644 --- a/source/explosions.h +++ b/source/explosions.h @@ -8,7 +8,7 @@ struct explosion_texture_t { - Texture *texture; // Textura para la explosión + std::shared_ptrtexture; // Textura para la explosión std::vector *animation; // Animación para la textura int size; // Tamaño de la explosión }; diff --git a/source/game_logo.cpp b/source/game_logo.cpp index 061fb71..e63ced6 100644 --- a/source/game_logo.cpp +++ b/source/game_logo.cpp @@ -16,18 +16,18 @@ GameLogo::GameLogo(int x, int y) : x(x), y(y) { // Crea los objetos - dustTexture = std::make_unique(Screen::get()->getRenderer(), Asset::get()->get("title_dust.png")); - coffeeTexture = std::make_unique(Screen::get()->getRenderer(), Asset::get()->get("title_coffee.png")); - crisisTexture = std::make_unique(Screen::get()->getRenderer(), Asset::get()->get("title_crisis.png")); - arcadeEditionTexture = std::make_unique(Screen::get()->getRenderer(), Asset::get()->get("title_arcade_edition.png")); + dustTexture = std::make_shared(Screen::get()->getRenderer(), Asset::get()->get("title_dust.png")); + coffeeTexture = std::make_shared(Screen::get()->getRenderer(), Asset::get()->get("title_coffee.png")); + crisisTexture = std::make_shared(Screen::get()->getRenderer(), Asset::get()->get("title_crisis.png")); + arcadeEditionTexture = std::make_shared(Screen::get()->getRenderer(), Asset::get()->get("title_arcade_edition.png")); - coffeeSprite = std::make_unique(coffeeTexture.get()); - crisisSprite = std::make_unique(crisisTexture.get()); + coffeeSprite = std::make_unique(coffeeTexture); + crisisSprite = std::make_unique(crisisTexture); - arcadeEditionSprite = std::make_unique((param.game.width - arcadeEditionTexture->getWidth()) / 2, param.title.arcadeEditionPosition, arcadeEditionTexture->getWidth(), arcadeEditionTexture->getHeight(), arcadeEditionTexture.get()); + arcadeEditionSprite = std::make_unique((param.game.width - arcadeEditionTexture->getWidth()) / 2, param.title.arcadeEditionPosition, arcadeEditionTexture->getWidth(), arcadeEditionTexture->getHeight(), arcadeEditionTexture); - dustLSprite = std::make_unique(dustTexture.get(), Asset::get()->get("title_dust.ani")); - dustRSprite = std::make_unique(dustTexture.get(), Asset::get()->get("title_dust.ani")); + dustLSprite = std::make_unique(dustTexture, Asset::get()->get("title_dust.ani")); + dustRSprite = std::make_unique(dustTexture, Asset::get()->get("title_dust.ani")); // Sonidos crashSound = JA_LoadSound(Asset::get()->get("title.wav").c_str()); diff --git a/source/game_logo.h b/source/game_logo.h index 71029e2..f721d77 100644 --- a/source/game_logo.h +++ b/source/game_logo.h @@ -15,10 +15,10 @@ class GameLogo { private: // Objetos y punteros - std::unique_ptr dustTexture; // Textura con los graficos del polvo - std::unique_ptr coffeeTexture; // Textura con los graficos de la palabra "COFFEE" - std::unique_ptr crisisTexture; // Textura con los graficos de la plabra "CRISIS" - std::unique_ptr arcadeEditionTexture; // Textura con los graficos de "Arcade Edition" + std::shared_ptr dustTexture; // Textura con los graficos del polvo + std::shared_ptr coffeeTexture; // Textura con los graficos de la palabra "COFFEE" + std::shared_ptr crisisTexture; // Textura con los graficos de la plabra "CRISIS" + std::shared_ptr arcadeEditionTexture; // Textura con los graficos de "Arcade Edition" std::unique_ptr dustLSprite; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo std::unique_ptr dustRSprite; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo diff --git a/source/instructions.cpp b/source/instructions.cpp index 8e4bfac..5a7fb83 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -80,25 +80,25 @@ Instructions::~Instructions() void Instructions::iniSprites() { // Inicializa las texturas - auto item1 = std::make_unique(renderer, Asset::get()->get("item_points1_disk.png")); - itemTextures.push_back(std::move(item1)); + auto item1 = std::make_shared(renderer, Asset::get()->get("item_points1_disk.png")); + itemTextures.push_back(item1); - auto item2 = std::make_unique(renderer, Asset::get()->get("item_points2_gavina.png")); - itemTextures.push_back(std::move(item2)); + auto item2 = std::make_shared(renderer, Asset::get()->get("item_points2_gavina.png")); + itemTextures.push_back(item2); - auto item3 = std::make_unique(renderer, Asset::get()->get("item_points3_pacmar.png")); - itemTextures.push_back(std::move(item3)); + auto item3 = std::make_shared(renderer, Asset::get()->get("item_points3_pacmar.png")); + itemTextures.push_back(item3); - auto item4 = std::make_unique(renderer, Asset::get()->get("item_clock.png")); - itemTextures.push_back(std::move(item4)); + auto item4 = std::make_shared(renderer, Asset::get()->get("item_clock.png")); + itemTextures.push_back(item4); - auto item5 = std::make_unique(renderer, Asset::get()->get("item_coffee.png")); - itemTextures.push_back(std::move(item5)); + auto item5 = std::make_shared(renderer, Asset::get()->get("item_coffee.png")); + itemTextures.push_back(item5); // Inicializa los sprites for (int i = 0; i < (int)itemTextures.size(); ++i) { - auto sprite = std::make_unique(0, 0, param.game.itemSize, param.game.itemSize, itemTextures[i].get()); + auto sprite = std::make_unique(0, 0, param.game.itemSize, param.game.itemSize, itemTextures[i]); sprite->setPos((SDL_Point){spritePos.x, spritePos.y + ((param.game.itemSize + itemSpace) * i)}); sprites.push_back(std::move(sprite)); } diff --git a/source/instructions.h b/source/instructions.h index 049a13a..2f0c885 100644 --- a/source/instructions.h +++ b/source/instructions.h @@ -31,7 +31,7 @@ class Instructions { private: // Objetos y punteros - std::vector> itemTextures; // Vector con las texturas de los items + std::vector> itemTextures; // Vector con las texturas de los items std::vector> sprites; // Vector con los sprites de los items std::unique_ptr eventHandler; // Manejador de eventos std::unique_ptr text; // Objeto para escribir texto diff --git a/source/logo.cpp b/source/logo.cpp index 19345c4..3027474 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -20,10 +20,9 @@ Logo::Logo() SDL_Renderer *renderer = Screen::get()->getRenderer(); // Reserva memoria para los punteros - eventHandler = std::make_unique(); - jailTexture = std::make_unique(renderer, Asset::get()->get("logo_jailgames.png")); - sinceTexture = std::make_unique(renderer, Asset::get()->get("logo_since_1998.png")); - sinceSprite = std::make_unique((param.game.width - sinceTexture->getWidth()) / 2, 83 + jailTexture->getHeight() + 5, sinceTexture->getWidth(), sinceTexture->getHeight(), sinceTexture.get()); + jailTexture = std::make_shared(renderer, Asset::get()->get("logo_jailgames.png")); + sinceTexture = std::make_shared(renderer, Asset::get()->get("logo_since_1998.png")); + sinceSprite = std::make_unique((param.game.width - sinceTexture->getWidth()) / 2, 83 + jailTexture->getHeight() + 5, sinceTexture->getWidth(), sinceTexture->getHeight(), sinceTexture); // Inicializa variables counter = 0; @@ -45,7 +44,7 @@ Logo::Logo() // Crea los sprites de cada linea for (int i = 0; i < jailTexture->getHeight(); ++i) { - auto temp = std::make_unique(0, i, jailTexture->getWidth(), 1, jailTexture.get()); + auto temp = std::make_unique(0, i, jailTexture->getWidth(), 1, jailTexture); temp->setSpriteClip(0, i, jailTexture->getWidth(), 1); const int posX = (i % 2 == 0) ? param.game.width + (i * 3) : -jailTexture->getWidth() - (i * 3); temp->setPosX(posX); @@ -74,20 +73,21 @@ void Logo::reloadTextures() // Comprueba el manejador de eventos void Logo::checkEvents() { + SDL_Event event; // Comprueba los eventos que hay en la cola - while (SDL_PollEvent(eventHandler.get()) != 0) + while (SDL_PollEvent(&event)) { // Evento de salida de la aplicación - if (eventHandler->type == SDL_QUIT) + if (event.type == SDL_QUIT) { section::name = section::NAME_QUIT; break; } // Comprueba si se ha cambiado el tamaño de la ventana - else if (eventHandler->type == SDL_WINDOWEVENT) + else if (event.type == SDL_WINDOWEVENT) { - if (eventHandler->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) + if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { reloadTextures(); } diff --git a/source/logo.h b/source/logo.h index 469d260..8d38f4b 100644 --- a/source/logo.h +++ b/source/logo.h @@ -22,10 +22,9 @@ class Logo { private: // Objetos y punteros - std::unique_ptr eventHandler; // Manejador de eventos - std::unique_ptr sinceTexture; // Textura con los graficos "Since 1998" + std::shared_ptr sinceTexture; // Textura con los graficos "Since 1998" std::unique_ptr sinceSprite; // Sprite para manejar la sinceTexture - std::unique_ptr jailTexture; // Textura con los graficos "JAILGAMES" + std::shared_ptr jailTexture; // Textura con los graficos "JAILGAMES" std::vector> jailSprite; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES // Variables diff --git a/source/on_screen_help.cpp b/source/on_screen_help.cpp index 5347d6c..04bb64e 100644 --- a/source/on_screen_help.cpp +++ b/source/on_screen_help.cpp @@ -92,17 +92,17 @@ void OnScreenHelp::render() void OnScreenHelp::fillTexture() { // Cambia el renderizador a la textura - SDL_Texture *temp = SDL_GetRenderTarget(Screen::get()->getRenderer()); + auto *temp = SDL_GetRenderTarget(Screen::get()->getRenderer()); SDL_SetRenderTarget(Screen::get()->getRenderer(), texture); // Crea el objeto para el texto auto text = std::make_unique(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Screen::get()->getRenderer()); // Crea la textura con los gráficos - auto controllersTexture = std::make_unique(Screen::get()->getRenderer(), Asset::get()->get("controllers.png")); + auto controllersTexture = std::make_shared(Screen::get()->getRenderer(), Asset::get()->get("controllers.png")); // Crea el sprite para dibujar los gráficos - auto sprite = std::make_unique((SDL_Rect){0, 0, 16, 16}, controllersTexture.get()); + auto sprite = std::make_unique((SDL_Rect){0, 0, 16, 16}, controllersTexture); // Borra la textura SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0); diff --git a/source/on_screen_help.h b/source/on_screen_help.h index cd900e2..c1135ec 100644 --- a/source/on_screen_help.h +++ b/source/on_screen_help.h @@ -3,8 +3,9 @@ #include // for SDL_Rect #include // for SDL_Texture #include // for vector -class Sprite; // lines 10-10 -class Text; +#include +#include "sprite.h" // lines 10-10 +#include "text.h" enum class OnScreenHelpStatus { diff --git a/source/screen.cpp b/source/screen.cpp index efbd726..e70cd30 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -232,15 +232,13 @@ void Screen::setVideoMode(ScreenVideoMode videoMode) // Reinicia los shaders if (options.video.shaders) { +#ifdef SHADERS std::ifstream f(asset->get("crtpi.glsl").c_str()); std::string source((std::istreambuf_iterator(f)), std::istreambuf_iterator()); shader::init(window, shaderCanvas, source.c_str()); +#endif } - - // Actualiza variables - // shakeEffect.originalPos = srcrect.x; - // shakeEffect.originalWidth = srcrect.w; } // Camibia entre pantalla completa y ventana diff --git a/source/text.cpp b/source/text.cpp index 8976e73..951e718 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -95,8 +95,8 @@ Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer) } // Crea los objetos - texture = std::make_unique(renderer, bitmapFile); - sprite = std::make_unique((SDL_Rect){0, 0, boxWidth, boxHeight}, texture.get()); + texture = std::make_shared(renderer, bitmapFile); + sprite = std::make_unique((SDL_Rect){0, 0, boxWidth, boxHeight}, texture); // Inicializa variables fixedWidth = false; diff --git a/source/text.h b/source/text.h index 10dffbe..8dfd949 100644 --- a/source/text.h +++ b/source/text.h @@ -34,7 +34,7 @@ class Text private: // Objetos y punteros std::unique_ptr sprite; // Objeto con los graficos para el texto - std::unique_ptr texture; // Textura con los bitmaps del texto + std::shared_ptr texture; // Textura con los bitmaps del texto // Variables int boxWidth; // Anchura de la caja de cada caracter en el png diff --git a/source/title.cpp b/source/title.cpp index e2eca2e..d5dc791 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -35,15 +35,15 @@ Title::Title(JA_Music_t *music) text1->setPalette(1); text2 = std::make_unique(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer); - miniLogoTexture = std::make_unique(renderer, asset->get("logo_jailgames_mini.png")); - miniLogoSprite = std::make_unique(param.game.gameArea.centerX - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture.get()); + miniLogoTexture = std::make_shared(renderer, asset->get("logo_jailgames_mini.png")); + miniLogoSprite = std::make_unique(param.game.gameArea.centerX - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture); tiledbg = std::make_unique(asset->get("title_bg_tile.png"), (SDL_Rect){0, 0, param.game.width, param.game.height}, TILED_MODE_RANDOM); gameLogo = std::make_unique(param.game.gameArea.centerX, param.title.titleCCPosition); gameLogo->enable(); - defineButtons = std::make_unique(text2.get()); + defineButtons = std::make_unique(std::move(text2)); // Inicializa los valores init(); @@ -78,9 +78,6 @@ void Title::update() // Actualiza el objeto screen screen->update(); - // Actualiza el objeto 'defineButtons' - defineButtons->update(); - // Comprueba el fade y si se ha acabado fade->update(); if (fade->hasEnded()) diff --git a/source/title.h b/source/title.h index 8c24691..f3ca992 100644 --- a/source/title.h +++ b/source/title.h @@ -52,7 +52,7 @@ private: std::unique_ptr tiledbg; // Objeto para dibujar el mosaico animado de fondo std::unique_ptr gameLogo; // Objeto para dibujar el logo con el título del juego std::unique_ptr defineButtons; // Objeto para definir los botones del joystic - std::unique_ptr miniLogoTexture; // Textura con el logo de JailGames mini + std::shared_ptr miniLogoTexture; // Textura con el logo de JailGames mini std::unique_ptr miniLogoSprite; // Sprite con el logo de JailGames mini std::unique_ptr text1; // Objeto de texto para poder escribir textos en pantalla