From b940d627d675dddedcfef974429f21841f9481d3 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 3 Mar 2025 21:33:59 +0100 Subject: [PATCH] =?UTF-8?q?Transici=C3=B3=20a=20surface:=20crec=20que=20fa?= =?UTF-8?q?lta=20room.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/ending2.cpp | 62 +++++++++++++++++++------------------------ source/ending2.h | 36 ++++++++++++------------- source/enemy.cpp | 23 +++------------- source/enemy.h | 52 ++++++++++++++++-------------------- source/item.cpp | 10 +++---- source/item.h | 15 +++++------ source/room.cpp | 2 +- source/scoreboard.cpp | 38 +++++++++++++------------- source/scoreboard.h | 40 ++++++++++++++-------------- 9 files changed, 121 insertions(+), 157 deletions(-) diff --git a/source/ending2.cpp b/source/ending2.cpp index 8d6fafb..d3d7af7 100644 --- a/source/ending2.cpp +++ b/source/ending2.cpp @@ -10,12 +10,12 @@ #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 "s_moving_sprite.h" // for SMovingSprite #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 "surface.h" // for Surface #include "utils.h" // for Color, stringToColor #include @@ -31,10 +31,10 @@ Ending2::Ending2() options.section.subsection = Subsection::NONE; // Inicializa el vector de colores - const std::vector color_list = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"}; - for (const auto &color : color_list) + const std::vector COLORS = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"}; + for (const auto &color : COLORS) { - colors_.push_back(stringToColor(options.video.palette, color)); + colors_.push_back(stringToColor(color)); } // Cambia el color del borde @@ -97,7 +97,7 @@ void Ending2::update() // Dibuja el final en pantalla void Ending2::render() { - // Prepara para empezar a dibujar en la textura de juego + // Prepara para empezar a dibujar en la surface de juego Screen::get()->start(); // Limpia la pantalla @@ -325,36 +325,33 @@ void Ending2::updateTexts() // Dibuja los sprites void Ending2::renderSprites() { - const Color color = stringToColor(options.video.palette, "red"); + const Uint8 colorA = stringToColor("red"); for (auto sprite : sprites_) { const bool A = sprite->getRect().y + sprite->getRect().h > 0; const bool B = sprite->getRect().y < options.game.height; if (A && B) { - sprite->getTexture()->setColor(color.r, color.g, color.b); - sprite->render(); + sprite->render(1, colorA); } } // Pinta el ultimo elemento de otro color - const Color c = stringToColor(options.video.palette, "white"); - sprites_.back()->getTexture()->setColor(c.r, c.g, c.b); - sprites_.back()->render(); + const Uint8 colorB = stringToColor("white"); + sprites_.back()->render(1, colorB); } // Dibuja los sprites con el texto void Ending2::renderSpriteTexts() { - const Color color = stringToColor(options.video.palette, "white"); + const Uint8 color = stringToColor("white"); for (auto sprite : sprite_texts_) { const bool A = sprite->getRect().y + sprite->getRect().h > 0; const bool B = sprite->getRect().y < options.game.height; if (A && B) { - sprite->getTexture()->setColor(color.r, color.g, color.b); - sprite->render(); + sprite->render(1, color); } } } @@ -424,17 +421,16 @@ void Ending2::createSpriteTexts() // Calcula la posición Y del texto en base a la posición y altura del sprite const int Y = sprites_.at(i)->getPosY() + sprites_.at(i)->getHeight() + DIST_SPRITE_TEXT_; - // Crea la textura - auto texture = std::make_shared(Screen::get()->getRenderer()); - texture->createBlank(W, H); - texture->setAsRenderTarget(Screen::get()->getRenderer()); - texture->setBlendMode(SDL_BLENDMODE_BLEND); + // Crea la surface + auto surface = std::make_shared(Screen::get()->getRenderSurfaceData(), W, H); + Screen::get()->setRenderSurfaceData(surface); text->write(0, 0, txt); // Crea el sprite SDL_Rect pos = {X, Y, W, H}; - sprite_texts_.emplace_back(std::make_shared(texture, pos)); + sprite_texts_.emplace_back(std::make_shared(surface, pos)); sprite_texts_.back()->setVelY(SPRITE_DESP_SPEED_); + Screen::get()->setRenderSurfaceData(nullptr); } } @@ -457,17 +453,16 @@ void Ending2::createTexts() const int dx = -(w / 2); const int y = options.game.height + (text->getCharacterSize() * (i * 2)); - // Crea la textura - auto texture = std::make_shared(Screen::get()->getRenderer()); - texture->createBlank(w, h); - texture->setAsRenderTarget(Screen::get()->getRenderer()); - texture->setBlendMode(SDL_BLENDMODE_BLEND); + // Crea la surface + auto surface = std::make_shared(Screen::get()->getRenderSurfaceData(), w, h); + Screen::get()->setRenderSurfaceData(surface); text->write(0, 0, list[i]); // Crea el sprite SDL_Rect pos = {x + dx, y, w, h}; - texts_.emplace_back(std::make_shared(texture, pos)); + texts_.emplace_back(std::make_shared(surface, pos)); texts_.back()->setVelY(SPRITE_DESP_SPEED_); + Screen::get()->setRenderSurfaceData(nullptr); } // Crea los últimos textos @@ -487,17 +482,16 @@ void Ending2::createTexts() const int dx = -(w / 2); const int y = START + (text->getCharacterSize() * (i * 2)); - // Crea la textura - auto texture = std::make_shared(Screen::get()->getRenderer()); - texture->createBlank(w, h); - texture->setAsRenderTarget(Screen::get()->getRenderer()); - texture->setBlendMode(SDL_BLENDMODE_BLEND); + // Crea la surface + auto surface = std::make_shared(Screen::get()->getRenderSurfaceData(),w, h); + Screen::get()->setRenderSurfaceData(surface); text->write(0, 0, list[i]); // Crea el sprite SDL_Rect pos = {x + dx, y, w, h}; - texts_.emplace_back(std::make_shared(texture, pos)); + texts_.emplace_back(std::make_shared(surface, pos)); texts_.back()->setVelY(SPRITE_DESP_SPEED_); + Screen::get()->setRenderSurfaceData(nullptr); } } @@ -510,7 +504,7 @@ void Ending2::updateFinalFade() for (const auto &text : texts_) { - text->getTexture()->setColor(colors_.at(INDEX).r, colors_.at(INDEX).g, colors_.at(INDEX).b); + //text->getTexture()->setColor(colors_.at(INDEX).r, colors_.at(INDEX).g, colors_.at(INDEX).b); } } diff --git a/source/ending2.h b/source/ending2.h index 920610d..0d2dec0 100644 --- a/source/ending2.h +++ b/source/ending2.h @@ -1,30 +1,28 @@ #pragma once -#include // for Uint32 -#include // for shared_ptr -#include // for string -#include // for vector -#include "defines.h" // for GAMECANVAS_WIDTH, GAMECANVAS_FIRST_QUAR... -#include "utils.h" // for Color -class AnimatedSprite; // lines 10-10 -class MovingSprite; // lines 13-13 +#include // for Uint32 +#include // for shared_ptr +#include // for string +#include // for vector +#include "defines.h" // for GAMECANVAS_WIDTH, GAMECANVAS_FIRST_QUAR... +#include "utils.h" // for Color +class SAnimatedSprite; // lines 10-10 +class SMovingSprite; // lines 13-13 class Ending2 { private: // Constantes - static constexpr int FIRST_COL_ = - GAMECANVAS_FIRST_QUARTER_X + (GAMECANVAS_WIDTH / 16); // Primera columna por donde desfilan los sprites - static constexpr int SECOND_COL_ = - GAMECANVAS_THIRD_QUARTER_X - (GAMECANVAS_WIDTH / 16); // Segunda columna por donde desfilan los sprites - static constexpr int DIST_SPRITE_TEXT_ = 8; // Distancia entre el sprite y el texto que lo acompaña - static constexpr int DIST_SPRITE_SPRITE_ = 0; // Distancia entre dos sprites de la misma columna - static constexpr float SPRITE_DESP_SPEED_ = -0.2f; // Velocidad de desplazamiento de los sprites + static constexpr int FIRST_COL_ = GAMECANVAS_FIRST_QUARTER_X + (GAMECANVAS_WIDTH / 16); // Primera columna por donde desfilan los sprites + static constexpr int SECOND_COL_ = GAMECANVAS_THIRD_QUARTER_X - (GAMECANVAS_WIDTH / 16); // Segunda columna por donde desfilan los sprites + static constexpr int DIST_SPRITE_TEXT_ = 8; // Distancia entre el sprite y el texto que lo acompaña + static constexpr int DIST_SPRITE_SPRITE_ = 0; // Distancia entre dos sprites de la misma columna + static constexpr float SPRITE_DESP_SPEED_ = -0.2f; // Velocidad de desplazamiento de los sprites // Objetos y punteros - std::vector> sprites_; // Vector con todos los sprites a dibujar - std::vector> sprite_texts_; // Vector con los sprites de texto de los sprites - std::vector> texts_; // Vector con los sprites de texto + std::vector> sprites_; // Vector con todos los sprites a dibujar + std::vector> sprite_texts_; // Vector con los sprites de texto de los sprites + std::vector> texts_; // Vector con los sprites de texto // Variables bool counter_enabled_; // Indica si está el contador habilitado @@ -33,7 +31,7 @@ private: bool post_counter_enabled_; // Indica si está habilitado el contador Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa std::vector sprite_list_; // Lista con todos los sprites a dibujar - std::vector colors_; // Vector con los colores para el fade + std::vector colors_; // Vector con los colores para el fade int sprite_max_width_; // El valor de ancho del sprite mas ancho int sprite_max_height_; // El valor de alto del sprite mas alto diff --git a/source/enemy.cpp b/source/enemy.cpp index 20ac9a9..a347efb 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 "s_animated_sprite.h" // for AnimatedSprite +#include "s_animated_sprite.h" // for SAnimatedSprite #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()->getSurface(enemy.texture_path), Resource::get()->getAnimations(enemy.animation_path))), + : sprite_(std::make_shared(Resource::get()->getSurface(enemy.surface_path), Resource::get()->getAnimations(enemy.animation_path))), color_string_(enemy.color), x1_(enemy.x1), x2_(enemy.x2), @@ -33,16 +33,13 @@ Enemy::Enemy(const EnemyData &enemy) collider_ = getRect(); // Coloca un frame al azar o el designado - sprite_->setCurrentAnimationFrame( - (enemy.frame == -1) ? (rand() % sprite_->getCurrentAnimationSize()) : enemy.frame); + sprite_->setCurrentAnimationFrame((enemy.frame == -1) ? (rand() % sprite_->getCurrentAnimationSize()) : enemy.frame); } // Pinta el enemigo en pantalla void Enemy::render() { - sprite_->getTexture()->setColor(color_.r, color_.g, color_.b); - sprite_->render(); - sprite_->getTexture()->setColor(255, 255, 255); + sprite_->render(1, color_); } // Actualiza las variables del objeto @@ -111,16 +108,4 @@ SDL_Rect Enemy::getRect() SDL_Rect &Enemy::getCollider() { return collider_; -} - -// Recarga la textura -void Enemy::reLoadTexture() -{ - sprite_->getTexture()->reLoad(); -} - -// Asigna la paleta -void Enemy::setPalette(Palette pal) -{ - color_ = stringToColor(pal, color_string_); } \ No newline at end of file diff --git a/source/enemy.h b/source/enemy.h index 631f9dd..91ca5ee 100644 --- a/source/enemy.h +++ b/source/enemy.h @@ -1,40 +1,40 @@ #pragma once -#include // for SDL_Rect -#include // for shared_ptr -#include // for string -#include "utils.h" // for Color -class AnimatedSprite; +#include // for SDL_Rect +#include // for shared_ptr +#include // for string +#include "utils.h" // for Color +class SAnimatedSprite; // Estructura para pasar los datos de un enemigo struct EnemyData { - std::string texture_path; // Ruta al fichero con la textura - std::string animation_path; // Ruta al fichero con la animación - int w; // Anchura del enemigo - int h; // Altura del enemigo - float x; // Posición inicial en el eje X - float y; // Posición inicial en el eje Y - float vx; // Velocidad en el eje X - float vy; // Velocidad en el eje Y - int x1; // Limite izquierdo de la ruta en el eje X - int x2; // Limite derecho de la ruta en el eje X - int y1; // Limite superior de la ruta en el eje Y - int y2; // Limite inferior de la ruta en el eje Y - bool flip; // Indica si el enemigo hace flip al terminar su ruta - bool mirror; // Indica si el enemigo está volteado verticalmente - int frame; // Frame inicial para la animación del enemigo - std::string color; // Color del enemigo + std::string surface_path; // Ruta al fichero con la textura + std::string animation_path; // Ruta al fichero con la animación + int w; // Anchura del enemigo + int h; // Altura del enemigo + float x; // Posición inicial en el eje X + float y; // Posición inicial en el eje Y + float vx; // Velocidad en el eje X + float vy; // Velocidad en el eje Y + int x1; // Limite izquierdo de la ruta en el eje X + int x2; // Limite derecho de la ruta en el eje X + int y1; // Limite superior de la ruta en el eje Y + int y2; // Limite inferior de la ruta en el eje Y + bool flip; // Indica si el enemigo hace flip al terminar su ruta + bool mirror; // Indica si el enemigo está volteado verticalmente + int frame; // Frame inicial para la animación del enemigo + std::string color; // Color del enemigo }; class Enemy { private: // Objetos y punteros - std::shared_ptr sprite_; // Sprite del enemigo + std::shared_ptr sprite_; // Sprite del enemigo // Variables - Color color_; // Color del enemigo + Uint8 color_; // Color del enemigo std::string color_string_; // Color del enemigo en formato texto int x1_; // Limite izquierdo de la ruta en el eje X int x2_; // Limite derecho de la ruta en el eje X @@ -65,10 +65,4 @@ public: // Obtiene el rectangulo de colision del enemigo SDL_Rect &getCollider(); - - // Recarga la textura - void reLoadTexture(); - - // Asigna la paleta - void setPalette(Palette pal); }; diff --git a/source/item.cpp b/source/item.cpp index a070427..7ad02f0 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -1,11 +1,11 @@ #include "item.h" #include "resource.h" -#include "s_sprite.h" // Para Sprite +#include "s_sprite.h" // Para SSprite #include "surface.h" // Para Texture // Constructor Item::Item(ItemData item) - : sprite_(std::make_shared(Resource::get()->getSurface(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 @@ -25,9 +25,7 @@ Item::Item(ItemData item) void Item::render() { const int INDEX = (counter_ / change_color_speed) % color_.size(); - sprite_->getTexture()->setColor(color_.at(INDEX).r, color_.at(INDEX).g, color_.at(INDEX).b); - sprite_->render(); - sprite_->getTexture()->setColor(255, 255, 255); + sprite_->render(1, color_.at(INDEX)); } // Obtiene su ubicación @@ -38,7 +36,7 @@ SDL_Point Item::getPos() } // Asigna los colores del objeto -void Item::setColors(Color col1, Color col2) +void Item::setColors(Uint8 col1, Uint8 col2) { // Reinicializa el vector de colores color_.clear(); diff --git a/source/item.h b/source/item.h index 3cf2d04..068bdf6 100644 --- a/source/item.h +++ b/source/item.h @@ -4,7 +4,7 @@ #include // for shared_ptr, __shared_ptr_access #include // for string #include // for vector -#include "s_sprite.h" // for Sprite +#include "s_sprite.h" // for SSprite #include "surface.h" // for Texture #include "utils.h" // for Color @@ -15,8 +15,8 @@ struct ItemData int y; // Posición del item en pantalla int tile; // Número de tile dentro de la textura int counter; // Contador inicial. Es el que lo hace cambiar de color - Color color1; // Uno de los dos colores que se utiliza para el item - Color color2; // Uno de los dos colores que se utiliza para el item + Uint8 color1; // Uno de los dos colores que se utiliza para el item + Uint8 color2; // Uno de los dos colores que se utiliza para el item // Constructor ItemData() : x(0), y(0), tile(0), counter(0), color1(), color2() {} @@ -29,10 +29,10 @@ private: static constexpr int ITEM_SIZE_ = 8; // Objetos y punteros - std::shared_ptr sprite_; // Sprite del objeto + std::shared_ptr sprite_; // SSprite del objeto // Variables - std::vector color_; // Vector con los colores del objeto + std::vector color_; // Vector con los colores del objeto int counter_; // Contador interno SDL_Rect collider_; // Rectangulo de colisión int change_color_speed; // Cuanto mas alto, mas tarda en cambiar de color @@ -56,9 +56,6 @@ public: // Obtiene su ubicación SDL_Point getPos(); - // Recarga la textura - void reLoadTexture() { sprite_->getTexture()->reLoad(); } - // Asigna los colores del objeto - void setColors(Color col1, Color col2); + void setColors(Uint8 col1, Uint8 col2); }; \ No newline at end of file diff --git a/source/room.cpp b/source/room.cpp index 7587a4e..c6f77ba 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -272,7 +272,7 @@ bool setEnemy(EnemyData *enemy, const std::string &key, const std::string &value { if (key == "tileSetFile") { - enemy->texture_path = value; + enemy->surface_path = value; } else if (key == "animation") { diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index 4849934..48f955e 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -4,7 +4,7 @@ #include // for SDL_Rect #include // for SDL_GetTicks #include // for basic_ostream, operator<<, cout, endl -#include "s_animated_sprite.h" // for AnimatedSprite +#include "s_animated_sprite.h" // for SAnimatedSprite #include "defines.h" // for BLOCK #include "options.h" // for Options, options, OptionsVideo, Cheat #include "resource.h" // for Resource @@ -21,14 +21,14 @@ Scoreboard::Scoreboard(std::shared_ptr data) constexpr int TEXTURE_HEIGHT_ = 6 * BLOCK; // Reserva memoria para los objetos - item_texture_ = Resource::get()->getSurface("items.gif"); + item_surface_ = 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_ = std::make_shared(player_texture, player_animations); player_sprite_->setCurrentAnimation("walk_menu"); - texture_ = createTexture(Screen::get()->getRenderer(), TEXTURE_WIDTH_, TEXTURE_HEIGHT_); - texture_dest_ = {0, options.game.height - TEXTURE_HEIGHT_, TEXTURE_WIDTH_, TEXTURE_HEIGHT_}; + surface_ = createTexture(Screen::get()->getRenderer(), TEXTURE_WIDTH_, TEXTURE_HEIGHT_); + surface_dest_ = {0, options.game.height - TEXTURE_HEIGHT_, TEXTURE_WIDTH_, TEXTURE_HEIGHT_}; // Inicializa las variables counter_ = 0; @@ -36,26 +36,26 @@ Scoreboard::Scoreboard(std::shared_ptr data) is_paused_ = false; paused_time_ = 0; paused_time_elapsed_ = 0; - items_color_ = stringToColor(options.video.palette, "white"); + items_color_ = stringToColor("white"); // Inicializa el vector de colores const std::vector COLORS = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"}; for (const auto &color : COLORS) { - color_.push_back(stringToColor(options.video.palette, color)); + color_.push_back(stringToColor(color)); } } // Destructor Scoreboard::~Scoreboard() { - SDL_DestroyTexture(texture_); + SDL_DestroyTexture(surface_); } // Pinta el objeto en pantalla void Scoreboard::render() { - SDL_RenderCopy(Screen::get()->getRenderer(), texture_, nullptr, &texture_dest_); + SDL_RenderCopy(Screen::get()->getRenderer(), surface_, nullptr, &surface_dest_); } // Actualiza las variables del objeto @@ -124,11 +124,11 @@ void Scoreboard::updateItemsColor() if (counter_ % 20 < 10) { - items_color_ = stringToColor(options.video.palette, "white"); + items_color_ = stringToColor("white"); } else { - items_color_ = stringToColor(options.video.palette, "magenta"); + items_color_ = stringToColor("magenta"); } } @@ -143,7 +143,7 @@ void Scoreboard::fillTexture() { // Empieza a dibujar en la textura auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer()); - SDL_SetRenderTarget(Screen::get()->getRenderer(), texture_); + SDL_SetRenderTarget(Screen::get()->getRenderer(), surface_); // Limpia la textura SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 255); @@ -162,17 +162,15 @@ void Scoreboard::fillTexture() { player_sprite_->setPosX(8 + (16 * i) + desp); const int index = i % color_.size(); - player_sprite_->getTexture()->setColor(color_[index].r, color_[index].g, color_[index].b); - player_sprite_->render(); + player_sprite_->render(1, color_.at(index)); } // Muestra si suena la música if (data_->music) { - const Color c = data_->color; + const Uint8 c = data_->color; SDL_Rect clip = {0, 8, 8, 8}; - item_texture_->setColor(c.r, c.g, c.b); - item_texture_->render(20 * BLOCK, LINE2, &clip); + item_surface_->renderWithColorReplace(20 * BLOCK, LINE2, 1, c, &clip); } // Escribe los textos @@ -182,11 +180,11 @@ void Scoreboard::fillTexture() 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")); + text->writeColored(26 * BLOCK, LINE1, TIME_TEXT, stringToColor("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")); + text->writeColored(22 * BLOCK, LINE2, "Rooms", stringToColor("white")); + text->writeColored(28 * BLOCK, LINE2, ROOMS_TEXT, stringToColor("white")); // Deja el renderizador como estaba SDL_SetRenderTarget(Screen::get()->getRenderer(), temp); diff --git a/source/scoreboard.h b/source/scoreboard.h index 5b94ed0..cd2282a 100644 --- a/source/scoreboard.h +++ b/source/scoreboard.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, basic_string -#include // for vector -#include "utils.h" // for Color -class AnimatedSprite; // lines 9-9 -class Texture; // lines 13-13 +#include // for SDL_Rect +#include // for SDL_Texture +#include // for Uint32 +#include // for shared_ptr +#include // for string, basic_string +#include // for vector +#include "utils.h" // for Color +class SAnimatedSprite; // lines 9-9 +class Surface; // lines 13-13 struct ScoreboardData { @@ -16,16 +16,16 @@ struct ScoreboardData int lives; // Lleva la cuenta de las vidas restantes del jugador int rooms; // Lleva la cuenta de las habitaciones visitadas bool music; // Indica si ha de sonar la música durante el juego - Color color; // Color para escribir el texto del marcador + Uint8 color; // Color para escribir el texto del marcador Uint32 ini_clock; // Tiempo inicial para calcular el tiempo transcurrido bool jail_is_open; // Indica si se puede entrar a la Jail // Constructor por defecto ScoreboardData() - : items(0), lives(0), rooms(0), music(true), color({0, 0, 0}), ini_clock(0), jail_is_open(false) {} + : items(0), lives(0), rooms(0), music(true), color(0), ini_clock(0), jail_is_open(false) {} // Constructor parametrizado - ScoreboardData(int items, int lives, int rooms, bool music, Color color, Uint32 ini_clock, bool jail_is_open) + ScoreboardData(int items, int lives, int rooms, bool music, Uint8 color, Uint32 ini_clock, bool jail_is_open) : items(items), lives(lives), rooms(rooms), music(music), color(color), ini_clock(ini_clock), jail_is_open(jail_is_open) {} }; @@ -49,21 +49,21 @@ private: }; // Objetos y punteros - 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 - SDL_Texture *texture_; // Textura donde dibujar el marcador; + std::shared_ptr player_sprite_; // Sprite para mostrar las vidas en el marcador + std::shared_ptr item_surface_; // Surface con los graficos para los elementos del marcador + std::shared_ptr data_; // Contiene las variables a mostrar en el marcador + SDL_Texture *surface_; // Surface donde dibujar el marcador; // Variables - std::vector color_; // Vector con los colores del objeto + std::vector color_; // Vector con los colores del objeto int counter_; // Contador interno int change_color_speed_; // Cuanto mas alto, mas tarda en cambiar de color bool is_paused_; // Indica si el marcador esta en modo pausa Uint32 paused_time_; // Milisegundos que ha estado el marcador en pausa Uint32 paused_time_elapsed_; // Tiempo acumulado en pausa ClockData clock_; // Contiene las horas, minutos y segundos transcurridos desde el inicio de la partida - Color items_color_; // Color de la cantidad de items recogidos - SDL_Rect texture_dest_; // Rectangulo donde dibujar la textura del marcador + Uint8 items_color_; // Color de la cantidad de items recogidos + SDL_Rect surface_dest_; // Rectangulo donde dibujar la surface del marcador // Obtiene el tiempo transcurrido de partida ClockData getTime(); @@ -71,7 +71,7 @@ private: // Actualiza el color de la cantidad de items recogidos void updateItemsColor(); - // Dibuja los elementos del marcador en la textura + // Dibuja los elementos del marcador en la surface void fillTexture(); public: