diff --git a/source/credits.cpp b/source/credits.cpp index 609fa41..56105db 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -20,15 +20,9 @@ // Constructor Credits::Credits() - : screen_(Screen::get()), - renderer_(Screen::get()->getRenderer()), - resource_(Resource::get()), - asset_(Asset::get()), - input_(Input::get()) { // Reserva memoria para los punteros - text_ = resource_->getText("smb2"); - sprite_ = std::make_shared(resource_->getTexture("shine.png"), resource_->getAnimations("shine.ani")); + sprite_ = std::make_shared(Resource::get()->getTexture("shine.png"), Resource::get()->getAnimations("shine.ani")); // Inicializa variables options.section.section = Section::CREDITS; @@ -36,10 +30,10 @@ Credits::Credits() sprite_->setPosition({194, 174, 8, 8}); // Cambia el color del borde - screen_->setBorderColor(stringToColor(options.video.palette, "black")); + Screen::get()->setBorderColor(stringToColor(options.video.palette, "black")); // Crea la textura para el texto que se escribe en pantalla - text_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); + text_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); if (text_texture_ == nullptr) { if (options.console) @@ -50,7 +44,7 @@ Credits::Credits() SDL_SetTextureBlendMode(text_texture_, SDL_BLENDMODE_BLEND); // Crea la textura para cubrir el rexto - cover_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); + cover_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); if (cover_texture_ == nullptr) { if (options.console) @@ -175,54 +169,56 @@ void Credits::fillTexture() iniTexts(); // Rellena la textura de texto - SDL_SetRenderTarget(renderer_, text_texture_); + SDL_SetRenderTarget(Screen::get()->getRenderer(), text_texture_); Color color = stringToColor(options.video.palette, "black"); - SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); - SDL_RenderClear(renderer_); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF); + SDL_RenderClear(Screen::get()->getRenderer()); + + auto text = Resource::get()->getText("smb2"); // Escribe el texto en la textura - const int SIZE = text_->getCharacterSize(); + const int SIZE = text->getCharacterSize(); int pos_y = 0; for (const auto &t : texts_) { - text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, pos_y * SIZE, t.label, 1, t.color); + text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, pos_y * SIZE, t.label, 1, t.color); pos_y++; } // Escribe el corazón - const int TEXT_LENGHT = text_->lenght(texts_[22].label, 1) - text_->lenght(" ", 1); // Se resta el ultimo caracter que es un espacio + const int TEXT_LENGHT = text->lenght(texts_[22].label, 1) - text->lenght(" ", 1); // Se resta el ultimo caracter que es un espacio const int POS_X = ((PLAY_AREA_WIDTH - TEXT_LENGHT) / 2) + TEXT_LENGHT; - text_->writeColored(POS_X, 176, "}", stringToColor(options.video.palette, "bright_red")); + text->writeColored(POS_X, 176, "}", stringToColor(options.video.palette, "bright_red")); // Recoloca el sprite del brillo sprite_->setPosX(POS_X + 2); - SDL_SetRenderTarget(renderer_, nullptr); + SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr); // Rellena la textura que cubre el texto con color transparente - SDL_SetRenderTarget(renderer_, cover_texture_); - SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0x00); - SDL_RenderClear(renderer_); + SDL_SetRenderTarget(Screen::get()->getRenderer(), cover_texture_); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0x00); + SDL_RenderClear(Screen::get()->getRenderer()); // Los primeros 8 pixels crea una malla - SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF); for (int i = 0; i < 256; i += 2) { - SDL_RenderDrawPoint(renderer_, i, 0); - SDL_RenderDrawPoint(renderer_, i, 2); - SDL_RenderDrawPoint(renderer_, i, 4); - SDL_RenderDrawPoint(renderer_, i, 6); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 0); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 2); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 4); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 6); - SDL_RenderDrawPoint(renderer_, i + 1, 5); - SDL_RenderDrawPoint(renderer_, i + 1, 7); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 5); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 7); } // El resto se rellena de color sólido SDL_Rect rect = {0, 8, 256, 192}; - SDL_RenderFillRect(renderer_, &rect); + SDL_RenderFillRect(Screen::get()->getRenderer(), &rect); - SDL_SetRenderTarget(renderer_, nullptr); + SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr); } // Actualiza el contador @@ -269,7 +265,7 @@ void Credits::update() // Actualiza el contador updateCounter(); - screen_->update(); + Screen::get()->update(); // Actualiza el sprite con el brillo if (counter_ > 770) @@ -283,28 +279,28 @@ void Credits::update() void Credits::render() { // Prepara para empezar a dibujar en la textura de juego - screen_->start(); + Screen::get()->start(); // Limpia la pantalla - screen_->clean(); + Screen::get()->clean(); if (counter_ < 1150) { // Dibuja la textura con el texto en pantalla - SDL_RenderCopy(renderer_, text_texture_, nullptr, nullptr); + SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, nullptr, nullptr); // Dibuja la textura que cubre el texto const int offset = std::min(counter_ / 8, 192 / 2); SDL_Rect srcRect = {0, 0, 256, 192 - (offset * 2)}; SDL_Rect dstRect = {0, offset * 2, 256, 192 - (offset * 2)}; - SDL_RenderCopy(renderer_, cover_texture_, &srcRect, &dstRect); + SDL_RenderCopy(Screen::get()->getRenderer(), cover_texture_, &srcRect, &dstRect); // Dibuja el sprite con el brillo sprite_->render(); } // Vuelca el contenido del renderizador en pantalla - screen_->render(); + Screen::get()->render(); } // Bucle para el logo del juego diff --git a/source/credits.h b/source/credits.h index 3d944f3..b0ceb7e 100644 --- a/source/credits.h +++ b/source/credits.h @@ -1,17 +1,17 @@ #pragma once -#include // for SDL_Texture, SDL_Renderer -#include // for Uint32 -#include // for shared_ptr -#include // for string -#include // for vector -#include "utils.h" // for Color -class AnimatedSprite; // lines 10-10 -class Asset; // lines 11-11 -class Input; // lines 12-12 -class Resource; // lines 13-13 -class Screen; // lines 14-14 -class Text; // lines 15-15 +#include // for SDL_Texture, SDL_Renderer +#include // for Uint32 +#include // for shared_ptr +#include // for string +#include // for vector +#include "utils.h" // for Color +class AnimatedSprite; // lines 10-10 +class Asset; // lines 11-11 +class Input; // lines 12-12 +class Resource; // lines 13-13 +class Screen; // lines 14-14 +class Text; // lines 15-15 class Credits { @@ -23,21 +23,15 @@ private: }; // Objetos y punteros - Screen *screen_; // Objeto encargado de dibujar en pantalla - SDL_Renderer *renderer_; // El renderizador de la ventana - Resource *resource_; // Objeto con los recursos - Asset *asset_; // Objeto con los ficheros de recursos - Input *input_; // Objeto pata gestionar la entrada - std::shared_ptr text_; // Objeto para escribir texto en pantalla SDL_Texture *text_texture_; // Textura para dibujar el texto SDL_Texture *cover_texture_; // Textura para cubrir el texto std::shared_ptr sprite_; // Sprite para el brillo del corazón // Variables - int counter_ = 0; // Contador - bool counter_enabled_ = true; // Indica si esta activo el contador - int sub_counter_ = 0; // Contador secundario - Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa + int counter_ = 0; // Contador + bool counter_enabled_ = true; // Indica si esta activo el contador + int sub_counter_ = 0; // Contador secundario + Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa std::vector texts_; // Vector con los textos // Actualiza las variables diff --git a/source/debug.cpp b/source/debug.cpp index c954335..0752979 100644 --- a/source/debug.cpp +++ b/source/debug.cpp @@ -26,35 +26,30 @@ Debug *Debug::get() return Debug::debug_; } -// Constructor -Debug::Debug() - : screen_(Screen::get()), - renderer_(Screen::get()->getRenderer()), - text_(Resource::get()->getText("debug")) {} - // Dibuja en pantalla void Debug::render() { + auto text = Resource::get()->getText("debug"); int y = y_; int w = 0; for (const auto &s : slot_) { - text_->write(x_, y, s); + text->write(x_, y, s); w = (std::max(w, (int)s.length())); - y += text_->getCharacterSize() + 1; - if (y > 192 - text_->getCharacterSize()) + y += text->getCharacterSize() + 1; + if (y > 192 - text->getCharacterSize()) { y = y_; - x_ += w * text_->getCharacterSize() + 2; + x_ += w * text->getCharacterSize() + 2; } } y = 0; for (const auto &l : log_) { - text_->writeColored(x_ + 10, y, l, Color(255, 255, 255)); - y += text_->getCharacterSize() + 1; + text->writeColored(x_ + 10, y, l, Color(255, 255, 255)); + y += text->getCharacterSize() + 1; } } diff --git a/source/debug.h b/source/debug.h index f90451f..e09d579 100644 --- a/source/debug.h +++ b/source/debug.h @@ -1,13 +1,13 @@ #pragma once -#include // for SDL_Point -#include // for SDL_Renderer -#include // for shared_ptr -#include // for string -#include // for vector -class Screen; // lines 9-9 -class Text; // lines 10-10 -class Texture; // lines 11-11 +#include // for SDL_Point +#include // for SDL_Renderer +#include // for shared_ptr +#include // for string +#include // for vector +class Screen; // lines 9-9 +class Text; // lines 10-10 +class Texture; // lines 11-11 // Clase Debug class Debug @@ -16,11 +16,6 @@ private: // [SINGLETON] Objeto privado static Debug *debug_; - // Objetos y punteros - Screen *screen_; // Objeto encargado de dibujar en pantalla - SDL_Renderer *renderer_; // El renderizador de la ventana - std::shared_ptr text_; // Objeto encargado de escribir texto en pantalla - // Variables std::vector slot_; // Vector con los textos a escribir std::vector log_; // Vector con los textos a escribir @@ -29,7 +24,7 @@ private: bool enabled_ = false; // Indica si esta activo el modo debug // Constructor - Debug(); + Debug() = default; // Destructor ~Debug() = default; @@ -59,5 +54,5 @@ public: void addToLog(std::string text) { log_.push_back(text); } void clearLog() { log_.clear(); } void setEnabled(bool value) { enabled_ = value; } - void switchEnabled() { enabled_ = !enabled_; } + void toggleEnabled() { enabled_ = !enabled_; } }; \ No newline at end of file diff --git a/source/demo.cpp b/source/demo.cpp index bf31aae..5869a77 100644 --- a/source/demo.cpp +++ b/source/demo.cpp @@ -19,13 +19,7 @@ // Constructor Demo::Demo() - : screen_(Screen::get()), - renderer_(Screen::get()->getRenderer()), - resource_(Resource::get()), - asset_(Asset::get()), - input_(Input::get()), - debug_(Debug::get()), - board_(std::make_shared()) + : board_(std::make_shared()) { // Inicia algunas variables board_->ini_clock = SDL_GetTicks(); @@ -45,7 +39,6 @@ Demo::Demo() ItemTracker::init(); scoreboard_ = std::make_shared(board_); room_ = std::make_shared(current_room_, board_); - text_ = resource_->getText("smb2"); // Inicializa el resto de variables counter_ = 0; @@ -112,7 +105,7 @@ void Demo::update() scoreboard_->update(); checkRoomChange(); - screen_->update(); + Screen::get()->update(); } } @@ -120,7 +113,7 @@ void Demo::update() void Demo::render() { // Prepara para dibujar el frame - screen_->start(); + Screen::get()->start(); // Dibuja los elementos del juego en orden room_->renderMap(); @@ -130,7 +123,7 @@ void Demo::render() scoreboard_->render(); // Actualiza la pantalla - screen_->render(); + Screen::get()->render(); } // Escribe el nombre de la pantalla @@ -139,10 +132,10 @@ void Demo::renderRoomName() // Texto en el centro de la pantalla SDL_Rect rect = {0, 16 * BLOCK, PLAY_AREA_WIDTH, BLOCK * 2}; Color color = stringToColor(options.video.palette, "white"); - SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); - SDL_RenderFillRect(renderer_, &rect); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF); + SDL_RenderFillRect(Screen::get()->getRenderer(), &rect); - text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, 16 * 8 + 4, room_->getName(), 1, room_->getBGColor()); + Resource::get()->getText("smb2")->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, 16 * 8 + 4, room_->getName(), 1, room_->getBGColor()); } // Cambia de habitación @@ -152,7 +145,7 @@ bool Demo::changeRoom(const std::string &room_path) if (room_path != "0") { // Verifica que exista el fichero que se va a cargar - if (asset_->get(room_path) != "") + if (Asset::get()->get(room_path) != "") { // Crea un objeto habitación a partir del fichero room_ = std::make_shared(room_path, board_); diff --git a/source/demo.h b/source/demo.h index b198665..af9192f 100644 --- a/source/demo.h +++ b/source/demo.h @@ -19,14 +19,7 @@ class Demo { private: // Objetos y punteros - Screen *screen_; // Objeto encargado de manejar el renderizador - SDL_Renderer *renderer_; // El renderizador de la ventana - Resource *resource_; // Objeto con los recursos - Asset *asset_; // Objeto con la ruta a todos los ficheros de recursos - Input *input_; // Objeto pata gestionar la entrada - Debug *debug_; // Objeto para gestionar la información de debug std::shared_ptr room_; // Objeto encargado de gestionar cada habitación del juego - std::shared_ptr text_; // Objeto para los textos del juego std::shared_ptr scoreboard_; // Objeto encargado de gestionar el marcador // Variables diff --git a/source/ending.cpp b/source/ending.cpp index 48cb2d9..c82fee9 100644 --- a/source/ending.cpp +++ b/source/ending.cpp @@ -23,24 +23,14 @@ // Constructor Ending::Ending() - : screen_(Screen::get()), - renderer_(Screen::get()->getRenderer()), - resource_(Resource::get()), - asset_(Asset::get()), - input_(Input::get()) + : counter_(-1), + pre_counter_(0), + cover_counter_(0), + ticks_(0), + current_scene_(0) { - // Reserva memoria para los punteros a objetos - text_ = resource_->getText("smb2"); - music = resource_->getMusic("ending1.ogg"); - - // Inicializa variables - counter_ = -1; - pre_counter_ = 0; - cover_counter_ = 0; options.section.section = Section::ENDING; options.section.subsection = Subsection::NONE; - ticks_ = 0; - current_scene_ = 0; // Inicializa los textos iniTexts(); @@ -52,10 +42,10 @@ Ending::Ending() iniScenes(); // Cambia el color del borde - screen_->setBorderColor(stringToColor(options.video.palette, "black")); + Screen::get()->setBorderColor(stringToColor(options.video.palette, "black")); // Crea la textura para cubrir el rexto - cover_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT + 8); + cover_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT + 8); if (cover_texture_ == nullptr) { if (options.console) @@ -100,7 +90,7 @@ void Ending::update() // Actualiza el volumen de la musica updateMusicVolume(); - screen_->update(); + Screen::get()->update(); } } @@ -108,10 +98,10 @@ void Ending::update() void Ending::render() { // Prepara para empezar a dibujar en la textura de juego - screen_->start(); + Screen::get()->start(); // Limpia la pantalla - screen_->clean(stringToColor(options.video.palette, "black")); + Screen::get()->clean(stringToColor(options.video.palette, "black")); // Dibuja las imagenes de la escena sprite_pics_[current_scene_].sprite->render(); @@ -131,7 +121,7 @@ void Ending::render() renderCoverTexture(); // Vuelca el contenido del renderizador en pantalla - screen_->render(); + Screen::get()->render(); } // Comprueba el manejador de eventos @@ -190,51 +180,54 @@ void Ending::iniTexts() for (const auto &t : texts) { - EndingTexture st; - const int width = text_->lenght(t.caption, 1) + 2 + 2; - const int height = text_->getCharacterSize() + 2 + 2; - Color c = stringToColor(options.video.palette, "black"); + auto text = Resource::get()->getText("smb2"); + const int WIDTH = text->lenght(t.caption, 1) + 2 + 2; + const int HEIGHT = text->getCharacterSize() + 2 + 2; + Color color = stringToColor(options.video.palette, "black"); + + EndingTexture st; + // Crea la texture - st.texture = std::make_shared(renderer_); - st.texture->createBlank(width, height); - st.texture->setAsRenderTarget(renderer_); + st.texture = std::make_shared(Screen::get()->getRenderer()); + st.texture->createBlank(WIDTH, HEIGHT); + st.texture->setAsRenderTarget(Screen::get()->getRenderer()); st.texture->setBlendMode(SDL_BLENDMODE_BLEND); - text_->writeDX(TEXT_STROKE, 2, 2, t.caption, 1, c, 2, c); + text->writeDX(TEXT_STROKE, 2, 2, t.caption, 1, color, 2, color); // Crea el sprite st.sprite = std::make_shared(st.texture, 0, 0, st.texture->getWidth(), st.texture->getHeight()); st.sprite->setPosition((GAMECANVAS_WIDTH - st.texture->getWidth()) / 2, t.pos); // Crea la coverTexture - st.cover_texture = std::make_shared(renderer_); - st.cover_texture->createBlank(width, height + 8); - st.cover_texture->setAsRenderTarget(renderer_); + st.cover_texture = std::make_shared(Screen::get()->getRenderer()); + st.cover_texture->createBlank(WIDTH, HEIGHT + 8); + st.cover_texture->setAsRenderTarget(Screen::get()->getRenderer()); st.cover_texture->setBlendMode(SDL_BLENDMODE_BLEND); // Rellena la coverTexture con color transparente - SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0); - SDL_RenderClear(renderer_); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0); + SDL_RenderClear(Screen::get()->getRenderer()); // Los primeros 8 pixels crea una malla - c = stringToColor(options.video.palette, "black"); - SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF); - for (int i = 0; i < width; i += 2) + color = stringToColor(options.video.palette, "black"); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF); + for (int i = 0; i < WIDTH; i += 2) { - SDL_RenderDrawPoint(renderer_, i, 0); - SDL_RenderDrawPoint(renderer_, i, 2); - SDL_RenderDrawPoint(renderer_, i, 4); - SDL_RenderDrawPoint(renderer_, i, 6); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 0); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 2); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 4); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 6); - SDL_RenderDrawPoint(renderer_, i + 1, 5); - SDL_RenderDrawPoint(renderer_, i + 1, 7); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 5); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 7); } // El resto se rellena de color sólido - SDL_Rect rect = {0, 8, width, height}; - c = stringToColor(options.video.palette, "black"); - SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF); - SDL_RenderFillRect(renderer_, &rect); + SDL_Rect rect = {0, 8, WIDTH, HEIGHT}; + color = stringToColor(options.video.palette, "black"); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF); + SDL_RenderFillRect(Screen::get()->getRenderer(), &rect); // Crea el sprite st.cover_sprite = std::make_shared(st.cover_texture, 0, 0, st.cover_texture->getWidth(), st.cover_texture->getHeight() - 8); @@ -243,7 +236,7 @@ void Ending::iniTexts() // Inicializa variables st.clip_desp = 8; - st.clip_height = height; + st.clip_height = HEIGHT; sprite_texts_.push_back(st); } @@ -280,7 +273,7 @@ void Ending::iniPics() EndingTexture sp; // Crea la texture - sp.texture = resource_->getTexture(p.caption); + sp.texture = Resource::get()->getTexture(p.caption); const int width = sp.texture->getWidth(); const int height = sp.texture->getHeight(); @@ -289,34 +282,34 @@ void Ending::iniPics() sp.sprite->setPosition((GAMECANVAS_WIDTH - width) / 2, p.pos); // Crea la coverTexture - sp.cover_texture = std::make_shared(renderer_); + sp.cover_texture = std::make_shared(Screen::get()->getRenderer()); sp.cover_texture->createBlank(width, height + 8); - sp.cover_texture->setAsRenderTarget(renderer_); + sp.cover_texture->setAsRenderTarget(Screen::get()->getRenderer()); sp.cover_texture->setBlendMode(SDL_BLENDMODE_BLEND); // Rellena la coverTexture con color transparente - SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0); - SDL_RenderClear(renderer_); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0); + SDL_RenderClear(Screen::get()->getRenderer()); // Los primeros 8 pixels crea una malla Color c = stringToColor(options.video.palette, "black"); - SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), c.r, c.g, c.b, 0xFF); for (int i = 0; i < width; i += 2) { - SDL_RenderDrawPoint(renderer_, i, 0); - SDL_RenderDrawPoint(renderer_, i, 2); - SDL_RenderDrawPoint(renderer_, i, 4); - SDL_RenderDrawPoint(renderer_, i, 6); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 0); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 2); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 4); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 6); - SDL_RenderDrawPoint(renderer_, i + 1, 5); - SDL_RenderDrawPoint(renderer_, i + 1, 7); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 5); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 7); } // El resto se rellena de color sólido SDL_Rect rect = {0, 8, width, height}; c = stringToColor(options.video.palette, "black"); - SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF); - SDL_RenderFillRect(renderer_, &rect); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), c.r, c.g, c.b, 0xFF); + SDL_RenderFillRect(Screen::get()->getRenderer(), &rect); // Crea el sprite sp.cover_sprite = std::make_shared(sp.cover_texture, 0, 0, sp.cover_texture->getWidth(), sp.cover_texture->getHeight() - 8); @@ -417,7 +410,7 @@ void Ending::iniScenes() // Bucle principal void Ending::run() { - JA_PlayMusic(music); + JA_PlayMusic(Resource::get()->getMusic("ending1.ogg")); while (options.section.section == Section::ENDING) { @@ -516,29 +509,29 @@ void Ending::checkChangeScene() void Ending::fillCoverTexture() { // Rellena la textura que cubre el texto con color transparente - SDL_SetRenderTarget(renderer_, cover_texture_); - SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0); - SDL_RenderClear(renderer_); + SDL_SetRenderTarget(Screen::get()->getRenderer(), cover_texture_); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0); + SDL_RenderClear(Screen::get()->getRenderer()); // Los primeros 8 pixels crea una malla const Color color = stringToColor(options.video.palette, "black"); - SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF); for (int i = 0; i < 256; i += 2) { - SDL_RenderDrawPoint(renderer_, i + 0, GAMECANVAS_HEIGHT + 0); - SDL_RenderDrawPoint(renderer_, i + 1, GAMECANVAS_HEIGHT + 1); - SDL_RenderDrawPoint(renderer_, i + 0, GAMECANVAS_HEIGHT + 2); - SDL_RenderDrawPoint(renderer_, i + 1, GAMECANVAS_HEIGHT + 3); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 0, GAMECANVAS_HEIGHT + 0); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, GAMECANVAS_HEIGHT + 1); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 0, GAMECANVAS_HEIGHT + 2); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, GAMECANVAS_HEIGHT + 3); - SDL_RenderDrawPoint(renderer_, i, GAMECANVAS_HEIGHT + 4); - SDL_RenderDrawPoint(renderer_, i, GAMECANVAS_HEIGHT + 6); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, GAMECANVAS_HEIGHT + 4); + SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, GAMECANVAS_HEIGHT + 6); } // El resto se rellena de color sólido SDL_Rect rect = {0, 0, 256, GAMECANVAS_HEIGHT}; - SDL_RenderFillRect(renderer_, &rect); + SDL_RenderFillRect(Screen::get()->getRenderer(), &rect); - SDL_SetRenderTarget(renderer_, nullptr); + SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr); } // Dibuja la cortinilla de cambio de escena @@ -549,7 +542,7 @@ void Ending::renderCoverTexture() const int offset = std::min(cover_counter_, 100); SDL_Rect srcRect = {0, 200 - (cover_counter_ * 2), 256, offset * 2}; SDL_Rect dstRect = {0, 0, 256, offset * 2}; - SDL_RenderCopy(renderer_, cover_texture_, &srcRect, &dstRect); + SDL_RenderCopy(Screen::get()->getRenderer(), cover_texture_, &srcRect, &dstRect); } } diff --git a/source/ending.h b/source/ending.h index cd9f552..1483a88 100644 --- a/source/ending.h +++ b/source/ending.h @@ -48,12 +48,6 @@ private: }; // Objetos y punteros - Screen *screen_; // Objeto encargado de dibujar en pantalla - SDL_Renderer *renderer_; // El renderizador de la ventana - Resource *resource_; // Objeto con los recursos - Asset *asset_; // Objeto con los ficheros de recursos - Input *input_; // Objeto pata gestionar la entrada - std::shared_ptr text_; // Objeto para escribir texto en pantalla SDL_Texture *cover_texture_; // Textura para cubrir el texto // Variables @@ -65,7 +59,6 @@ private: std::vector sprite_pics_; // Vector con los sprites de texto con su cortinilla int current_scene_; // Escena actual std::vector scenes_; // Vector con los textos e imagenes de cada escena - JA_Music_t *music; // Musica que suena durante el final // Actualiza el objeto void update(); diff --git a/source/game.cpp b/source/game.cpp index 12baf16..2274796 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -227,7 +227,7 @@ void Game::checkDebugEvents(const SDL_Event &event) switch (event.key.keysym.scancode) { case SDL_SCANCODE_G: - Debug::get()->switchEnabled(); + Debug::get()->toggleEnabled(); options.cheats.invincible = static_cast(Debug::get()->getEnabled()); board_->music = !Debug::get()->getEnabled(); board_->music ? JA_ResumeMusic() : JA_PauseMusic(); diff --git a/source/game_over.cpp b/source/game_over.cpp index dfb786c..53e1318 100644 --- a/source/game_over.cpp +++ b/source/game_over.cpp @@ -18,34 +18,25 @@ // Constructor GameOver::GameOver() - : screen_(Screen::get()), - renderer_(Screen::get()->getRenderer()), - resource_(Resource::get()), - asset_(Asset::get()), - input_(Input::get()) + : player_sprite_(std::make_shared(Resource::get()->getTexture("player_game_over.png"), Resource::get()->getAnimations("player_game_over.ani"))), + tv_sprite_(std::make_shared(Resource::get()->getTexture("tv.png"), Resource::get()->getAnimations("tv.ani"))), + pre_counter_(0), + counter_(0), + ticks_(0) { - // Reserva memoria para los punteros a objetos - text_ = resource_->getText("smb2"); - player_sprite_ = std::make_shared(resource_->getTexture("player_game_over.png"), resource_->getAnimations("player_game_over.ani")); - tv_sprite_ = std::make_shared(resource_->getTexture("tv.png"), resource_->getAnimations("tv.ani")); - music_ = resource_->getMusic("game_over.ogg"); - - // Inicializa variables - pre_counter_ = 0; - counter_ = 0; options.section.section = Section::GAME_OVER; options.section.subsection = Subsection::NONE; - ticks_ = 0; + player_sprite_->setPosX(GAMECANVAS_CENTER_X + 10); player_sprite_->setPosY(30); tv_sprite_->setPosX(GAMECANVAS_CENTER_X - tv_sprite_->getWidth() - 10); tv_sprite_->setPosY(30); // Inicializa el vector de colores - const std::vector colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"}; - for (const auto &cl : colorList) + const std::vector COLORS = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"}; + for (const auto &color : COLORS) { - colors_.push_back(stringToColor(options.video.palette, cl)); + colors_.push_back(stringToColor(options.video.palette, color)); } color_ = colors_.back(); } @@ -72,7 +63,7 @@ void GameOver::update() player_sprite_->update(); tv_sprite_->update(); - screen_->update(); + Screen::get()->update(); } } @@ -81,11 +72,13 @@ void GameOver::render() { constexpr int Y = 32; - screen_->start(); - screen_->clean(); + Screen::get()->start(); + Screen::get()->clean(); + + auto text = Resource::get()->getText("smb2"); // Escribe el texto de GAME OVER - text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y, "G A M E O V E R", 1, color_); + text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y, "G A M E O V E R", 1, color_); // Dibuja los sprites player_sprite_->setPosY(Y + 30); @@ -95,15 +88,15 @@ void GameOver::render() // Escribe el texto con las habitaciones y los items const std::string itemsTxt = std::to_string(options.stats.items / 100) + std::to_string((options.stats.items % 100) / 10) + std::to_string(options.stats.items % 10); const std::string roomsTxt = std::to_string(options.stats.rooms / 100) + std::to_string((options.stats.rooms % 100) / 10) + std::to_string(options.stats.rooms % 10); - text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 80, "ITEMS: " + itemsTxt, 1, color_); - text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 90, "ROOMS: " + roomsTxt, 1, color_); + text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 80, "ITEMS: " + itemsTxt, 1, color_); + text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 90, "ROOMS: " + roomsTxt, 1, color_); // Escribe el texto con "Tu peor pesadilla" - text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 110, "YOUR WORST NIGHTMARE IS", 1, color_); - text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 120, options.stats.worst_nightmare, 1, color_); + text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 110, "YOUR WORST NIGHTMARE IS", 1, color_); + text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 120, options.stats.worst_nightmare, 1, color_); // Vuelca el contenido del renderizador en pantalla - screen_->render(); + Screen::get()->render(); } // Comprueba el manejador de eventos @@ -178,7 +171,7 @@ void GameOver::updateCounters() // Hace sonar la música if (counter_ == 1) { - JA_PlayMusic(music_, 0); + JA_PlayMusic(Resource::get()->getMusic("game_over.ogg"), 0); } // Comprueba si ha terminado la sección diff --git a/source/game_over.h b/source/game_over.h index 130d8bf..ccb9fdf 100644 --- a/source/game_over.h +++ b/source/game_over.h @@ -22,12 +22,6 @@ private: static constexpr int COUNTER_FADE_LENGHT_ = 20; // Contador: duración del fade // Objetos y punteros - Screen *screen_; // Objeto encargado de dibujar en pantalla - SDL_Renderer *renderer_; // El renderizador de la ventana - Resource *resource_; // Objeto con los recursos - Asset *asset_; // Objeto con los ficheros de recursos - Input *input_; // Objeto pata gestionar la entrada - std::shared_ptr text_; // Objeto para escribir texto en pantalla std::shared_ptr player_sprite_; // Sprite con el jugador std::shared_ptr tv_sprite_; // Sprite con el televisor @@ -37,7 +31,6 @@ private: Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa std::vector colors_; // Vector con los colores para el fade Color color_; // Color usado para el texto y los sprites - JA_Music_t *music_; // Musica que suena durante el juego // Actualiza el objeto void update(); diff --git a/source/loading_screen.cpp b/source/loading_screen.cpp index a1a5700..0bd8257 100644 --- a/source/loading_screen.cpp +++ b/source/loading_screen.cpp @@ -18,30 +18,22 @@ // Constructor LoadingScreen::LoadingScreen() - : screen_(Screen::get()), - renderer_(Screen::get()->getRenderer()), - resource_(Resource::get()), - asset_(Asset::get()), - input_(Input::get()) { // Reserva memoria para los punteros if (options.video.palette == Palette::ZXSPECTRUM) { - mono_loading_screen_texture_ = resource_->getTexture("loading_screen_bn.png"); - color_loading_screen_texture_ = resource_->getTexture("loading_screen_color.png"); + mono_loading_screen_texture_ = Resource::get()->getTexture("loading_screen_bn.png"); + color_loading_screen_texture_ = Resource::get()->getTexture("loading_screen_color.png"); } else if (options.video.palette == Palette::ZXARNE) { - mono_loading_screen_texture_ = resource_->getTexture("loading_screen_bn_zxarne.png"); - color_loading_screen_texture_ = resource_->getTexture("loading_screen_color_zxarne.png"); + mono_loading_screen_texture_ = Resource::get()->getTexture("loading_screen_bn_zxarne.png"); + color_loading_screen_texture_ = Resource::get()->getTexture("loading_screen_color_zxarne.png"); } mono_loading_screen_sprite_ = std::make_shared(mono_loading_screen_texture_, 0, 0, mono_loading_screen_texture_->getWidth(), mono_loading_screen_texture_->getHeight()); color_loading_screen_sprite_ = std::make_shared(color_loading_screen_texture_, 0, 0, color_loading_screen_texture_->getWidth(), color_loading_screen_texture_->getHeight()); - loading_sound1_ = resource_->getMusic("loading_sound1.ogg"); - loading_sound2_ = resource_->getMusic("loading_sound2.ogg"); - loading_sound3_ = resource_->getMusic("loading_sound3.ogg"); - texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options.game.width, options.game.height); + texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options.game.width, options.game.height); if (texture_ == nullptr) { if (options.console) @@ -73,7 +65,7 @@ LoadingScreen::LoadingScreen() } // Cambia el color del borde - screen_->setBorderColor(stringToColor(options.video.palette, "black")); + Screen::get()->setBorderColor(stringToColor(options.video.palette, "black")); } // Destructor @@ -125,7 +117,7 @@ void LoadingScreen::updateLoad() load_rect_ = {0, 0, 16, 8}; color_loading_screen_sprite_->setClip(load_rect_); color_loading_screen_sprite_->setPosition(load_rect_); - JA_PlayMusic(loading_sound3_); + JA_PlayMusic(Resource::get()->getMusic("loading_sound3.ogg")); } } // Segunda parte de la carga, la parte de los bloques en color @@ -154,7 +146,7 @@ void LoadingScreen::updateCounter() if (counter_ == 1) { - JA_PlayMusic(loading_sound2_); + JA_PlayMusic(Resource::get()->getMusic("loading_sound2.ogg")); } } @@ -169,12 +161,12 @@ void LoadingScreen::renderBorder() { // Pinta el borde de colro azul Color color = stringToColor(options.video.palette, "blue"); - SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); - SDL_RenderClear(renderer_); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF); + SDL_RenderClear(Screen::get()->getRenderer()); // Añade lineas amarillas color = stringToColor(options.video.palette, "yellow"); - SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF); const int WIDTH = options.game.width + (options.video.border.width * 2); const int HEIGHT = options.game.height + (options.video.border.height * 2); bool drawEnabled = rand() % 2 == 0 ? true : false; @@ -187,7 +179,7 @@ void LoadingScreen::renderBorder() { for (int i = row; i < row + ROW_HEIGHT; ++i) { - SDL_RenderDrawLine(renderer_, 0, i, WIDTH, i); + SDL_RenderDrawLine(Screen::get()->getRenderer(), 0, i, WIDTH, i); } } row += ROW_HEIGHT; @@ -206,7 +198,7 @@ void LoadingScreen::update() updateCounter(); updateLoad(); fillTexture(); - screen_->update(); + Screen::get()->update(); } } @@ -216,20 +208,20 @@ void LoadingScreen::render() if (options.video.border.enabled) { // Prepara para empezar a dibujar en la textura del borde - screen_->startDrawOnBorder(); + Screen::get()->startDrawOnBorder(); // Dibuja el efecto de carga en el borde renderBorder(); } // Prepara para empezar a dibujar en la textura de juego - screen_->start(); + Screen::get()->start(); // Copila la textura a la pantalla - SDL_RenderCopy(renderer_, texture_, nullptr, nullptr); + SDL_RenderCopy(Screen::get()->getRenderer(), texture_, nullptr, nullptr); // Vuelca el contenido del renderizador en pantalla - screen_->render(); + Screen::get()->render(); } // Bucle para el logo del juego @@ -237,12 +229,12 @@ void LoadingScreen::run() { // Inicia el sonido de carga JA_SetVolume(64); - JA_PlayMusic(loading_sound1_); + JA_PlayMusic(Resource::get()->getMusic("loading_sound1.ogg")); // Limpia la pantalla - screen_->start(); - screen_->clean(); - screen_->render(); + Screen::get()->start(); + Screen::get()->clean(); + Screen::get()->render(); while (options.section.section == Section::LOADING_SCREEN) { @@ -258,27 +250,27 @@ void LoadingScreen::run() void LoadingScreen::fillTexture() { // Empieza a dibujar en la textura - auto temp = SDL_GetRenderTarget(renderer_); - SDL_SetRenderTarget(renderer_, texture_); + auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer()); + SDL_SetRenderTarget(Screen::get()->getRenderer(), texture_); // Dibuja la pantalla de carga renderLoad(); // Deja el renderizador como estaba - SDL_SetRenderTarget(renderer_, temp); + SDL_SetRenderTarget(Screen::get()->getRenderer(), temp); } // Limpia la textura void LoadingScreen::clearTexture() { // Empieza a dibujar en la textura - auto temp = SDL_GetRenderTarget(renderer_); - SDL_SetRenderTarget(renderer_, texture_); + auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer()); + SDL_SetRenderTarget(Screen::get()->getRenderer(), texture_); // Limpia - SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF); - SDL_RenderClear(renderer_); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0x00, 0x00, 0x00, 0xFF); + SDL_RenderClear(Screen::get()->getRenderer()); // Deja el renderizador como estaba - SDL_SetRenderTarget(renderer_, temp); + SDL_SetRenderTarget(Screen::get()->getRenderer(), temp); } \ No newline at end of file diff --git a/source/loading_screen.h b/source/loading_screen.h index 3bb8d4f..b6858ec 100644 --- a/source/loading_screen.h +++ b/source/loading_screen.h @@ -16,11 +16,6 @@ class LoadingScreen { private: // Objetos y punteros - Screen *screen_; // Objeto encargado de dibujar en pantalla - SDL_Renderer *renderer_; // El renderizador de la ventana - Resource *resource_; // Objeto con los recursos - Asset *asset_; // Objeto con los ficheros de recursos - Input *input_; // Objeto pata gestionar la entrada std::shared_ptr mono_loading_screen_texture_; // Textura con la pantalla de carga en blanco y negro std::shared_ptr color_loading_screen_texture_; // Textura con la pantalla de carga en color std::shared_ptr mono_loading_screen_sprite_; // Sprite para manejar la textura loadingScreenTexture1 @@ -32,9 +27,6 @@ private: Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa int load_counter_ = 0; // Contador para controlar las cargas bool loading_first_part_ = true; // Para saber en que parte de la carga se encuentra - JA_Music_t *loading_sound1_; // Sonidos para imitar la carga tipo spectrum - JA_Music_t *loading_sound2_; // Sonidos para imitar la carga tipo spectrum - JA_Music_t *loading_sound3_; // Sonidos para imitar la carga tipo spectrum int line_index_[192]; // El orden en el que se procesan las 192 lineas de la pantalla de carga SDL_Rect load_rect_ = {0, 0, 51, 1}; // Rectangulo para dibujar la pantalla de carga SDL_Texture *texture_; // Textura para dibujar la pantalla de carga diff --git a/source/logo.cpp b/source/logo.cpp index 988a4f8..c821da3 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -17,16 +17,10 @@ // Constructor Logo::Logo() - : screen_(Screen::get()), - renderer_(Screen::get()->getRenderer()), - resource_(Resource::get()), - asset_(Asset::get()), - input_(Input::get()) + : jailgames_texture_(Resource::get()->getTexture("jailgames.png")), + since_1998_texture_(Resource::get()->getTexture("since_1998.png")), + since_1998_sprite_(std::make_shared(since_1998_texture_, (256 - since_1998_texture_->getWidth()) / 2, 83 + jailgames_texture_->getHeight() + 5, since_1998_texture_->getWidth(), since_1998_texture_->getHeight())) { - // Reserva memoria para los punteros - jailgames_texture_ = resource_->getTexture("jailgames.png"); - since_1998_texture_ = resource_->getTexture("since_1998.png"); - since_1998_sprite_ = std::make_shared(since_1998_texture_, (256 - since_1998_texture_->getWidth()) / 2, 83 + jailgames_texture_->getHeight() + 5, since_1998_texture_->getWidth(), since_1998_texture_->getHeight()); since_1998_sprite_->setClip(0, 0, since_1998_texture_->getWidth(), since_1998_texture_->getHeight()); since_1998_texture_->setColor(0, 0, 0); @@ -50,7 +44,7 @@ Logo::Logo() } // Cambia el color del borde - screen_->setBorderColor(stringToColor(options.video.palette, "black")); + Screen::get()->setBorderColor(stringToColor(options.video.palette, "black")); } // Comprueba el manejador de eventos @@ -211,7 +205,7 @@ void Logo::update() // Gestiona el color de las texturas updateTextureColors(); - screen_->update(); + Screen::get()->update(); // Comprueba si ha terminado el logo if (counter_ == END_LOGO_ + POST_LOGO_) @@ -225,10 +219,10 @@ void Logo::update() void Logo::render() { // Prepara para empezar a dibujar en la textura de juego - screen_->start(); + Screen::get()->start(); // Limpia la pantalla - screen_->clean(); + Screen::get()->clean(); // Dibuja los objetos for (auto s : jailgames_sprite_) @@ -238,7 +232,7 @@ void Logo::render() since_1998_sprite_->render(); // Vuelca el contenido del renderizador en pantalla - screen_->render(); + Screen::get()->render(); } // Bucle para el logo del juego diff --git a/source/logo.h b/source/logo.h index ac9a212..f9d2e91 100644 --- a/source/logo.h +++ b/source/logo.h @@ -21,11 +21,6 @@ private: static constexpr int POST_LOGO_ = 20; // Tiempo que dura el logo con el fade al maximo // Objetos y punteros - Screen *screen_; // Objeto encargado de dibujar en pantalla - SDL_Renderer *renderer_; // El renderizador de la ventana - Resource *resource_; // Objeto con los recursos - Asset *asset_; // Objeto con los ficheros de recursos - Input *input_; // Objeto pata gestionar la entrada std::shared_ptr jailgames_texture_; // Textura con los graficos "JAILGAMES" std::shared_ptr since_1998_texture_; // Textura con los graficos "Since 1998" std::vector> jailgames_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES diff --git a/source/notifier.cpp b/source/notifier.cpp index 901d8e3..09986ef 100644 --- a/source/notifier.cpp +++ b/source/notifier.cpp @@ -35,8 +35,7 @@ Notifier *Notifier::get() // Constructor Notifier::Notifier(const std::string &icon_file, const std::string &text) - : renderer_(Screen::get()->getRenderer()), - icon_texture_(!icon_file.empty() ? Resource::get()->getTexture(icon_file) : nullptr), + : icon_texture_(!icon_file.empty() ? Resource::get()->getTexture(icon_file) : nullptr), text_(Resource::get()->getText(text)), bg_color_(options.notifications.color), wait_time_(150), @@ -84,8 +83,8 @@ void Notifier::update() // Comprueba los estados if (notifications_[i].state == NotificationStatus::RISING) { - //const float step = ((float)notifications_[i].counter / notifications_[i].travel_dist); - //const int alpha = 255 * step; + // const float step = ((float)notifications_[i].counter / notifications_[i].travel_dist); + // const int alpha = 255 * step; constexpr int ALPHA = 255; if (options.notifications.getVerticalPosition() == NotificationPosition::TOP) @@ -117,11 +116,10 @@ void Notifier::update() else if (notifications_[i].state == NotificationStatus::VANISHING) { - //const float step = (notifications_[i].counter / (float)notifications_[i].travel_dist); - //const int ALPHA = 255 * (1 - step); + // const float step = (notifications_[i].counter / (float)notifications_[i].travel_dist); + // const int ALPHA = 255 * (1 - step); constexpr int ALPHA = 255; - if (options.notifications.getVerticalPosition() == NotificationPosition::TOP) { notifications_[i].rect.y--; @@ -235,34 +233,34 @@ void Notifier::show(std::vector texts, NotificationText text_is, in n.rect = {desp_h, y_pos, width, height}; // Crea la textura - n.texture = std::make_shared(renderer_); + n.texture = std::make_shared(Screen::get()->getRenderer()); n.texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET); n.texture->setBlendMode(SDL_BLENDMODE_BLEND); // Prepara para dibujar en la textura - n.texture->setAsRenderTarget(renderer_); + n.texture->setAsRenderTarget(Screen::get()->getRenderer()); // Dibuja el fondo de la notificación - SDL_SetRenderDrawColor(renderer_, bg_color_.r, bg_color_.g, bg_color_.b, 255); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), bg_color_.r, bg_color_.g, bg_color_.b, 255); SDL_Rect rect; if (shape == NotificationShape::ROUNDED) { rect = {4, 0, width - (4 * 2), height}; - SDL_RenderFillRect(renderer_, &rect); + SDL_RenderFillRect(Screen::get()->getRenderer(), &rect); rect = {4 / 2, 1, width - 4, height - 2}; - SDL_RenderFillRect(renderer_, &rect); + SDL_RenderFillRect(Screen::get()->getRenderer(), &rect); rect = {1, 4 / 2, width - 2, height - 4}; - SDL_RenderFillRect(renderer_, &rect); + SDL_RenderFillRect(Screen::get()->getRenderer(), &rect); rect = {0, 4, width, height - (4 * 2)}; - SDL_RenderFillRect(renderer_, &rect); + SDL_RenderFillRect(Screen::get()->getRenderer(), &rect); } else if (shape == NotificationShape::SQUARED) { - SDL_RenderClear(renderer_); + SDL_RenderClear(Screen::get()->getRenderer()); } // Dibuja el icono de la notificación @@ -291,7 +289,7 @@ void Notifier::show(std::vector texts, NotificationText text_is, in } // Deja de dibujar en la textura - SDL_SetRenderTarget(renderer_, nullptr); + SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr); // Crea el sprite de la notificación n.sprite = std::make_shared(n.texture, n.rect); diff --git a/source/notifier.h b/source/notifier.h index 0975400..0a03003 100644 --- a/source/notifier.h +++ b/source/notifier.h @@ -62,9 +62,6 @@ private: can_be_removed(true), height(0) {} }; - // Objetos y punteros - SDL_Renderer *renderer_; // El renderizador de la ventana - std::shared_ptr icon_texture_; // Textura para los iconos de las notificaciones std::shared_ptr text_; // Objeto para dibujar texto diff --git a/source/player.cpp b/source/player.cpp index 0bb390b..c1aa844 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -17,11 +17,7 @@ // Constructor Player::Player(const PlayerData &player) - : renderer_(Screen::get()->getRenderer()), - input_(Input::get()), - asset_(Asset::get()), - debug_(Debug::get()), - room_(player.room) + : room_(player.room) { // Inicializa algunas variables initSprite(player.texture_path, player.animations_path); @@ -82,13 +78,13 @@ void Player::checkInput() if (!auto_movement_) { // Comprueba las entradas de desplazamiento lateral solo en el caso de no estar enganchado a una superficie automatica - if (input_->checkInput(InputAction::LEFT)) + if (Input::get()->checkInput(InputAction::LEFT)) { vx_ = -0.6f; sprite_->setFlip(SDL_FLIP_HORIZONTAL); } - else if (input_->checkInput(InputAction::RIGHT)) + else if (Input::get()->checkInput(InputAction::RIGHT)) { vx_ = 0.6f; sprite_->setFlip(SDL_FLIP_NONE); @@ -119,7 +115,7 @@ void Player::checkInput() } } - if (input_->checkInput(InputAction::JUMP)) + if (Input::get()->checkInput(InputAction::JUMP)) { // Solo puede saltar si ademas de estar (state == s_standing) // Esta sobre el suelo, rampa o suelo que se mueve @@ -469,8 +465,8 @@ void Player::move() collider_box_ = getRect(); // Actualiza el rectangulo de colisión #ifdef DEBUG - debug_->add("RECT_X: " + std::to_string(debug_rect_x_.x) + "," + std::to_string(debug_rect_x_.y) + "," + std::to_string(debug_rect_x_.w) + "," + std::to_string(debug_rect_x_.h)); - debug_->add("RECT_Y: " + std::to_string(debug_rect_y_.x) + "," + std::to_string(debug_rect_y_.y) + "," + std::to_string(debug_rect_y_.w) + "," + std::to_string(debug_rect_y_.h)); + Debug::get()->add("RECT_X: " + std::to_string(debug_rect_x_.x) + "," + std::to_string(debug_rect_x_.y) + "," + std::to_string(debug_rect_x_.w) + "," + std::to_string(debug_rect_x_.h)); + Debug::get()->add("RECT_Y: " + std::to_string(debug_rect_y_.x) + "," + std::to_string(debug_rect_y_.y) + "," + std::to_string(debug_rect_y_.w) + "," + std::to_string(debug_rect_y_.h)); #endif } @@ -510,7 +506,7 @@ void Player::playJumpSound() } #ifdef DEBUG - debug_->add("JUMP: " + std::to_string(jumping_counter_ / 4)); + Debug::get()->add("JUMP: " + std::to_string(jumping_counter_ / 4)); #endif } @@ -523,7 +519,7 @@ void Player::playFallSound() } #ifdef DEBUG - debug_->add("FALL: " + std::to_string(falling_counter_ / 4)); + Debug::get()->add("FALL: " + std::to_string(falling_counter_ / 4)); #endif } @@ -550,17 +546,17 @@ bool Player::isOnFloor() #ifdef DEBUG if (onFloor) { - debug_->add("ON_FLOOR"); + Debug::get()->add("ON_FLOOR"); } if (onSlopeL) { - debug_->add("ON_SLOPE_L: " + std::to_string(under_feet_[0].x) + "," + std::to_string(under_feet_[0].y)); + Debug::get()->add("ON_SLOPE_L: " + std::to_string(under_feet_[0].x) + "," + std::to_string(under_feet_[0].y)); } if (onSlopeR) { - debug_->add("ON_SLOPE_R: " + std::to_string(under_feet_[1].x) + "," + std::to_string(under_feet_[1].y)); + Debug::get()->add("ON_SLOPE_R: " + std::to_string(under_feet_[1].x) + "," + std::to_string(under_feet_[1].y)); } #endif @@ -583,7 +579,7 @@ bool Player::isOnAutoSurface() #ifdef DEBUG if (onAutoSurface) { - debug_->add("ON_AUTO_SURFACE"); + Debug::get()->add("ON_AUTO_SURFACE"); } #endif @@ -609,7 +605,7 @@ bool Player::isOnDownSlope() #ifdef DEBUG if (onSlope) { - debug_->add("ON_DOWN_SLOPE"); + Debug::get()->add("ON_DOWN_SLOPE"); } #endif @@ -744,34 +740,36 @@ void Player::initSprite(const std::string &texture_path, const std::string &anim // Pinta la información de debug del jugador void Player::renderDebugInfo() { - if (debug_->getEnabled()) + if (Debug::get()->getEnabled()) { + auto renderer = Screen::get()->getRenderer(); + // Pinta los underfeet - SDL_SetRenderDrawColor(renderer_, 255, 0, 255, 255); - SDL_RenderDrawPoint(renderer_, under_feet_[0].x, under_feet_[0].y); - SDL_RenderDrawPoint(renderer_, under_feet_[1].x, under_feet_[1].y); + SDL_SetRenderDrawColor(renderer, 255, 0, 255, 255); + SDL_RenderDrawPoint(renderer, under_feet_[0].x, under_feet_[0].y); + SDL_RenderDrawPoint(renderer, under_feet_[1].x, under_feet_[1].y); // Pinta rectangulo del jugador - SDL_SetRenderDrawColor(renderer_, debug_color_.r, debug_color_.g, debug_color_.b, 192); + SDL_SetRenderDrawColor(renderer, debug_color_.r, debug_color_.g, debug_color_.b, 192); SDL_Rect rect = getRect(); - SDL_RenderFillRect(renderer_, &rect); - SDL_SetRenderDrawColor(renderer_, 0, 255, 255, 255); - SDL_RenderDrawRect(renderer_, &rect); + SDL_RenderFillRect(renderer, &rect); + SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255); + SDL_RenderDrawRect(renderer, &rect); // Pinta el rectangulo de movimiento - SDL_SetRenderDrawColor(renderer_, 255, 0, 0, 255); + SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); if (vx_ != 0.0f) { - SDL_RenderFillRect(renderer_, &debug_rect_x_); + SDL_RenderFillRect(renderer, &debug_rect_x_); } if (vy_ != 0.0f) { - SDL_RenderFillRect(renderer_, &debug_rect_y_); + SDL_RenderFillRect(renderer, &debug_rect_y_); } // Pinta el punto de debug - SDL_SetRenderDrawColor(renderer_, rand() % 256, rand() % 256, rand() % 256, 255); - SDL_RenderDrawPoint(renderer_, debug_point_.x, debug_point_.y); + SDL_SetRenderDrawColor(renderer, rand() % 256, rand() % 256, rand() % 256, 255); + SDL_RenderDrawPoint(renderer, debug_point_.x, debug_point_.y); } } #endif \ No newline at end of file diff --git a/source/player.h b/source/player.h index 6d0e31b..c142a91 100644 --- a/source/player.h +++ b/source/player.h @@ -63,10 +63,6 @@ public: static constexpr float MAX_VY_ = 1.2f; // Velocidad máxima que puede alcanzar al desplazarse en vertical // Objetos y punteros - SDL_Renderer *renderer_; // El renderizador de la ventana - Input *input_; // Objeto para gestionar la entrada - Asset *asset_; // Objeto con la ruta a todos los ficheros de recursos - Debug *debug_; // Objeto para gestionar la información de debug std::shared_ptr room_; // Objeto encargado de gestionar cada habitación del juego std::shared_ptr sprite_; // Sprite del jugador diff --git a/source/room.cpp b/source/room.cpp index a56c242..bb725c2 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -399,11 +399,7 @@ bool setItem(ItemData *item, const std::string &key, const std::string &value) // Constructor Room::Room(const std::string &room_path, std::shared_ptr data) - : screen_(Screen::get()), - renderer_(Screen::get()->getRenderer()), - asset_(Asset::get()), - debug_(Debug::get()), - data_(data) + : data_(data) { auto room = Resource::get()->getRoom(room_path); number_ = room->number; @@ -468,7 +464,7 @@ Room::Room(const std::string &room_path, std::shared_ptr data) setAnimatedTiles(); // Crea la textura para el mapa de tiles de la habitación - map_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT); + map_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT); if (map_texture_ == nullptr) { if (options.console) @@ -482,7 +478,7 @@ Room::Room(const std::string &room_path, std::shared_ptr data) fillMapTexture(); // Establece el color del borde - screen_->setBorderColor(stringToColor(options.video.palette, room->border_color)); + Screen::get()->setBorderColor(stringToColor(options.video.palette, room->border_color)); } // Destructor @@ -514,9 +510,9 @@ Color Room::getBorderColor() void Room::fillMapTexture() { const Color color = stringToColor(options.video.palette, bg_color_); - SDL_SetRenderTarget(renderer_, map_texture_); - SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); - SDL_RenderClear(renderer_); + SDL_SetRenderTarget(Screen::get()->getRenderer(), map_texture_); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF); + SDL_RenderClear(Screen::get()->getRenderer()); // Los tileSetFiles son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo @@ -538,14 +534,14 @@ void Room::fillMapTexture() texture_->render(x * TILE_SIZE_, y * TILE_SIZE_, &clip); #ifdef DEBUG - if (debug_->getEnabled()) + if (Debug::get()->getEnabled()) { if (clip.x != -TILE_SIZE_) { clip.x = x * TILE_SIZE_; clip.y = y * TILE_SIZE_; - SDL_SetRenderDrawColor(renderer_, 64, 64, 64, 224); - SDL_RenderFillRect(renderer_, &clip); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 64, 64, 64, 224); + SDL_RenderFillRect(Screen::get()->getRenderer(), &clip); } } #endif @@ -553,16 +549,16 @@ void Room::fillMapTexture() } #ifdef DEBUG - if (debug_->getEnabled()) + if (Debug::get()->getEnabled()) { // BottomSurfaces if (true) { for (auto l : bottom_surfaces_) { - SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); - SDL_SetRenderDrawColor(renderer_, 255, 0, 0, 0xFF); - SDL_RenderDrawLine(renderer_, l.x1, l.y, l.x2, l.y); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 255, 0, 0, 0xFF); + SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x1, l.y, l.x2, l.y); } } @@ -571,9 +567,9 @@ void Room::fillMapTexture() { for (auto l : top_surfaces_) { - SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); - SDL_SetRenderDrawColor(renderer_, 0, 255, 0, 0xFF); - SDL_RenderDrawLine(renderer_, l.x1, l.y, l.x2, l.y); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 255, 0, 0xFF); + SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x1, l.y, l.x2, l.y); } } @@ -582,9 +578,9 @@ void Room::fillMapTexture() { for (auto l : left_surfaces_) { - SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); - SDL_SetRenderDrawColor(renderer_, 128, 128, 255, 0xFF); - SDL_RenderDrawLine(renderer_, l.x, l.y1, l.x, l.y2); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 128, 128, 255, 0xFF); + SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x, l.y1, l.x, l.y2); } } @@ -593,9 +589,9 @@ void Room::fillMapTexture() { for (auto l : right_surfaces_) { - SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); - SDL_SetRenderDrawColor(renderer_, 255, 255, 0, 0xFF); - SDL_RenderDrawLine(renderer_, l.x, l.y1, l.x, l.y2); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 255, 255, 0, 0xFF); + SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x, l.y1, l.x, l.y2); } } @@ -604,9 +600,9 @@ void Room::fillMapTexture() { for (auto l : left_slopes_) { - SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); - SDL_SetRenderDrawColor(renderer_, 0, 255, 255, 0xFF); - SDL_RenderDrawLine(renderer_, l.x1, l.y1, l.x2, l.y2); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 255, 255, 0xFF); + SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x1, l.y1, l.x2, l.y2); } } @@ -615,9 +611,9 @@ void Room::fillMapTexture() { for (auto l : right_slopes_) { - SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); - SDL_SetRenderDrawColor(renderer_, 255, 0, 255, 0xFF); - SDL_RenderDrawLine(renderer_, l.x1, l.y1, l.x2, l.y2); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 255, 0, 255, 0xFF); + SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x1, l.y1, l.x2, l.y2); } } @@ -626,14 +622,14 @@ void Room::fillMapTexture() { for (auto l : auto_surfaces_) { - SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); - SDL_RenderDrawLine(renderer_, l.x1, l.y, l.x2, l.y); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF); + SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x1, l.y, l.x2, l.y); } } } #endif - SDL_SetRenderTarget(renderer_, nullptr); + SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr); } // Dibuja el mapa en pantalla @@ -641,11 +637,11 @@ void Room::renderMap() { // Dibuja la textura con el mapa en pantalla SDL_Rect dest = {0, 0, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT}; - SDL_RenderCopy(renderer_, map_texture_, nullptr, &dest); + SDL_RenderCopy(Screen::get()->getRenderer(), map_texture_, nullptr, &dest); // Dibuja los tiles animados #ifdef DEBUG - if (!debug_->getEnabled()) + if (!Debug::get()->getEnabled()) { renderAnimatedTiles(); } @@ -811,73 +807,19 @@ bool Room::itemCollision(SDL_Rect &rect) return false; } -// Recarga la textura -void Room::reLoadTexture() -{ - texture_->reLoad(); - fillMapTexture(); - - for (auto enemy : enemies_) - { - enemy->reLoadTexture(); - } - - for (auto item : items_) - { - item->reLoadTexture(); - } -} - -// Recarga la paleta -void Room::reLoadPalette() -{ - // Cambia el color de los items - for (auto item : items_) - { - item->setColors(stringToColor(options.video.palette, item_color1_), stringToColor(options.video.palette, item_color2_)); - } - - // Cambia el color de los enemigos - for (auto enemy : enemies_) - { - enemy->setPalette(options.video.palette); - } - - // Establece el color del borde - screen_->setBorderColor(stringToColor(options.video.palette, border_color_)); - - // Cambia la textura - // texture_ = (options.video.palette == Palette::ZXSPECTRUM) ? Resource::get()->getTexture(room->tile_set_file) : Resource::get()->getTexture(room->tile_set_file); - - // Pone la nueva textura a los tiles animados - for (auto tile : animated_tiles_) - { - tile.sprite->setTexture(texture_); - } - - // Recarga las texturas - reLoadTexture(); -} - -// Obten el tamaño del tile -int Room::getTileSize() -{ - return TILE_SIZE_; -} - // Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile int Room::getSlopeHeight(SDL_Point p, tile_e slope) { // Calcula la base del tile int base = ((p.y / TILE_SIZE_) * TILE_SIZE_) + TILE_SIZE_; #ifdef DEBUG - debug_->add("BASE = " + std::to_string(base)); + Debug::get()->add("BASE = " + std::to_string(base)); #endif // Calcula cuanto se ha entrado en el tile horizontalmente const int pos = (p.x % TILE_SIZE_); // Esto da un valor entre 0 y 7 #ifdef DEBUG - debug_->add("POS = " + std::to_string(pos)); + Debug::get()->add("POS = " + std::to_string(pos)); #endif // Se resta a la base la cantidad de pixeles pos en funcion de la rampa @@ -885,14 +827,14 @@ int Room::getSlopeHeight(SDL_Point p, tile_e slope) { base -= pos + 1; #ifdef DEBUG - debug_->add("BASE_R = " + std::to_string(base)); + Debug::get()->add("BASE_R = " + std::to_string(base)); #endif } else { base -= (TILE_SIZE_ - pos); #ifdef DEBUG - debug_->add("BASE_L = " + std::to_string(base)); + Debug::get()->add("BASE_L = " + std::to_string(base)); #endif } diff --git a/source/room.h b/source/room.h index 3e2a046..cae5d18 100644 --- a/source/room.h +++ b/source/room.h @@ -78,10 +78,6 @@ private: static constexpr int MAP_HEIGHT_ = 16; // Alto del mapa en tiles // Objetos y punteros - Screen *screen_; // Objeto encargado de dibujar en pantalla - SDL_Renderer *renderer_; // El renderizador de la ventana - Asset *asset_; // Objeto con la ruta a todos los ficheros de recursos - Debug *debug_; // Objeto para gestionar la información de debug std::vector> enemies_; // Listado con los enemigos de la habitación std::vector> items_; // Listado con los items que hay en la habitación std::shared_ptr texture_; // Textura con los graficos de la habitación @@ -195,14 +191,8 @@ public: // Indica si hay colision con un objeto a partir de un rectangulo bool itemCollision(SDL_Rect &rect); - // Recarga la textura - void reLoadTexture(); - - // Recarga la paleta - void reLoadPalette(); - // Obten el tamaño del tile - int getTileSize(); + int getTileSize() const { return TILE_SIZE_; } // Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile int getSlopeHeight(SDL_Point p, tile_e slope); diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index 3c6f946..9eea1f2 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -13,24 +13,20 @@ // Constructor Scoreboard::Scoreboard(std::shared_ptr data) - : renderer_(Screen::get()->getRenderer()), - resource_(Resource::get()), - asset_(Asset::get()), - data_(data), + : data_(data), clock_(ClockData()) { const int TEXTURE_WIDTH_ = options.game.width; constexpr int TEXTURE_HEIGHT_ = 6 * BLOCK; // Reserva memoria para los objetos - item_texture_ = resource_->getTexture("items.png"); - auto player_texture = resource_->getTexture(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png"); - auto player_animations = resource_->getAnimations(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani"); + item_texture_ = Resource::get()->getTexture("items.png"); + auto player_texture = Resource::get()->getTexture(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png"); + auto player_animations = Resource::get()->getAnimations(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani"); player_sprite_ = std::make_shared(player_texture, player_animations); player_sprite_->setCurrentAnimation("walk_menu"); - text_ = resource_->getText("smb2"); - texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, TEXTURE_WIDTH_, TEXTURE_HEIGHT_); + texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, TEXTURE_WIDTH_, TEXTURE_HEIGHT_); if (texture_ == nullptr) { if (options.console) @@ -65,7 +61,7 @@ Scoreboard::~Scoreboard() // Pinta el objeto en pantalla void Scoreboard::render() { - SDL_RenderCopy(renderer_, texture_, nullptr, &texture_dest_); + SDL_RenderCopy(Screen::get()->getRenderer(), texture_, nullptr, &texture_dest_); } // Actualiza las variables del objeto @@ -152,12 +148,12 @@ int Scoreboard::getMinutes() void Scoreboard::fillTexture() { // Empieza a dibujar en la textura - auto temp = SDL_GetRenderTarget(renderer_); - SDL_SetRenderTarget(renderer_, texture_); + auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer()); + SDL_SetRenderTarget(Screen::get()->getRenderer(), texture_); // Limpia la textura - SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 255); - SDL_RenderFillRect(renderer_, nullptr); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 255); + SDL_RenderFillRect(Screen::get()->getRenderer(), nullptr); // Anclas constexpr int LINE1 = BLOCK; @@ -186,17 +182,18 @@ void Scoreboard::fillTexture() } // Escribe los textos - const std::string timeTxt = std::to_string((clock_.minutes % 100) / 10) + std::to_string(clock_.minutes % 10) + clock_.separator + std::to_string((clock_.seconds % 60) / 10) + std::to_string(clock_.seconds % 10); - const std::string itemsTxt = std::to_string(data_->items / 100) + std::to_string((data_->items % 100) / 10) + std::to_string(data_->items % 10); - text_->writeColored(BLOCK, LINE1, "Items collected ", data_->color); - text_->writeColored(17 * BLOCK, LINE1, itemsTxt, items_color_); - text_->writeColored(20 * BLOCK, LINE1, " Time ", data_->color); - text_->writeColored(26 * BLOCK, LINE1, timeTxt, stringToColor(options.video.palette, "white")); + auto text = Resource::get()->getText("smb2"); + const std::string TIME_TEXT = std::to_string((clock_.minutes % 100) / 10) + std::to_string(clock_.minutes % 10) + clock_.separator + std::to_string((clock_.seconds % 60) / 10) + std::to_string(clock_.seconds % 10); + const std::string ITEMS_TEXT = std::to_string(data_->items / 100) + std::to_string((data_->items % 100) / 10) + std::to_string(data_->items % 10); + text->writeColored(BLOCK, LINE1, "Items collected ", data_->color); + text->writeColored(17 * BLOCK, LINE1, ITEMS_TEXT, items_color_); + text->writeColored(20 * BLOCK, LINE1, " Time ", data_->color); + text->writeColored(26 * BLOCK, LINE1, TIME_TEXT, stringToColor(options.video.palette, "white")); - const std::string roomsTxt = std::to_string(data_->rooms / 100) + std::to_string((data_->rooms % 100) / 10) + std::to_string(data_->rooms % 10); - text_->writeColored(22 * BLOCK, LINE2, "Rooms", stringToColor(options.video.palette, "white")); - text_->writeColored(28 * BLOCK, LINE2, roomsTxt, stringToColor(options.video.palette, "white")); + const std::string ROOMS_TEXT = std::to_string(data_->rooms / 100) + std::to_string((data_->rooms % 100) / 10) + std::to_string(data_->rooms % 10); + text->writeColored(22 * BLOCK, LINE2, "Rooms", stringToColor(options.video.palette, "white")); + text->writeColored(28 * BLOCK, LINE2, ROOMS_TEXT, stringToColor(options.video.palette, "white")); // Deja el renderizador como estaba - SDL_SetRenderTarget(renderer_, temp); + SDL_SetRenderTarget(Screen::get()->getRenderer(), temp); } \ No newline at end of file diff --git a/source/scoreboard.h b/source/scoreboard.h index 68972e3..772a733 100644 --- a/source/scoreboard.h +++ b/source/scoreboard.h @@ -51,10 +51,6 @@ private: }; // Objetos y punteros - SDL_Renderer *renderer_; // El renderizador de la ventana - Resource *resource_; // Objeto con los recursos - Asset *asset_; // Objeto con la ruta a todos los ficheros de recursos - std::shared_ptr text_; // Objeto para escribir texto std::shared_ptr player_sprite_; // Sprite para mostrar las vidas en el marcador std::shared_ptr item_texture_; // Textura con los graficos para las vidas std::shared_ptr data_; // Contiene las variables a mostrar en el marcador diff --git a/source/stats.cpp b/source/stats.cpp index c98e218..de7a9ff 100644 --- a/source/stats.cpp +++ b/source/stats.cpp @@ -50,7 +50,7 @@ void Stats::addDeath(const std::string &name) // En caso contrario crea la entrada else { - stats_t item; + StatsData item; item.name = name; item.visited = 0; item.died = 1; @@ -71,7 +71,7 @@ void Stats::addVisit(const std::string &name) // En caso contrario crea la entrada else { - stats_t item; + StatsData item; item.name = name; item.visited = 1; item.died = 0; @@ -80,7 +80,7 @@ void Stats::addVisit(const std::string &name) } // Busca una entrada en la lista por nombre -int Stats::findByName(const std::string &name, const std::vector &list) +int Stats::findByName(const std::string &name, const std::vector &list) { int i = 0; @@ -97,7 +97,7 @@ int Stats::findByName(const std::string &name, const std::vector &list) } // Carga las estadisticas desde un fichero -bool Stats::loadFromFile(const std::string &file_path, std::vector &list) +bool Stats::loadFromFile(const std::string &file_path, std::vector &list) { list.clear(); @@ -106,7 +106,7 @@ bool Stats::loadFromFile(const std::string &file_path, std::vector &lis // Variables para manejar el fichero std::ifstream file(file_path); - + // Si el fichero se puede abrir if (file.good()) { @@ -117,7 +117,7 @@ bool Stats::loadFromFile(const std::string &file_path, std::vector &lis // Comprueba que la linea no sea un comentario if (line.substr(0, 1) != "#") { - stats_t stat; + StatsData stat; std::stringstream ss(line); std::string tmp; @@ -152,7 +152,7 @@ bool Stats::loadFromFile(const std::string &file_path, std::vector &lis } // Guarda las estadisticas en un fichero -void Stats::saveToFile(const std::string &file_path, const std::vector &list) +void Stats::saveToFile(const std::string &file_path, const std::vector &list) { // Crea y abre el fichero de texto std::ofstream file(file_path); @@ -203,7 +203,7 @@ void Stats::updateListFromBuffer() } else { // En caso contrario crea la entrada - stats_t item; + StatsData item; item.name = buffer.name; item.visited = buffer.visited; item.died = buffer.died; diff --git a/source/stats.h b/source/stats.h index 89ee414..bf670d3 100644 --- a/source/stats.h +++ b/source/stats.h @@ -1,39 +1,39 @@ #pragma once -#include // for string -#include // for vector +#include // for string +#include // for vector class Stats { private: - struct stats_t + struct StatsData { std::string name; // Nombre de la habitación int visited; // Cuenta las veces que se ha visitado una habitación int died; // Cuenta las veces que se ha muerto en una habitación }; - struct stats_dictionary_t + struct StatsDictionary { std::string number; // Numero de la habitación std::string name; // Nombre de la habitación }; // Variables - std::vector dictionary; // Lista con la equivalencia nombre-numero de habitacion - std::vector bufferList; // Lista con las estadisticas temporales por habitación - std::vector list; // Lista con las estadisticas completas por habitación + std::vector dictionary; // Lista con la equivalencia nombre-numero de habitacion + std::vector bufferList; // Lista con las estadisticas temporales por habitación + std::vector list; // Lista con las estadisticas completas por habitación std::string bufferPath; // Fichero con las estadísticas temporales std::string filePath; // Fichero con las estadísticas completas // Busca una entrada en la lista por nombre - int findByName(const std::string &name, const std::vector &list); + int findByName(const std::string &name, const std::vector &list); // Carga las estadisticas desde un fichero - bool loadFromFile(const std::string &filePath, std::vector &list); + bool loadFromFile(const std::string &filePath, std::vector &list); // Guarda las estadisticas en un fichero - void saveToFile(const std::string &filePath, const std::vector &list); + void saveToFile(const std::string &filePath, const std::vector &list); // Calcula cual es la habitación con más muertes void checkWorstNightmare(); @@ -50,7 +50,7 @@ public: // Inicializador // Se debe llamar a este procedimiento una vez se haya creado el diccionario numero-nombre - void init(); + void init(); // Añade una muerte a las estadisticas void addDeath(const std::string &name); diff --git a/source/title.cpp b/source/title.cpp index fa29f5b..c88b9a6 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -23,26 +23,11 @@ // Constructor Title::Title() - : screen_(Screen::get()), - renderer_(Screen::get()->getRenderer()), - resource_(Resource::get()), - input_(Input::get()) + : texture_(Resource::get()->getTexture("title_logo.png")), + sprite_(std::make_shared(texture_, 0, 0, texture_->getWidth(), texture_->getHeight())) { - // Reserva memoria para los punteros - if (options.video.palette == Palette::ZXSPECTRUM) - { - texture_ = resource_->getTexture("title_logo.png"); - } - else if (options.video.palette == Palette::ZXARNE) - { - texture_ = resource_->getTexture("title_logo.png"); - } - sprite_ = std::make_shared(texture_, 0, 0, texture_->getWidth(), texture_->getHeight()); - text_ = resource_->getText("smb2"); - info_text_ = resource_->getText("subatomic"); - // Crea la textura para los graficos que aparecen en el fondo de la pantalla de titulo - bg_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); + bg_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); if (bg_texture_ == nullptr) { if (options.console) @@ -53,7 +38,7 @@ Title::Title() SDL_SetTextureBlendMode(bg_texture_, SDL_BLENDMODE_BLEND); // Carga la surface con los gráficos de la pantalla de carga - pInit(renderer_, 256, 128); + pInit(Screen::get()->getRenderer(), 256, 128); loading_screen_ = pLoadSurface(Asset::get()->get("loading_screen_color.gif").c_str()); pLoadPal(Asset::get()->get("loading_screen_color.gif").c_str()); pSetSource(loading_screen_); @@ -68,7 +53,7 @@ Title::Title() createCheevosTexture(); // Cambia el color del borde - screen_->setBorderColor(stringToColor(options.video.palette, "black")); + Screen::get()->setBorderColor(stringToColor(options.video.palette, "black")); // Rellena la textura de fondo con todos los gráficos fillTexture(); @@ -137,22 +122,22 @@ void Title::checkInput() { if (show_cheevos_) { - if (input_->checkInput(InputAction::DOWN, REPEAT_TRUE)) + if (Input::get()->checkInput(InputAction::DOWN, REPEAT_TRUE)) { moveCheevosList(1); } - else if (input_->checkInput(InputAction::UP, REPEAT_TRUE)) + else if (Input::get()->checkInput(InputAction::UP, REPEAT_TRUE)) { moveCheevosList(0); } - else if (input_->checkInput(InputAction::ACCEPT, REPEAT_FALSE)) + else if (Input::get()->checkInput(InputAction::ACCEPT, REPEAT_FALSE)) { hideCheevosList(); counter_ = 0; } } - if (input_->checkInput(InputAction::ACCEPT, REPEAT_FALSE)) + if (Input::get()->checkInput(InputAction::ACCEPT, REPEAT_FALSE)) { if (state_ == TitleState::SHOW_LOADING_SCREEN) { @@ -166,6 +151,8 @@ void Title::checkInput() // Actualiza la marquesina void Title::updateMarquee() { + const auto TEXT = Resource::get()->getText("smb2"); + for (int i = 0; i < (int)letters_.size(); ++i) { if (letters_[i].enabled) @@ -181,7 +168,7 @@ void Title::updateMarquee() if (i > 0 && letters_[i - 1].x < 256 && letters_[i - 1].enabled) { letters_[i].enabled = true; - letters_[i].x = letters_[i - 1].x + text_->lenght(letters_[i - 1].letter) + 1; + letters_[i].x = letters_[i - 1].x + TEXT->lenght(letters_[i - 1].letter) + 1; } } } @@ -196,11 +183,12 @@ void Title::updateMarquee() // Dibuja la marquesina void Title::renderMarquee() { + const auto TEXT = Resource::get()->getText("smb2"); for (const auto &l : letters_) { if (l.enabled) { - text_->writeColored(l.x, 184, l.letter, stringToColor(options.video.palette, "white")); + TEXT->writeColored(l.x, 184, l.letter, stringToColor(options.video.palette, "white")); } } } @@ -217,7 +205,7 @@ void Title::update() // Comprueba las entradas checkInput(); - screen_->update(); + Screen::get()->update(); // Incrementa el contador counter_++; @@ -268,13 +256,13 @@ void Title::update() void Title::render() { // Prepara para empezar a dibujar en la textura de juego - screen_->start(); - screen_->clean(stringToColor(options.video.palette, "black")); + Screen::get()->start(); + Screen::get()->clean(stringToColor(options.video.palette, "black")); if (state_ == TitleState::SHOW_MENU) { // Dibuja la textura de fondo - SDL_RenderCopy(renderer_, bg_texture_, nullptr, nullptr); + SDL_RenderCopy(Screen::get()->getRenderer(), bg_texture_, nullptr, nullptr); // Dibuja la marquesina renderMarquee(); @@ -290,14 +278,14 @@ void Title::render() // Dibuja la pantalla de carga pCls(4); pBlit(0, 0, 0, 0, 256, 128); - pFlip(renderer_); + pFlip(Screen::get()->getRenderer()); // Dibuja el logo del título sprite_->render(); } // Vuelca el contenido del renderizador en pantalla - screen_->render(); + Screen::get()->render(); } // Bucle para el logo del juego @@ -333,73 +321,77 @@ void Title::moveCheevosList(int direction) // Rellena la textura de fondo con todos los gráficos void Title::fillTexture() { + auto renderer = Screen::get()->getRenderer(); + // Coloca el puntero del renderizador sobre la textura - SDL_SetRenderTarget(renderer_, bg_texture_); + SDL_SetRenderTarget(renderer, bg_texture_); // Rellena la textura de color const Color c = stringToColor(options.video.palette, "black"); - SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF); - SDL_RenderClear(renderer_); + SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF); + SDL_RenderClear(renderer); // Pinta el gráfico del titulo a partir del sprite sprite_->render(); // Escribe el texto en la textura - const Color textColor = stringToColor(options.video.palette, "green"); - const int textSize = text_->getCharacterSize(); - text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 11 * textSize, "1.PLAY", 1, textColor); - text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 13 * textSize, "2.ACHIEVEMENTS", 1, textColor); - text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 15 * textSize, "3.REDEFINE KEYS", 1, textColor); - text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 20 * textSize, "ESC.EXIT GAME", 1, textColor); + auto text = Resource::get()->getText("smb2"); + const Color COLOR = stringToColor(options.video.palette, "green"); + const int TEXT_SIZE = text->getCharacterSize(); + text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 11 * TEXT_SIZE, "1.PLAY", 1, COLOR); + text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 13 * TEXT_SIZE, "2.ACHIEVEMENTS", 1, COLOR); + text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 15 * TEXT_SIZE, "3.REDEFINE KEYS", 1, COLOR); + text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 20 * TEXT_SIZE, "ESC.EXIT GAME", 1, COLOR); // Devuelve el puntero del renderizador a su sitio - SDL_SetRenderTarget(renderer_, nullptr); + SDL_SetRenderTarget(renderer, nullptr); } // Crea y rellena la textura para mostrar los logros void Title::createCheevosTexture() { // Crea la textura con el listado de logros - const auto cheevosList = Cheevos::get()->list(); + const auto CHEEVOS_LIST = Cheevos::get()->list(); + const auto TEXT = Resource::get()->getText("subatomic"); constexpr int CHEEVOS_TEXTURE_WIDTH = 200; constexpr int CHEEVOS_TEXTURE_VIEW_HEIGHT = 110; constexpr int CHEEVOS_TEXTURE_POS_Y = 73; constexpr int CHEEVOS_PADDING = 10; - const int CHEEVO_HEIGHT = CHEEVOS_PADDING + (info_text_->getCharacterSize() * 2) + 1; - const int CHEEVOS_TEXTURE_HEIGHT = (CHEEVO_HEIGHT * cheevosList.size()) + 2 + info_text_->getCharacterSize() + 8; - cheevos_texture_ = std::make_shared(renderer_); + const int CHEEVO_HEIGHT = CHEEVOS_PADDING + (TEXT->getCharacterSize() * 2) + 1; + const int CHEEVOS_TEXTURE_HEIGHT = (CHEEVO_HEIGHT * CHEEVOS_LIST.size()) + 2 + TEXT->getCharacterSize() + 8; + cheevos_texture_ = std::make_shared(Screen::get()->getRenderer()); cheevos_texture_->createBlank(CHEEVOS_TEXTURE_WIDTH, CHEEVOS_TEXTURE_HEIGHT, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET); - cheevos_texture_->setAsRenderTarget(renderer_); + cheevos_texture_->setAsRenderTarget(Screen::get()->getRenderer()); cheevos_texture_->setBlendMode(SDL_BLENDMODE_BLEND); // Rellena la textura con color sólido const Color CHEEVOS_BG_COLOR = stringToColor(options.video.palette, "black"); - SDL_SetRenderDrawColor(renderer_, CHEEVOS_BG_COLOR.r, CHEEVOS_BG_COLOR.g, CHEEVOS_BG_COLOR.b, 0xFF); - SDL_RenderClear(renderer_); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), CHEEVOS_BG_COLOR.r, CHEEVOS_BG_COLOR.g, CHEEVOS_BG_COLOR.b, 0xFF); + SDL_RenderClear(Screen::get()->getRenderer()); // Escribe la lista de logros en la textura const std::string CHEEVOS_OWNER = "ACHIEVEMENTS"; const std::string CHEEVOS_LIST_CAPTION = CHEEVOS_OWNER + " (" + std::to_string(Cheevos::get()->unlocked()) + " / " + std::to_string(Cheevos::get()->size()) + ")"; int pos = 2; - info_text_->writeDX(TEXT_CENTER | TEXT_COLOR, cheevos_texture_->getWidth() / 2, pos, CHEEVOS_LIST_CAPTION, 1, stringToColor(options.video.palette, "bright_green")); - pos += info_text_->getCharacterSize(); + TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, cheevos_texture_->getWidth() / 2, pos, CHEEVOS_LIST_CAPTION, 1, stringToColor(options.video.palette, "bright_green")); + pos += TEXT->getCharacterSize(); const Color CHEEVO_LOCKED_COLOR = stringToColor(options.video.palette, "white"); const Color CHEEVO_UNLOCKED_COLOR = stringToColor(options.video.palette, "bright_green"); Color cheevoColor; - SDL_SetRenderDrawColor(renderer_, CHEEVO_LOCKED_COLOR.r, CHEEVO_LOCKED_COLOR.g, CHEEVO_LOCKED_COLOR.b, 0xFF); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), CHEEVO_LOCKED_COLOR.r, CHEEVO_LOCKED_COLOR.g, CHEEVO_LOCKED_COLOR.b, 0xFF); constexpr int LINE_X1 = (CHEEVOS_TEXTURE_WIDTH / 7) * 3; constexpr int LINE_X2 = LINE_X1 + ((CHEEVOS_TEXTURE_WIDTH / 7) * 1); - for (const auto &cheevo : cheevosList) + for (const auto &cheevo : CHEEVOS_LIST) { cheevoColor = cheevo.completed ? CHEEVO_UNLOCKED_COLOR : CHEEVO_LOCKED_COLOR; pos += CHEEVOS_PADDING; constexpr int HALF = CHEEVOS_PADDING / 2; - SDL_RenderDrawLine(renderer_, LINE_X1, pos - HALF - 1, LINE_X2, pos - HALF - 1); - info_text_->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.caption, 1, cheevoColor); - pos += info_text_->getCharacterSize() + 1; - info_text_->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.description, 1, cheevoColor); - pos += info_text_->getCharacterSize(); + SDL_RenderDrawLine(Screen::get()->getRenderer(), LINE_X1, pos - HALF - 1, LINE_X2, pos - HALF - 1); + TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.caption, 1, cheevoColor); + pos += TEXT->getCharacterSize() + 1; + TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.description, 1, cheevoColor); + pos += TEXT->getCharacterSize(); } // Crea el sprite para el listado de logros diff --git a/source/title.h b/source/title.h index 0ecbf5e..3781f97 100644 --- a/source/title.h +++ b/source/title.h @@ -32,15 +32,9 @@ private: }; // Objetos y punteros - Screen *screen_; // Objeto encargado de dibujar en pantalla - SDL_Renderer *renderer_; // El renderizador de la ventana - Resource *resource_; // Objeto con los recursos - Input *input_; // Objeto pata gestionar la entrada std::shared_ptr texture_; // Textura con los graficos std::shared_ptr sprite_; // Sprite para manejar la textura SDL_Texture *bg_texture_; // Textura para dibujar el fondo de la pantalla - std::shared_ptr text_; // Objeto para escribir texto en pantalla - std::shared_ptr info_text_; // Objeto para escribir texto en pantalla std::shared_ptr cheevos_texture_; // Textura con la lista de logros std::shared_ptr cheevos_sprite_; // Sprite para manejar la textura con la lista de logros