diff --git a/source/credits.cpp b/source/credits.cpp index 44b5a75..9b09192 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -7,7 +7,7 @@ #include // for SDL_GetTicks #include // for min #include // for basic_ostream, operator<<, cout, endl -#include "animated_sprite.h" // for AnimatedSprite +#include "s_animated_sprite.h" // for AnimatedSprite #include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH #include "global_events.h" // for check #include "global_inputs.h" // for check @@ -18,7 +18,7 @@ // Constructor Credits::Credits() - : shining_sprite_(std::make_shared(Resource::get()->getTexture("shine.png"), Resource::get()->getAnimations("shine.ani"))) + : shining_sprite_(std::make_shared(Resource::get()->getSurface("shine.gif"), Resource::get()->getAnimations("shine.ani"))) { // Inicializa variables options.section.section = Section::CREDITS; diff --git a/source/ending.cpp b/source/ending.cpp index b89e193..09c89fc 100644 --- a/source/ending.cpp +++ b/source/ending.cpp @@ -14,9 +14,9 @@ #include "options.h" // for Options, options, OptionsVideo, Sect... #include "resource.h" // for Resource #include "screen.h" // for Screen -#include "sprite.h" // for Sprite +#include "s_sprite.h" // for Sprite #include "text.h" // for Text, TEXT_STROKE -#include "texture.h" // for Texture +#include "surface.h" // for Texture #include "utils.h" // for Color, stringToColor, Palette // Constructor @@ -240,19 +240,19 @@ void Ending::iniPics() if (options.video.palette == Palette::ZXSPECTRUM) { - pics.push_back({"ending1.png", 48}); - pics.push_back({"ending2.png", 26}); - pics.push_back({"ending3.png", 29}); - pics.push_back({"ending4.png", 63}); - pics.push_back({"ending5.png", 53}); + pics.push_back({"ending1.gif", 48}); + pics.push_back({"ending2.gif", 26}); + pics.push_back({"ending3.gif", 29}); + pics.push_back({"ending4.gif", 63}); + pics.push_back({"ending5.gif", 53}); } else { - pics.push_back({"ending1_zxarne.png", 48}); - pics.push_back({"ending2_zxarne.png", 26}); - pics.push_back({"ending3_zxarne.png", 29}); - pics.push_back({"ending4_zxarne.png", 63}); - pics.push_back({"ending5_zxarne.png", 53}); + pics.push_back({"ending1_zxarne.gif", 48}); + pics.push_back({"ending2_zxarne.gif", 26}); + pics.push_back({"ending3_zxarne.gif", 29}); + pics.push_back({"ending4_zxarne.gif", 63}); + pics.push_back({"ending5_zxarne.gif", 53}); } // Crea los sprites @@ -263,7 +263,7 @@ void Ending::iniPics() EndingTexture sp; // Crea la texture - sp.image_texture = Resource::get()->getTexture(pic.caption); + sp.image_texture = Resource::get()->getSurface(pic.caption); const int WIDTH = sp.image_texture->getWidth(); const int HEIGHT = sp.image_texture->getHeight(); diff --git a/source/ending2.cpp b/source/ending2.cpp index aa58066..8d6fafb 100644 --- a/source/ending2.cpp +++ b/source/ending2.cpp @@ -1,22 +1,22 @@ #include "ending2.h" -#include // for SDL_BLENDMODE_BLEND -#include // for SDL_PollEvent, SDL_Event -#include // for SDL_Rect -#include // for SDL_RenderDrawPoint, SDL_SetRenderDr... -#include // for SDL_GetTicks -#include // for max, min, replace -#include "animated_sprite.h" // for AnimatedSprite -#include "defines.h" // for options.game.height, GAMECANVAS_CENTER_X -#include "global_events.h" // for check -#include "global_inputs.h" // for check -#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM... -#include "moving_sprite.h" // for MovingSprite -#include "options.h" // for Options, options, OptionsVideo, Sect... -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "text.h" // for Text -#include "texture.h" // for Texture -#include "utils.h" // for Color, stringToColor +#include // for SDL_BLENDMODE_BLEND +#include // for SDL_PollEvent, SDL_Event +#include // for SDL_Rect +#include // for SDL_RenderDrawPoint, SDL_SetRenderDr... +#include // for SDL_GetTicks +#include // for max, min, replace +#include "s_animated_sprite.h" // for AnimatedSprite +#include "defines.h" // for options.game.height, GAMECANVAS_CENTER_X +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM... +#include "s_moving_sprite.h" // for MovingSprite +#include "options.h" // for Options, options, OptionsVideo, Sect... +#include "resource.h" // for Resource +#include "screen.h" // for Screen +#include "text.h" // for Text +#include "surface.h" // for Texture +#include "utils.h" // for Color, stringToColor #include // Constructor @@ -282,7 +282,7 @@ void Ending2::loadSprites() // Carga los sprites for (const auto &file : sprite_list_) { - sprites_.emplace_back(std::make_shared(Resource::get()->getTexture(file + ".png"), Resource::get()->getAnimations(file + ".ani"))); + sprites_.emplace_back(std::make_shared(Resource::get()->getSurface(file + ".gif"), Resource::get()->getAnimations(file + ".ani"))); sprite_max_width_ = std::max(sprites_.back()->getWidth(), sprite_max_width_); sprite_max_height_ = std::max(sprites_.back()->getHeight(), sprite_max_height_); } diff --git a/source/enemy.cpp b/source/enemy.cpp index 9ae5af4..20ac9a9 100644 --- a/source/enemy.cpp +++ b/source/enemy.cpp @@ -1,14 +1,14 @@ #include "enemy.h" -#include // for SDL_RendererFlip, SDL_FLIP_NONE, SDL_FL... -#include // for rand -#include "animated_sprite.h" // for AnimatedSprite -#include "options.h" // for Options, OptionsVideo, options -#include "resource.h" // for Resource -#include "texture.h" // for Texture +#include // for SDL_RendererFlip, SDL_FLIP_NONE, SDL_FL... +#include // for rand +#include "s_animated_sprite.h" // for AnimatedSprite +#include "options.h" // for Options, OptionsVideo, options +#include "resource.h" // for Resource +#include "surface.h" // for Texture // Constructor Enemy::Enemy(const EnemyData &enemy) - : sprite_(std::make_shared(Resource::get()->getTexture(enemy.texture_path), Resource::get()->getAnimations(enemy.animation_path))), + : sprite_(std::make_shared(Resource::get()->getSurface(enemy.texture_path), Resource::get()->getAnimations(enemy.animation_path))), color_string_(enemy.color), x1_(enemy.x1), x2_(enemy.x2), diff --git a/source/game.cpp b/source/game.cpp index 5882af4..0528a3e 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -653,7 +653,7 @@ void Game::checkEndGameCheevos() // Inicializa al jugador void Game::initPlayer(const PlayerSpawn &spawn_point, std::shared_ptr room) { - std::string player_texture = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png"; + std::string player_texture = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.gif" : "player.gif"; std::string player_animations = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani"; const PlayerData player(spawn_point, player_texture, player_animations, room); player_ = std::make_shared(player); diff --git a/source/game_over.cpp b/source/game_over.cpp index 7959db2..2336861 100644 --- a/source/game_over.cpp +++ b/source/game_over.cpp @@ -1,30 +1,30 @@ #include "game_over.h" -#include // for SDL_PollEvent, SDL_Event -#include // for SDL_GetTicks -#include // for min, max -#include // for basic_string, operator+, to_string, cha... -#include "animated_sprite.h" // for AnimatedSprite -#include "defines.h" // for GAMECANVAS_CENTER_X, GAME_SPEED -#include "global_events.h" // for check -#include "global_inputs.h" // for check -#include "jail_audio.h" // for JA_PlayMusic -#include "options.h" // for Options, options, OptionsStats, Section... -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "text.h" // for TEXT_CENTER, TEXT_COLOR, Text -#include "texture.h" // for Texture +#include // for SDL_PollEvent, SDL_Event +#include // for SDL_GetTicks +#include // for min, max +#include // for basic_string, operator+, to_string, cha... +#include "s_animated_sprite.h" // for AnimatedSprite +#include "defines.h" // for GAMECANVAS_CENTER_X, GAME_SPEED +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#include "jail_audio.h" // for JA_PlayMusic +#include "options.h" // for Options, options, OptionsStats, Section... +#include "resource.h" // for Resource +#include "screen.h" // for Screen +#include "text.h" // for TEXT_CENTER, TEXT_COLOR, Text +#include "surface.h" // for Texture // Constructor GameOver::GameOver() - : 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"))), + : player_sprite_(std::make_shared(Resource::get()->getSurface("player_game_over.gif"), Resource::get()->getAnimations("player_game_over.ani"))), + tv_sprite_(std::make_shared(Resource::get()->getSurface("tv.gif"), Resource::get()->getAnimations("tv.ani"))), pre_counter_(0), counter_(0), ticks_(0) { options.section.section = Section::GAME_OVER; options.section.subsection = Subsection::NONE; - + player_sprite_->setPosX(GAMECANVAS_CENTER_X + 10); player_sprite_->setPosY(30); tv_sprite_->setPosX(GAMECANVAS_CENTER_X - tv_sprite_->getWidth() - 10); diff --git a/source/item.cpp b/source/item.cpp index 5d8c21b..a070427 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -1,11 +1,11 @@ #include "item.h" #include "resource.h" -#include "sprite.h" // Para Sprite -#include "texture.h" // Para Texture +#include "s_sprite.h" // Para Sprite +#include "surface.h" // Para Texture // Constructor Item::Item(ItemData item) - : sprite_(std::make_shared(Resource::get()->getTexture(item.tile_set_file), item.x, item.y, ITEM_SIZE_, ITEM_SIZE_)), + : sprite_(std::make_shared(Resource::get()->getSurface(item.tile_set_file), item.x, item.y, ITEM_SIZE_, ITEM_SIZE_)), change_color_speed(4) { // Inicia variables diff --git a/source/item.h b/source/item.h index 723e103..3cf2d04 100644 --- a/source/item.h +++ b/source/item.h @@ -1,12 +1,12 @@ #pragma once -#include // for SDL_Rect, SDL_Point -#include // for shared_ptr, __shared_ptr_access -#include // for string -#include // for vector -#include "sprite.h" // for Sprite -#include "texture.h" // for Texture -#include "utils.h" // for Color +#include // for SDL_Rect, SDL_Point +#include // for shared_ptr, __shared_ptr_access +#include // for string +#include // for vector +#include "s_sprite.h" // for Sprite +#include "surface.h" // for Texture +#include "utils.h" // for Color struct ItemData { diff --git a/source/loading_screen.cpp b/source/loading_screen.cpp index b80f956..d33ffab 100644 --- a/source/loading_screen.cpp +++ b/source/loading_screen.cpp @@ -1,40 +1,36 @@ #include "loading_screen.h" -#include // for SDL_GetError -#include // for SDL_PollEvent, SDL_Event -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for SDL_GetTicks -#include // for rand -#include // for char_traits, basic_ostream, operator<< -#include "defines.h" // for GAME_SPEED -#include "global_events.h" // for check -#include "global_inputs.h" // for check -#include "jail_audio.h" // for JA_PlayMusic, JA_SetVolume, JA_StopMusic -#include "options.h" // for Options, options, OptionsVideo, Section... -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "sprite.h" // for Sprite -#include "texture.h" // for Texture -#include "utils.h" // for Color, stringToColor, Palette +#include // for SDL_GetError +#include // for SDL_PollEvent, SDL_Event +#include // for SDL_PIXELFORMAT_RGBA8888 +#include // for SDL_GetTicks +#include // for rand +#include // for char_traits, basic_ostream, operator<< +#include "defines.h" // for GAME_SPEED +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#include "jail_audio.h" // for JA_PlayMusic, JA_SetVolume, JA_StopMusic +#include "options.h" // for Options, options, OptionsVideo, Section... +#include "resource.h" // for Resource +#include "screen.h" // for Screen +#include "s_sprite.h" // for SSprite +#include "surface.h" // for Texture +#include "utils.h" // for Color, stringToColor, Palette // Constructor LoadingScreen::LoadingScreen() + : mono_loading_screen_surface_(Resource::get()->getSurface("loading_screen_bn.gif")), + color_loading_screen_surface_(Resource::get()->getSurface("loading_screen_color.gif")), + mono_loading_screen_sprite_(std::make_shared(mono_loading_screen_surface_, 0, 0, mono_loading_screen_surface_->getWidth(), mono_loading_screen_surface_->getHeight())), + color_loading_screen_sprite_(std::make_shared(color_loading_screen_surface_, 0, 0, color_loading_screen_surface_->getWidth(), color_loading_screen_surface_->getHeight())), + screen_surface_(std::make_shared(Screen::get()->getSurface(), options.game.width, options.game.height)) { - // Reserva memoria para los punteros - if (options.video.palette == Palette::ZXSPECTRUM) - { - 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::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()); + // Cambia el destino de las surfaces + mono_loading_screen_surface_->setSurfaceDest(screen_surface_->getSurface()); + color_loading_screen_surface_->setSurfaceDest(screen_surface_->getSurface()); - texture_ = createTexture(Screen::get()->getRenderer(), options.game.width, options.game.height); - clearTexture(); + // Configura la superficie donde se van a pintar los sprites + screen_surface_->setColor(0, 0xFF000000); + screen_surface_->clear(0); // Inicializa variables options.section.section = Section::LOADING_SCREEN; @@ -65,7 +61,6 @@ LoadingScreen::LoadingScreen() LoadingScreen::~LoadingScreen() { JA_StopMusic(); - SDL_DestroyTexture(texture_); } // Comprueba el manejador de eventos @@ -152,32 +147,32 @@ void LoadingScreen::renderLoad() // Dibuja el efecto de carga en el borde void LoadingScreen::renderBorder() { - // Pinta el borde de colro azul - Color color = stringToColor(options.video.palette, "blue"); - SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF); - SDL_RenderClear(Screen::get()->getRenderer()); + // Pinta el borde de colro azul + Color color = stringToColor(options.video.palette, "blue"); + 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(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; + // Añade lineas amarillas + color = stringToColor(options.video.palette, "yellow"); + 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; - int row = 0; - while (row < HEIGHT) - { - const int ROW_HEIGHT = (rand() % 4) + 3; - if (drawEnabled) - { - for (int i = row; i < row + ROW_HEIGHT; ++i) - { - SDL_RenderDrawLine(Screen::get()->getRenderer(), 0, i, WIDTH, i); - } - } - row += ROW_HEIGHT; - drawEnabled = !drawEnabled; - } + int row = 0; + while (row < HEIGHT) + { + const int ROW_HEIGHT = (rand() % 4) + 3; + if (drawEnabled) + { + for (int i = row; i < row + ROW_HEIGHT; ++i) + { + SDL_RenderDrawLine(Screen::get()->getRenderer(), 0, i, WIDTH, i); + } + } + row += ROW_HEIGHT; + drawEnabled = !drawEnabled; + } } // Actualiza las variables @@ -190,7 +185,7 @@ void LoadingScreen::update() checkInput(); updateCounter(); updateLoad(); - fillTexture(); + renderLoad(); Screen::get()->update(); } } @@ -210,8 +205,8 @@ void LoadingScreen::render() // Prepara para empezar a dibujar en la textura de juego Screen::get()->start(); - // Copila la textura a la pantalla - SDL_RenderCopy(Screen::get()->getRenderer(), texture_, nullptr, nullptr); + // Copia la surface a la surface de Screen + screen_surface_->render(0, 0); // Vuelca el contenido del renderizador en pantalla Screen::get()->render(); @@ -237,33 +232,4 @@ void LoadingScreen::run() } JA_SetVolume(128); -} - -// Dibuja sobre la textura -void LoadingScreen::fillTexture() -{ - // Empieza a dibujar en la textura - 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(Screen::get()->getRenderer(), temp); -} - -// Limpia la textura -void LoadingScreen::clearTexture() -{ - // Empieza a dibujar en la textura - auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer()); - SDL_SetRenderTarget(Screen::get()->getRenderer(), texture_); - - // Limpia - SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0x00, 0x00, 0x00, 0xFF); - SDL_RenderClear(Screen::get()->getRenderer()); - - // Deja el renderizador como estaba - 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 42a1aae..5386354 100644 --- a/source/loading_screen.h +++ b/source/loading_screen.h @@ -1,20 +1,21 @@ #pragma once -#include // for SDL_Rect -#include // for SDL_Texture -#include // for Uint32 -#include // for shared_ptr -class Sprite; // lines 11-11 -class Texture; // lines 12-12 +#include // for SDL_Rect +#include // for SDL_Texture +#include // for Uint32 +#include // for shared_ptr +class SSprite; // lines 11-11 +class Surface; // lines 12-12 class LoadingScreen { private: // Objetos y punteros - 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 - std::shared_ptr color_loading_screen_sprite_; // Sprite para manejar la textura loadingScreenTexture2 + std::shared_ptr mono_loading_screen_surface_; // Surface con la pantalla de carga en blanco y negro + std::shared_ptr color_loading_screen_surface_; // Surface con la pantalla de carga en color + std::shared_ptr mono_loading_screen_sprite_; // SSprite para manejar la textura loadingScreenTexture1 + std::shared_ptr color_loading_screen_sprite_; // SSprite para manejar la textura loadingScreenTexture2 + std::shared_ptr screen_surface_; // Surface para dibujar la pantalla de carga // Variables int pre_counter_ = 0; // Contador previo para realizar una pausa inicial @@ -24,7 +25,6 @@ private: bool loading_first_part_ = true; // Para saber en que parte de la carga se encuentra 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 // Actualiza las variables void update(); @@ -50,12 +50,6 @@ private: // Dibuja el efecto de carga en el borde void renderBorder(); - // Dibuja sobre la textura - void fillTexture(); - - // Limpia la textura - void clearTexture(); - public: // Constructor LoadingScreen(); diff --git a/source/logo.cpp b/source/logo.cpp index 8f386dd..bbaf966 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -1,32 +1,32 @@ #include "logo.h" -#include // for SDL_PollEvent, SDL_Event -#include // for SDL_GetTicks -#include // for basic_string, string -#include "defines.h" // for GAME_SPEED -#include "global_events.h" // for check -#include "global_inputs.h" // for check -#include "jail_audio.h" // for JA_StopMusic -#include "options.h" // for Options, options, SectionState, Section -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "sprite.h" // for Sprite -#include "texture.h" // for Texture -#include "utils.h" // for Color, stringToColor +#include // for SDL_PollEvent, SDL_Event +#include // for SDL_GetTicks +#include // for basic_string, string +#include "defines.h" // for GAME_SPEED +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#include "jail_audio.h" // for JA_StopMusic +#include "options.h" // for Options, options, SectionState, Section +#include "resource.h" // for Resource +#include "screen.h" // for Screen +#include "s_sprite.h" // for SSprite +#include "surface.h" // for Texture +#include "utils.h" // for Color, stringToColor // Constructor Logo::Logo() - : 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())) + : jailgames_surface_(Resource::get()->getSurface("jailgames.gif")), + since_1998_surface_(Resource::get()->getSurface("since_1998.gif")), + since_1998_sprite_(std::make_shared(since_1998_surface_, (256 - since_1998_surface_->getWidth()) / 2, 83 + jailgames_surface_->getHeight() + 5, since_1998_surface_->getWidth(), since_1998_surface_->getHeight())) { - since_1998_sprite_->setClip(0, 0, since_1998_texture_->getWidth(), since_1998_texture_->getHeight()); - since_1998_texture_->setColor(0, 0, 0); + since_1998_sprite_->setClip(0, 0, since_1998_surface_->getWidth(), since_1998_surface_->getHeight()); + //since_1998_surface_->setColor(0, 0, 0); // Crea los sprites de cada linea - for (int i = 0; i < jailgames_texture_->getHeight(); ++i) + for (int i = 0; i < jailgames_surface_->getHeight(); ++i) { - jailgames_sprite_.push_back(std::make_shared(jailgames_texture_, 0, i, jailgames_texture_->getWidth(), 1)); - jailgames_sprite_.back()->setClip(0, i, jailgames_texture_->getWidth(), 1); + jailgames_sprite_.push_back(std::make_shared(jailgames_surface_, 0, i, jailgames_surface_->getWidth(), 1)); + jailgames_sprite_.back()->setClip(0, i, jailgames_surface_->getWidth(), 1); jailgames_sprite_.at(i)->setX((i % 2 == 0) ? (256 + (i * 3)) : (-181 - (i * 3))); jailgames_sprite_.at(i)->setY(83 + i); } @@ -98,88 +98,89 @@ void Logo::updateTextureColors() { constexpr int INI = 70; constexpr int INC = 4; - +/* if (counter_ == INI + INC * 0) { - since_1998_texture_->setColor(color_.at(0).r, color_.at(0).g, color_.at(0).b); + since_1998_surface_->setColor(color_.at(0).r, color_.at(0).g, color_.at(0).b); } else if (counter_ == INI + INC * 1) { - since_1998_texture_->setColor(color_.at(1).r, color_.at(1).g, color_.at(1).b); + since_1998_surface_->setColor(color_.at(1).r, color_.at(1).g, color_.at(1).b); } else if (counter_ == INI + INC * 2) { - since_1998_texture_->setColor(color_.at(2).r, color_.at(2).g, color_.at(2).b); + since_1998_surface_->setColor(color_.at(2).r, color_.at(2).g, color_.at(2).b); } else if (counter_ == INI + INC * 3) { - since_1998_texture_->setColor(color_.at(3).r, color_.at(3).g, color_.at(3).b); + since_1998_surface_->setColor(color_.at(3).r, color_.at(3).g, color_.at(3).b); } else if (counter_ == INI + INC * 4) { - since_1998_texture_->setColor(color_.at(4).r, color_.at(4).g, color_.at(4).b); + since_1998_surface_->setColor(color_.at(4).r, color_.at(4).g, color_.at(4).b); } else if (counter_ == INI + INC * 5) { - since_1998_texture_->setColor(color_.at(5).r, color_.at(5).g, color_.at(5).b); + since_1998_surface_->setColor(color_.at(5).r, color_.at(5).g, color_.at(5).b); } else if (counter_ == INI + INC * 6) { - since_1998_texture_->setColor(color_.at(6).r, color_.at(6).g, color_.at(6).b); + since_1998_surface_->setColor(color_.at(6).r, color_.at(6).g, color_.at(6).b); } else if (counter_ == INI + INC * 7) { - since_1998_texture_->setColor(color_.at(7).r, color_.at(7).g, color_.at(7).b); + since_1998_surface_->setColor(color_.at(7).r, color_.at(7).g, color_.at(7).b); } else if (counter_ == INIT_FADE_ + INC * 0) { - jailgames_texture_->setColor(color_.at(6).r, color_.at(6).g, color_.at(6).b); - since_1998_texture_->setColor(color_.at(6).r, color_.at(6).g, color_.at(6).b); + jailgames_surface_->setColor(color_.at(6).r, color_.at(6).g, color_.at(6).b); + since_1998_surface_->setColor(color_.at(6).r, color_.at(6).g, color_.at(6).b); } else if (counter_ == INIT_FADE_ + INC * 1) { - jailgames_texture_->setColor(color_.at(5).r, color_.at(5).g, color_.at(5).b); - since_1998_texture_->setColor(color_.at(5).r, color_.at(5).g, color_.at(5).b); + jailgames_surface_->setColor(color_.at(5).r, color_.at(5).g, color_.at(5).b); + since_1998_surface_->setColor(color_.at(5).r, color_.at(5).g, color_.at(5).b); } else if (counter_ == INIT_FADE_ + INC * 2) { - jailgames_texture_->setColor(color_.at(4).r, color_.at(4).g, color_.at(4).b); - since_1998_texture_->setColor(color_.at(4).r, color_.at(4).g, color_.at(4).b); + jailgames_surface_->setColor(color_.at(4).r, color_.at(4).g, color_.at(4).b); + since_1998_surface_->setColor(color_.at(4).r, color_.at(4).g, color_.at(4).b); } else if (counter_ == INIT_FADE_ + INC * 3) { - jailgames_texture_->setColor(color_.at(3).r, color_.at(3).g, color_.at(3).b); - since_1998_texture_->setColor(color_.at(3).r, color_.at(3).g, color_.at(3).b); + jailgames_surface_->setColor(color_.at(3).r, color_.at(3).g, color_.at(3).b); + since_1998_surface_->setColor(color_.at(3).r, color_.at(3).g, color_.at(3).b); } else if (counter_ == INIT_FADE_ + INC * 4) { - jailgames_texture_->setColor(color_.at(2).r, color_.at(2).g, color_.at(2).b); - since_1998_texture_->setColor(color_.at(2).r, color_.at(2).g, color_.at(2).b); + jailgames_surface_->setColor(color_.at(2).r, color_.at(2).g, color_.at(2).b); + since_1998_surface_->setColor(color_.at(2).r, color_.at(2).g, color_.at(2).b); } else if (counter_ == INIT_FADE_ + INC * 5) { - jailgames_texture_->setColor(color_.at(1).r, color_.at(1).g, color_.at(1).b); - since_1998_texture_->setColor(color_.at(1).r, color_.at(1).g, color_.at(1).b); + jailgames_surface_->setColor(color_.at(1).r, color_.at(1).g, color_.at(1).b); + since_1998_surface_->setColor(color_.at(1).r, color_.at(1).g, color_.at(1).b); } else if (counter_ == INIT_FADE_ + INC * 6) { - jailgames_texture_->setColor(color_.at(0).r, color_.at(0).g, color_.at(0).b); - since_1998_texture_->setColor(color_.at(0).r, color_.at(0).g, color_.at(0).b); + jailgames_surface_->setColor(color_.at(0).r, color_.at(0).g, color_.at(0).b); + since_1998_surface_->setColor(color_.at(0).r, color_.at(0).g, color_.at(0).b); } + */ } // Actualiza las variables diff --git a/source/logo.h b/source/logo.h index fed27e7..58d5231 100644 --- a/source/logo.h +++ b/source/logo.h @@ -1,11 +1,11 @@ #pragma once -#include // for Uint32 -#include // for shared_ptr -#include // for vector -#include "utils.h" // for Color -class Sprite; // lines 12-12 -class Texture; // lines 13-13 +#include // for Uint32 +#include // for shared_ptr +#include // for vector +#include "utils.h" // for Color +class SSprite; // lines 12-12 +class Surface; // lines 13-13 class Logo { @@ -16,10 +16,10 @@ private: static constexpr int POST_LOGO_ = 20; // Tiempo que dura el logo con el fade al maximo // Objetos y punteros - 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 - std::shared_ptr since_1998_sprite_; // Sprite para manejar la textura2 + std::shared_ptr jailgames_surface_; // Textura con los graficos "JAILGAMES" + std::shared_ptr since_1998_surface_; // Textura con los graficos "Since 1998" + std::vector> jailgames_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES + std::shared_ptr since_1998_sprite_; // SSprite para manejar la textura2 // Variables std::vector color_; // Vector con los colores para el fade diff --git a/source/notifier.cpp b/source/notifier.cpp index 0507ac6..a4bc226 100644 --- a/source/notifier.cpp +++ b/source/notifier.cpp @@ -1,17 +1,17 @@ #include "notifier.h" -#include // for SDL_BLENDMODE_BLEND -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for SDL_RenderFillRect, SDL_RenderClear -#include // for remove_if -#include // for string, basic_string -#include // for vector -#include "jail_audio.h" // for JA_PlaySound -#include "options.h" // for Options, options, OptionsNotification -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "sprite.h" // for Sprite -#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR -#include "texture.h" // for Texture +#include // for SDL_BLENDMODE_BLEND +#include // for SDL_PIXELFORMAT_RGBA8888 +#include // for SDL_RenderFillRect, SDL_RenderClear +#include // for remove_if +#include // for string, basic_string +#include // for vector +#include "jail_audio.h" // for JA_PlaySound +#include "options.h" // for Options, options, OptionsNotification +#include "resource.h" // for Resource +#include "screen.h" // for Screen +#include "s_sprite.h" // for Sprite +#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR +#include "surface.h" // for Texture // [SINGLETON] Notifier *Notifier::notifier_ = nullptr; @@ -36,7 +36,7 @@ Notifier *Notifier::get() // Constructor Notifier::Notifier(const std::string &icon_file, const std::string &text) - : icon_texture_(!icon_file.empty() ? Resource::get()->getTexture(icon_file) : nullptr), + : icon_texture_(!icon_file.empty() ? Resource::get()->getSurface(icon_file) : nullptr), text_(Resource::get()->getText(text)), bg_color_(options.notifications.color), wait_time_(150), diff --git a/source/player.cpp b/source/player.cpp index bfd1a63..dbfcfee 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -1,18 +1,18 @@ // IWYU pragma: no_include #include "player.h" -#include // for rand -#include // for max, min -#include // for ceil, abs -#include "animated_sprite.h" // for AnimatedSprite -#include "debug.h" // for Debug -#include "defines.h" // for BORDER_BOTTOM, BORDER_LEFT, BORDER_RIGHT -#include "input.h" // for Input, InputAction -#include "jail_audio.h" // for JA_PlaySound -#include "options.h" // for Options, options, Cheat, OptionsVideo -#include "resource.h" // for Resource -#include "room.h" // for Room, JA_Sound_t, TileType -#include "screen.h" // for Screen -#include "texture.h" // for Texture +#include // for rand +#include // for max, min +#include // for ceil, abs +#include "s_animated_sprite.h" // for AnimatedSprite +#include "debug.h" // for Debug +#include "defines.h" // for BORDER_BOTTOM, BORDER_LEFT, BORDER_RIGHT +#include "input.h" // for Input, InputAction +#include "jail_audio.h" // for JA_PlaySound +#include "options.h" // for Options, options, Cheat, OptionsVideo +#include "resource.h" // for Resource +#include "room.h" // for Room, JA_Sound_t, TileType +#include "screen.h" // for Screen +#include "surface.h" // for Texture // Constructor Player::Player(const PlayerData &player) @@ -715,7 +715,7 @@ void Player::applySpawnValues(const PlayerSpawn &spawn) // Inicializa el sprite del jugador void Player::initSprite(const std::string &texture_path, const std::string &animations_path) { - auto texture = Resource::get()->getTexture(texture_path); + auto texture = Resource::get()->getSurface(texture_path); auto animations = Resource::get()->getAnimations(animations_path); sprite_ = std::make_shared(texture, animations); diff --git a/source/player.h b/source/player.h index aed1117..7f414f3 100644 --- a/source/player.h +++ b/source/player.h @@ -1,16 +1,16 @@ #pragma once -#include // for SDL_Rect, SDL_Point -#include // for SDL_RendererFlip, SDL_FLIP_NONE -#include // for shared_ptr, __shared_ptr_access -#include // for string -#include // for vector -#include "animated_sprite.h" // for AnimatedSprite -#include "defines.h" // for BORDER_TOP, BLOCK -#include "texture.h" // for Texture -#include "utils.h" // for Color -class Room; // lines 16-16 -struct JA_Sound_t; // lines 17-17 +#include // for SDL_Rect, SDL_Point +#include // for SDL_RendererFlip, SDL_FLIP_NONE +#include // for shared_ptr, __shared_ptr_access +#include // for string +#include // for vector +#include "s_animated_sprite.h" // for AnimatedSprite +#include "defines.h" // for BORDER_TOP, BLOCK +#include "surface.h" // for Texture +#include "utils.h" // for Color +class Room; // lines 16-16 +struct JA_Sound_t; // lines 17-17 enum class PlayerState { diff --git a/source/resource.cpp b/source/resource.cpp index cbbc960..7f828a8 100644 --- a/source/resource.cpp +++ b/source/resource.cpp @@ -1,20 +1,20 @@ #include "resource.h" -#include // for SDL_PollEvent, SDL_Event, SDL_KEYDOWN -#include // for SDLK_ESCAPE -#include // for SDL_Rect -#include // for SDL_RenderDrawRect, SDL_RenderFillRect -#include // for exit, size_t -#include // for find_if -#include // for basic_ostream, operator<<, endl, cout -#include // for runtime_error -#include "asset.h" // for AssetType, Asset -#include "jail_audio.h" // for JA_DeleteMusic, JA_DeleteSound, JA_Loa... -#include "options.h" // for Options, OptionsGame, options -#include "screen.h" // for Screen -#include "text.h" // for Text, loadTextFile -#include "utils.h" // for getFileName, printWithDots, Color -struct JA_Music_t; // lines 12-12 -struct JA_Sound_t; // lines 13-13 +#include // for SDL_PollEvent, SDL_Event, SDL_KEYDOWN +#include // for SDLK_ESCAPE +#include // for SDL_Rect +#include // for SDL_RenderDrawRect, SDL_RenderFillRect +#include // for exit, size_t +#include // for find_if +#include // for basic_ostream, operator<<, endl, cout +#include // for runtime_error +#include "asset.h" // for AssetType, Asset +#include "jail_audio.h" // for JA_DeleteMusic, JA_DeleteSound, JA_Loa... +#include "options.h" // for Options, OptionsGame, options +#include "screen.h" // for Screen +#include "text.h" // for Text, loadTextFile +#include "utils.h" // for getFileName, printWithDots, Color +struct JA_Music_t; // lines 12-12 +struct JA_Sound_t; // lines 13-13 // [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado Resource *Resource::resource_ = nullptr; @@ -48,7 +48,7 @@ void Resource::clear() { clearSounds(); clearMusics(); - textures_.clear(); + surfaces_.clear(); text_files_.clear(); texts_.clear(); animations_.clear(); @@ -63,7 +63,7 @@ void Resource::load() std::cout << "** LOADING RESOURCES" << std::endl; loadSounds(); loadMusics(); - loadTextures(); + loadSurfaces(); loadTextFiles(); loadAnimations(); loadTileMaps(); @@ -110,14 +110,14 @@ JA_Music_t *Resource::getMusic(const std::string &name) } // Obtiene la textura a partir de un nombre -std::shared_ptr Resource::getTexture(const std::string &name) +std::shared_ptr Resource::getSurface(const std::string &name) { - auto it = std::find_if(textures_.begin(), textures_.end(), [&name](const auto &t) + auto it = std::find_if(surfaces_.begin(), surfaces_.end(), [&name](const auto &t) { return t.name == name; }); - if (it != textures_.end()) + if (it != surfaces_.end()) { - return it->texture; + return it->surface; } std::cerr << "Error: Imagen no encontrada " << name << std::endl; @@ -238,16 +238,16 @@ void Resource::loadMusics() } // Carga las texturas -void Resource::loadTextures() +void Resource::loadSurfaces() { - std::cout << "\n>> TEXTURES" << std::endl; + std::cout << "\n>> SURFACES" << std::endl; auto list = Asset::get()->getListByType(AssetType::BITMAP); - textures_.clear(); + surfaces_.clear(); for (const auto &l : list) { auto name = getFileName(l); - textures_.emplace_back(ResourceTexture(name, std::make_shared(Screen::get()->getRenderer(), l))); + surfaces_.emplace_back(ResourceSurface(name, std::make_shared(Screen::get()->getSurface(), l))); updateLoadingProgress(); } } @@ -330,16 +330,16 @@ void Resource::createText() std::cout << "\n>> CREATING TEXT_OBJECTS" << std::endl; std::vector resources = { - {"debug", "debug.png", "debug.txt"}, - {"gauntlet", "gauntlet.png", "gauntlet.txt"}, - {"smb2", "smb2.png", "smb2.txt"}, - {"subatomic", "subatomic.png", "subatomic.txt"}, - {"8bithud", "8bithud.png", "8bithud.txt"}}; + {"debug", "debug.gif", "debug.txt"}, + {"gauntlet", "gauntlet.gif", "gauntlet.txt"}, + {"smb2", "smb2.gif", "smb2.txt"}, + {"subatomic", "subatomic.gif", "subatomic.txt"}, + {"8bithud", "8bithud.gif", "8bithud.txt"}}; for (const auto &resource : resources) { texts_.emplace_back(ResourceText(resource.key, std::make_shared( - getTexture(resource.textureFile), + getSurface(resource.textureFile), getTextFile(resource.textFile)))); printWithDots("Text : ", resource.key, "[ DONE ]"); } diff --git a/source/resource.h b/source/resource.h index 2e695c9..e2365f3 100644 --- a/source/resource.h +++ b/source/resource.h @@ -1,14 +1,14 @@ #pragma once -#include // for shared_ptr -#include // for string -#include // for vector -#include "animated_sprite.h" // for AnimationsFileBuffer -#include "room.h" // for room_t -#include "text.h" // for Text, TextFile -#include "texture.h" // for Texture -struct JA_Music_t; // lines 11-11 -struct JA_Sound_t; // lines 12-12 +#include // for shared_ptr +#include // for string +#include // for vector +#include "s_animated_sprite.h" // for AnimationsFileBuffer +#include "room.h" // for room_t +#include "text.h" // for Text, TextFile +#include "surface.h" // for Surface +struct JA_Music_t; // lines 11-11 +struct JA_Sound_t; // lines 12-12 // Estructura para almacenar ficheros de sonido y su nombre struct ResourceSound @@ -32,15 +32,15 @@ struct ResourceMusic : name(name), music(music) {} }; -// Estructura para almacenar objetos Texture y su nombre -struct ResourceTexture +// Estructura para almacenar objetos Surface y su nombre +struct ResourceSurface { - std::string name; // Nombre de la textura - std::shared_ptr texture; // Objeto con la textura + std::string name; // Nombre de la surface + std::shared_ptr surface; // Objeto con la surface // Constructor - ResourceTexture(const std::string &name, std::shared_ptr texture) - : name(name), texture(texture) {} + ResourceSurface(const std::string &name, std::shared_ptr surface) + : name(name), surface(surface) {} }; // Estructura para almacenar ficheros TextFile y su nombre @@ -101,14 +101,6 @@ struct ResourceRoom // Estructura para llevar la cuenta de los recursos cargados struct ResourceCount { - // int sounds; // Número de sonidos cargados - // int musics; // Número de musicas cargadas - // int textures; // Número de texturas cargadas - // int text_files; // Número de ficheros de texto cargados - // int texts; // Número de objetos de texto cargados - // int animations; // Número de animaciones cargadas - // int tile_maps; // Número de mapas de tiles cargados - // int rooms; // Número de habitaciones cargadas int total; // Número total de recursos int loaded; // Número de recursos cargados @@ -141,7 +133,7 @@ private: std::vector sounds_; // Vector con los sonidos std::vector musics_; // Vector con las musicas - std::vector textures_; // Vector con las musicas + std::vector surfaces_; // Vector con las surfaces std::vector text_files_; // Vector con los ficheros de texto std::vector texts_; // Vector con los objetos de texto std::vector animations_; // Vector con las animaciones @@ -156,8 +148,8 @@ private: // Carga las musicas void loadMusics(); - // Carga las texturas - void loadTextures(); + // Carga las surfaces + void loadSurfaces(); // Carga los ficheros de texto void loadTextFiles(); @@ -222,8 +214,8 @@ public: // Obtiene la música a partir de un nombre JA_Music_t *getMusic(const std::string &name); - // Obtiene la textura a partir de un nombre - std::shared_ptr getTexture(const std::string &name); + // Obtiene la surface a partir de un nombre + std::shared_ptr getSurface(const std::string &name); // Obtiene el fichero de texto a partir de un nombre std::shared_ptr getTextFile(const std::string &name); diff --git a/source/room.cpp b/source/room.cpp index cce3b37..7587a4e 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -1,23 +1,23 @@ #include "room.h" -#include // for SDL_BLENDMODE_BLEND -#include // for SDL_GetError -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for rand -#include // for exception -#include // for basic_ostream, operator<<, basic_ist... -#include // for cout, cerr -#include // for basic_stringstream -#include "debug.h" // for Debug -#include "defines.h" // for BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_W... -#include "item_tracker.h" // for ItemTracker -#include "jail_audio.h" // for JA_PlaySound -#include "options.h" // for Options, options, OptionsVideo, Opti... -#include "resource.h" // for Resource -#include "scoreboard.h" // for ScoreboardData -#include "screen.h" // for Screen -#include "sprite.h" // for Sprite -#include "texture.h" // for Texture -#include "utils.h" // for LineHorizontal, LineDiagonal, LineVe... +#include // for SDL_BLENDMODE_BLEND +#include // for SDL_GetError +#include // for SDL_PIXELFORMAT_RGBA8888 +#include // for rand +#include // for exception +#include // for basic_ostream, operator<<, basic_ist... +#include // for cout, cerr +#include // for basic_stringstream +#include "debug.h" // for Debug +#include "defines.h" // for BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_W... +#include "item_tracker.h" // for ItemTracker +#include "jail_audio.h" // for JA_PlaySound +#include "options.h" // for Options, options, OptionsVideo, Opti... +#include "resource.h" // for Resource +#include "scoreboard.h" // for ScoreboardData +#include "screen.h" // for Screen +#include "s_sprite.h" // for Sprite +#include "surface.h" // for Texture +#include "utils.h" // for LineHorizontal, LineDiagonal, LineVe... // Carga las variables y texturas desde un fichero de mapa de tiles std::vector loadRoomTileFile(const std::string &file_path, bool verbose) @@ -444,7 +444,7 @@ void Room::initializeRoom(const RoomData &room) tile_map_file_ = room.tile_map_file; auto_surface_direction_ = room.auto_surface_direction; tile_map_ = Resource::get()->getTileMap(room.tile_map_file); - texture_ = Resource::get()->getTexture(room.tile_set_file); + texture_ = Resource::get()->getSurface(room.tile_set_file); tile_set_width_ = texture_->getWidth() / TILE_SIZE_; is_paused_ = false; counter_ = 0; diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index ce32a7a..4849934 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -1,16 +1,16 @@ #include "scoreboard.h" -#include // for SDL_GetError -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for SDL_Rect -#include // for SDL_GetTicks -#include // for basic_ostream, operator<<, cout, endl -#include "animated_sprite.h" // for AnimatedSprite -#include "defines.h" // for BLOCK -#include "options.h" // for Options, options, OptionsVideo, Cheat -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "text.h" // for Text -#include "texture.h" // for Texture +#include // for SDL_GetError +#include // for SDL_PIXELFORMAT_RGBA8888 +#include // for SDL_Rect +#include // for SDL_GetTicks +#include // for basic_ostream, operator<<, cout, endl +#include "s_animated_sprite.h" // for AnimatedSprite +#include "defines.h" // for BLOCK +#include "options.h" // for Options, options, OptionsVideo, Cheat +#include "resource.h" // for Resource +#include "screen.h" // for Screen +#include "text.h" // for Text +#include "surface.h" // for Texture // Constructor Scoreboard::Scoreboard(std::shared_ptr data) @@ -21,8 +21,8 @@ Scoreboard::Scoreboard(std::shared_ptr data) constexpr int TEXTURE_HEIGHT_ = 6 * BLOCK; // Reserva memoria para los objetos - item_texture_ = Resource::get()->getTexture("items.png"); - auto player_texture = Resource::get()->getTexture(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png"); + item_texture_ = Resource::get()->getSurface("items.gif"); + auto player_texture = Resource::get()->getSurface(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.gif" : "player.gif"); 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"); diff --git a/source/screen.cpp b/source/screen.cpp index d68fd93..598140f 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -93,6 +93,9 @@ void Screen::startDrawOnBorder() { SDL_SetRenderTarget(renderer_, border_texture // Vuelca el contenido del renderizador en pantalla void Screen::render() { + // Copia la surface a game_texture_ + surface_->copyToTexture(renderer_, game_texture_); + // Renderiza sobre gameCanvas los overlays renderNotifications(); diff --git a/source/screen.h b/source/screen.h index 67cd38e..f3b321a 100644 --- a/source/screen.h +++ b/source/screen.h @@ -6,6 +6,8 @@ #include // for Uint32 #include // for SDL_Window #include "utils.h" // for Color +#include "surface.h" // for Surface +#include // for shared_ptr // Tipos de filtro enum class ScreenFilter : Uint32 @@ -24,12 +26,12 @@ private: static Screen *screen_; // Objetos y punteros - SDL_Window *window_; // Ventana de la aplicación - SDL_Renderer *renderer_; // El renderizador de la ventana - SDL_Texture *surface_texture_; // Textura donde se dibuja el juego - SDL_Texture *game_texture_; // Textura donde se dibuja el juego - SDL_Texture *border_texture_; // Textura donde se dibuja el borde del juego - // std::shared_ptr surface_; // Objeto para trabajar con surfaces + SDL_Window *window_; // Ventana de la aplicación + SDL_Renderer *renderer_; // El renderizador de la ventana + SDL_Texture *surface_texture_; // Textura donde se dibuja el juego + SDL_Texture *game_texture_; // Textura donde se dibuja el juego + SDL_Texture *border_texture_; // Textura donde se dibuja el borde del juego + std::shared_ptr surface_; // Objeto para trabajar con surfaces // Variables int window_width_; // Ancho de la pantalla o ventana @@ -57,7 +59,7 @@ private: // Reinicia los shaders void resetShaders(); - + // Constructor Screen(SDL_Window *window, SDL_Renderer *renderer); @@ -132,7 +134,7 @@ public: // Getters SDL_Renderer *getRenderer() { return renderer_; } - // std::shared_ptr getSurface() { return surface_->getSurface(); } + std::shared_ptr getSurface() { return surface_->getSurface(); } SDL_Texture *getGameTexture() { return game_texture_; }; SDL_Texture *getBorderTexture() { return border_texture_; } }; \ No newline at end of file diff --git a/source/surface.cpp b/source/surface.cpp index 5b7798b..485ab1d 100644 --- a/source/surface.cpp +++ b/source/surface.cpp @@ -98,11 +98,11 @@ void Surface::setColor(int index, Uint32 color) palette_.at(index) = color; } -// Limpia la superficie de destino con un color -void Surface::clear(std::shared_ptr surface, Uint8 color) +// Rellena la superficie con un color +void Surface::clear(Uint8 color) { - const size_t total_pixels = surface->width * surface->height; - std::fill(surface->data, surface->data + total_pixels, color); + const size_t total_pixels = surface_->width * surface_->height; + std::fill(surface_->data, surface_->data + total_pixels, color); } // Pone un pixel en la superficie de destino diff --git a/source/surface.h b/source/surface.h index 74f6097..d5403cf 100644 --- a/source/surface.h +++ b/source/surface.h @@ -92,8 +92,8 @@ public: // Establece un color en la paleta void setColor(int index, Uint32 color); - // Limpia la superficie de destino con un color - void clear(std::shared_ptr surface, Uint8 color); + // Rellena la superficie con un color + void clear(Uint8 color); // Vuelca la superficie a una textura void copyToTexture(SDL_Renderer *renderer, SDL_Texture *texture); @@ -106,4 +106,10 @@ public: int getTransparentColor() const { return transparent_color_; } int getWidth() const { return surface_->width; } int getHeight() const { return surface_->height; } + + // Setters + void setTransparentColor(int color) { transparent_color_ = color; } + void setSurfaceDest(std::shared_ptr surface_dest) { surface_dest_ = surface_dest; } + void setPalette(const std::array &palette) { palette_ = palette; } + void setSurface(std::shared_ptr surface) { surface_ = surface; } }; diff --git a/source/text.cpp b/source/text.cpp index f919510..6335f4b 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -8,8 +8,8 @@ #include // Para cerr #include // Para runtime_error #include "screen.h" // Para Screen -#include "sprite.h" // Para Sprite -#include "texture.h" // Para Texture +#include "s_sprite.h" // Para SSprite +#include "surface.h" // Para Surface #include "utils.h" // Para Color, getFileName, printWithDots // Llena una estructuta TextFile desde un fichero @@ -80,7 +80,7 @@ std::shared_ptr loadTextFile(const std::string &file_path) } // Constructor -Text::Text(std::shared_ptr texture, const std::string &text_file) +Text::Text(std::shared_ptr surface, const std::string &text_file) { // Carga los offsets desde el fichero auto tf = loadTextFile(text_file); @@ -96,14 +96,14 @@ Text::Text(std::shared_ptr texture, const std::string &text_file) } // Crea los objetos - sprite_ = std::make_unique(texture, (SDL_Rect){0, 0, box_width_, box_height_}); + sprite_ = std::make_unique(surface, (SDL_Rect){0, 0, box_width_, box_height_}); // Inicializa variables fixed_width_ = false; } // Constructor -Text::Text(std::shared_ptr texture, std::shared_ptr text_file) +Text::Text(std::shared_ptr surface, std::shared_ptr text_file) { // Inicializa variables desde la estructura box_height_ = text_file->box_height; @@ -116,7 +116,7 @@ Text::Text(std::shared_ptr texture, std::shared_ptr text_file } // Crea los objetos - sprite_ = std::make_unique(texture, (SDL_Rect){0, 0, box_width_, box_height_}); + sprite_ = std::make_unique(surface, (SDL_Rect){0, 0, box_width_, box_height_}); // Inicializa variables fixed_width_ = false; @@ -141,71 +141,58 @@ void Text::write(int x, int y, const std::string &text, int kerning, int lenght) } } -// Escribe texto en pantalla -void Text::write2X(int x, int y, const std::string &text, int kerning) -{ - int shift = 0; - for (size_t i = 0; i < text.length(); ++i) - { - auto index = static_cast(text[i]); - SDL_Rect rect = {offset_[index].x, offset_[index].y, box_width_, box_height_}; - sprite_->getTexture()->render(x + shift, y, &rect, 2.0f, 2.0f); - shift += (offset_[index].w + kerning) * 2; - } -} - -// Escribe el texto en una textura -std::shared_ptr Text::writeToTexture(const std::string &text, int zoom, int kerning) +// Escribe el texto en una surface +std::shared_ptr Text::writeToSurface(const std::string &text, int zoom, int kerning) { auto renderer = Screen::get()->getRenderer(); - auto texture = std::make_shared(renderer); + auto surface = std::make_shared(renderer); auto width = lenght(text, kerning) * zoom; auto height = box_height_ * zoom; auto temp = SDL_GetRenderTarget(renderer); - texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET); - texture->setBlendMode(SDL_BLENDMODE_BLEND); - texture->setAsRenderTarget(renderer); + //surface->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET); + //surface->setBlendMode(SDL_BLENDMODE_BLEND); + //surface->setAsRenderTarget(renderer); SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); SDL_RenderClear(renderer); - zoom == 1 ? write(0, 0, text, kerning) : write2X(0, 0, text, kerning); + //zoom == 1 ? write(0, 0, text, kerning) : write2X(0, 0, text, kerning); SDL_SetRenderTarget(renderer, temp); - return texture; + return surface; } -// Escribe el texto con extras en una textura -std::shared_ptr Text::writeDXToTexture(Uint8 flags, const std::string &text, int kerning, Color textColor, Uint8 shadow_distance, Color shadow_color, int lenght) +// Escribe el texto con extras en una surface +std::shared_ptr Text::writeDXToSurface(Uint8 flags, const std::string &text, int kerning, Color textColor, Uint8 shadow_distance, Color shadow_color, int lenght) { auto renderer = Screen::get()->getRenderer(); - auto texture = std::make_shared(renderer); + auto surface = std::make_shared(renderer); auto width = Text::lenght(text, kerning) + shadow_distance; auto height = box_height_ + shadow_distance; auto temp = SDL_GetRenderTarget(renderer); - texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET); - texture->setBlendMode(SDL_BLENDMODE_BLEND); - texture->setAsRenderTarget(renderer); + //surface->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET); + //surface->setBlendMode(SDL_BLENDMODE_BLEND); + //surface->setAsRenderTarget(renderer); SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); SDL_RenderClear(renderer); writeDX(flags, 0, 0, text, kerning, textColor, shadow_distance, shadow_color, lenght); SDL_SetRenderTarget(renderer, temp); - return texture; + return surface; } // Escribe el texto con colores void Text::writeColored(int x, int y, const std::string &text, Color color, int kerning, int lenght) { - sprite_->getTexture()->setColor(color.r, color.g, color.b); + //sprite_->getSurface()->setColor(color.r, color.g, color.b); write(x, y, text, kerning, lenght); - sprite_->getTexture()->setColor(255, 255, 255); + //sprite_->getSurface()->setColor(255, 255, 255); } // Escribe el texto con sombra void Text::writeShadowed(int x, int y, const std::string &text, Color color, Uint8 shadow_distance, int kerning, int lenght) { - sprite_->getTexture()->setColor(color.r, color.g, color.b); + //sprite_->getSurface()->setColor(color.r, color.g, color.b); write(x + shadow_distance, y + shadow_distance, text, kerning, lenght); - sprite_->getTexture()->setColor(255, 255, 255); + //sprite_->getSurface()->setColor(255, 255, 255); write(x, y, text, kerning, lenght); } @@ -275,23 +262,8 @@ int Text::getCharacterSize() const return box_width_; } -// Recarga la textura -void Text::reLoadTexture() -{ - sprite_->getTexture()->reLoad(); -} - // Establece si se usa un tamaño fijo de letra void Text::setFixedWidth(bool value) { fixed_width_ = value; -} - -// Establece una paleta -void Text::setPalette(int number) -{ - auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer()); - SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr); - //sprite_->getTexture()->setPalette(number); - SDL_SetRenderTarget(Screen::get()->getRenderer(), temp); } \ No newline at end of file diff --git a/source/text.h b/source/text.h index 3ec7b97..9576f80 100644 --- a/source/text.h +++ b/source/text.h @@ -3,9 +3,9 @@ #include // Para Uint8 #include // Para unique_ptr, shared_ptr #include // Para string -#include "sprite.h" // Para Sprite +#include "s_sprite.h" // Para SSprite #include "utils.h" // Para Color -class Texture; // lines 9-9 +class Surface; // lines 9-9 constexpr int TEXT_COLOR = 1; constexpr int TEXT_SHADOW = 2; @@ -32,7 +32,7 @@ class Text { private: // Objetos y punteros - std::unique_ptr sprite_ = nullptr; // Objeto con los graficos para el texto + std::unique_ptr sprite_ = nullptr; // Objeto con los graficos para el texto // Variables int box_width_ = 0; // Anchura de la caja de cada caracter en el png @@ -42,21 +42,20 @@ private: public: // Constructor - Text(std::shared_ptr texture, const std::string &text_file); - Text(std::shared_ptr texture, std::shared_ptr text_file); + Text(std::shared_ptr surface, const std::string &text_file); + Text(std::shared_ptr surface, std::shared_ptr text_file); // Destructor ~Text() = default; // Escribe el texto en pantalla void write(int x, int y, const std::string &text, int kerning = 1, int lenght = -1); - void write2X(int x, int y, const std::string &text, int kerning = 1); // Escribe el texto en una textura - std::shared_ptr writeToTexture(const std::string &text, int zoom = 1, int kerning = 1); + std::shared_ptr writeToSurface(const std::string &text, int zoom = 1, int kerning = 1); // Escribe el texto con extras en una textura - std::shared_ptr writeDXToTexture(Uint8 flags, const std::string &text, int kerning = 1, Color textColor = Color(), Uint8 shadow_distance = 1, Color shadow_color = Color(), int lenght = -1); + std::shared_ptr writeDXToSurface(Uint8 flags, const std::string &text, int kerning = 1, Color textColor = Color(), Uint8 shadow_distance = 1, Color shadow_color = Color(), int lenght = -1); // Escribe el texto con colores void writeColored(int x, int y, const std::string &text, Color color, int kerning = 1, int lenght = -1); @@ -76,12 +75,6 @@ public: // Devuelve el valor de la variable int getCharacterSize() const; - // Recarga la textura - void reLoadTexture(); - // Establece si se usa un tamaño fijo de letra void setFixedWidth(bool value); - - // Establece una paleta - void setPalette(int number); }; \ No newline at end of file diff --git a/source/title.cpp b/source/title.cpp index 1c3cb80..584246c 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -15,21 +15,18 @@ #include "options.h" // for Options, options, OptionsVideo, Sect... #include "resource.h" // for Resource #include "screen.h" // for Screen -#include "sprite.h" // for Sprite +#include "s_sprite.h" // for SSprite #include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR -#include "texture.h" // for Texture +#include "surface.h" // for Texture #include "utils.h" // for Color, stringToColor, Palette #include "paleta.h" // Constructor Title::Title() - : texture_(Resource::get()->getTexture("title_logo.png")), - sprite_(std::make_shared(texture_, 0, 0, texture_->getWidth(), texture_->getHeight())) + : surface_(Resource::get()->getSurface("title_logo.gif")), + sprite_(std::make_shared(surface_, 0, 0, surface_->getWidth(), surface_->getHeight())), + bg_surface_(std::make_shared(Screen::get()->getSurface(), options.game.width, options.game.height)) { - // Crea la textura para los graficos que aparecen en el fondo de la pantalla de titulo - bg_texture_ = createTexture(Screen::get()->getRenderer(), options.game.width, options.game.height); - SDL_SetTextureBlendMode(bg_texture_, SDL_BLENDMODE_BLEND); - // Carga la surface con los gráficos de la pantalla de carga pInit(Screen::get()->getRenderer(), 256, 128); loading_screen_ = pLoadSurface(Asset::get()->get("loading_screen_color.gif").c_str()); @@ -49,7 +46,7 @@ Title::Title() Screen::get()->setBorderColor(stringToColor(options.video.palette, "black")); // Rellena la textura de fondo con todos los gráficos - fillTexture(); + fillSurface(); // Inicia la musica playMusic("title.ogg"); @@ -59,7 +56,7 @@ Title::Title() Title::~Title() { pDeleteSurface(loading_screen_); - SDL_DestroyTexture(bg_texture_); + SDL_DestroyTexture(bg_surface_); } // Inicializa la marquesina @@ -255,7 +252,7 @@ void Title::render() if (state_ == TitleState::SHOW_MENU) { // Dibuja la textura de fondo - SDL_RenderCopy(Screen::get()->getRenderer(), bg_texture_, nullptr, nullptr); + SDL_RenderCopy(Screen::get()->getRenderer(), bg_surface_, nullptr, nullptr); // Dibuja la marquesina renderMarquee(); @@ -296,28 +293,28 @@ void Title::run() void Title::moveCheevosList(int direction) { const int speed = 2; - cheevos_texture_view_.y = direction == 0 ? cheevos_texture_view_.y - speed : cheevos_texture_view_.y + speed; + cheevos_surface_view_.y = direction == 0 ? cheevos_surface_view_.y - speed : cheevos_surface_view_.y + speed; - const int bottom = cheevos_texture_->getHeight() - cheevos_texture_view_.h; - if (cheevos_texture_view_.y < 0) + const int bottom = cheevos_surface_->getHeight() - cheevos_surface_view_.h; + if (cheevos_surface_view_.y < 0) { - cheevos_texture_view_.y = 0; + cheevos_surface_view_.y = 0; } - else if (cheevos_texture_view_.y > bottom) + else if (cheevos_surface_view_.y > bottom) { - cheevos_texture_view_.y = bottom; + cheevos_surface_view_.y = bottom; } - cheevos_sprite_->setClip(cheevos_texture_view_); + cheevos_sprite_->setClip(cheevos_surface_view_); } // Rellena la textura de fondo con todos los gráficos -void Title::fillTexture() +void Title::fillSurface() { auto renderer = Screen::get()->getRenderer(); // Coloca el puntero del renderizador sobre la textura - SDL_SetRenderTarget(renderer, bg_texture_); + SDL_SetRenderTarget(renderer, bg_surface_); // Rellena la textura de color const Color c = stringToColor(options.video.palette, "black"); @@ -352,10 +349,10 @@ void Title::createCheevosTexture() constexpr int CHEEVOS_PADDING = 10; 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(Screen::get()->getRenderer()); - cheevos_texture_->setBlendMode(SDL_BLENDMODE_BLEND); + cheevos_surface_ = std::make_shared(Screen::get()->getRenderer()); + cheevos_surface_->createBlank(CHEEVOS_TEXTURE_WIDTH, CHEEVOS_TEXTURE_HEIGHT, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET); + cheevos_surface_->setAsRenderTarget(Screen::get()->getRenderer()); + cheevos_surface_->setBlendMode(SDL_BLENDMODE_BLEND); // Rellena la textura con color sólido const Color CHEEVOS_BG_COLOR = stringToColor(options.video.palette, "black"); @@ -366,7 +363,7 @@ void Title::createCheevosTexture() const std::string CHEEVOS_OWNER = "ACHIEVEMENTS"; const std::string CHEEVOS_LIST_CAPTION = CHEEVOS_OWNER + " (" + std::to_string(Cheevos::get()->getTotalUnlockedAchievements()) + " / " + std::to_string(Cheevos::get()->size()) + ")"; int pos = 2; - TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, cheevos_texture_->getWidth() / 2, pos, CHEEVOS_LIST_CAPTION, 1, stringToColor(options.video.palette, "bright_green")); + TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, cheevos_surface_->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"); @@ -388,15 +385,15 @@ void Title::createCheevosTexture() } // Crea el sprite para el listado de logros - cheevos_sprite_ = std::make_shared(cheevos_texture_, (GAMECANVAS_WIDTH - cheevos_texture_->getWidth()) / 2, CHEEVOS_TEXTURE_POS_Y, cheevos_texture_->getWidth(), cheevos_texture_->getHeight()); - cheevos_texture_view_ = {0, 0, cheevos_texture_->getWidth(), CHEEVOS_TEXTURE_VIEW_HEIGHT}; - cheevos_sprite_->setClip(cheevos_texture_view_); + cheevos_sprite_ = std::make_shared(cheevos_surface_, (GAMECANVAS_WIDTH - cheevos_surface_->getWidth()) / 2, CHEEVOS_TEXTURE_POS_Y, cheevos_surface_->getWidth(), cheevos_surface_->getHeight()); + cheevos_surface_view_ = {0, 0, cheevos_surface_->getWidth(), CHEEVOS_TEXTURE_VIEW_HEIGHT}; + cheevos_sprite_->setClip(cheevos_surface_view_); } // Oculta la lista de logros void Title::hideCheevosList() { show_cheevos_ = false; - cheevos_texture_view_.y = 0; - cheevos_sprite_->setClip(cheevos_texture_view_); + cheevos_surface_view_.y = 0; + cheevos_sprite_->setClip(cheevos_surface_view_); } \ No newline at end of file diff --git a/source/title.h b/source/title.h index dfa09c3..e53b440 100644 --- a/source/title.h +++ b/source/title.h @@ -1,14 +1,14 @@ #pragma once -#include // for SDL_Rect -#include // for SDL_Texture -#include // for Uint32 -#include // for shared_ptr -#include // for string -#include // for vector -#include "paleta.h" // for jSurface -class Sprite; // lines 13-13 -class Texture; // lines 15-15 +#include // for SDL_Rect +#include // for SDL_Texture +#include // for Uint32 +#include // for shared_ptr +#include // for string +#include // for vector +#include "paleta.h" // for jSurface +class SSprite; // lines 13-13 +class Surface; // lines 15-15 class Title { @@ -28,11 +28,11 @@ private: }; // Objetos y punteros - 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 cheevos_texture_; // Textura con la lista de logros - std::shared_ptr cheevos_sprite_; // Sprite para manejar la textura con la lista de logros + std::shared_ptr surface_; // Textura con los graficos + std::shared_ptr sprite_; // SSprite para manejar la surface + std::shared_ptr bg_surface_; // Textura para dibujar el fondo de la pantalla + std::shared_ptr cheevos_surface_; // Textura con la lista de logros + std::shared_ptr cheevos_sprite_; // SSprite para manejar la surface con la lista de logros // Variables int counter_ = 0; // Contador @@ -41,7 +41,7 @@ private: std::vector letters_; // Vector con las letras de la marquesina int marquee_speed_ = 3; // Velocidad de desplazamiento de la marquesina bool show_cheevos_ = false; // Indica si se muestra por pantalla el listado de logros - SDL_Rect cheevos_texture_view_; // Zona visible de la textura con el listado de logros + SDL_Rect cheevos_surface_view_; // Zona visible de la surface con el listado de logros TitleState state_; // Estado en el que se encuentra el bucle principal jSurface loading_screen_; // Surface con los gráficos de la pantalla de carga @@ -69,10 +69,10 @@ private: // Desplaza la lista de logros void moveCheevosList(int direction); - // Rellena la textura de fondo con todos los gráficos - void fillTexture(); + // Rellena la surface de fondo con todos los gráficos + void fillSurface(); - // Crea y rellena la textura para mostrar los logros + // Crea y rellena la surface para mostrar los logros void createCheevosTexture(); // Oculta la lista de logros