Arreglos en la estructura i format del codi

This commit is contained in:
2025-03-01 20:39:44 +01:00
parent 5c371e7517
commit 360ebfd2e6
12 changed files with 126 additions and 156 deletions

View File

@@ -10,7 +10,7 @@ constexpr const char *TEXT_COPYRIGHT = "@2022 JailDesigner";
constexpr const char *VERSION = "1.10"; constexpr const char *VERSION = "1.10";
// Velocidad del juego // Velocidad del juego
constexpr Uint32 GAME_SPEED = 1000 / 60; constexpr Uint32 GAME_SPEED = 15;
// Tamaño de bloque // Tamaño de bloque
constexpr int BLOCK = 8; constexpr int BLOCK = 8;

View File

@@ -21,25 +21,14 @@
// Constructor // Constructor
Ending2::Ending2() Ending2::Ending2()
: screen_(Screen::get()), : counter_enabled_(false),
renderer_(Screen::get()->getRenderer()), pre_counter_(0),
resource_(Resource::get()), post_counter_(0),
asset_(Asset::get()), post_counter_enabled_(false),
input_(Input::get()), ticks_(0)
text_(resource_->getText("smb2")),
music_(resource_->getMusic("ending2.ogg"))
{ {
// Inicializa variables
counter_enabled_ = false;
pre_counter_ = 0;
post_counter_ = 0;
post_counter_enabled_ = false;
options.section.section = Section::ENDING2; options.section.section = Section::ENDING2;
options.section.subsection = Subsection::NONE; options.section.subsection = Subsection::NONE;
ticks_ = 0;
dist_sprite_text_ = 8;
dist_sprite_sprite_ = 0;
sprite_desp_speed_ = -0.2f;
// Inicializa el vector de colores // Inicializa el vector de colores
const std::vector<std::string> color_list = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"}; const std::vector<std::string> color_list = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
@@ -49,7 +38,7 @@ Ending2::Ending2()
} }
// Cambia el color del borde // Cambia el color del borde
screen_->setBorderColor(stringToColor(options.video.palette, "black")); Screen::get()->setBorderColor(stringToColor(options.video.palette, "black"));
// Inicializa la lista de sprites // Inicializa la lista de sprites
iniSpriteList(); iniSpriteList();
@@ -100,7 +89,8 @@ void Ending2::update()
// Actualiza el volumen de la musica // Actualiza el volumen de la musica
updateMusicVolume(); updateMusicVolume();
screen_->update(); // Actualiza el objeto
Screen::get()->update();
} }
} }
@@ -108,10 +98,10 @@ void Ending2::update()
void Ending2::render() void Ending2::render()
{ {
// Prepara para empezar a dibujar en la textura de juego // Prepara para empezar a dibujar en la textura de juego
screen_->start(); Screen::get()->start();
// Limpia la pantalla // Limpia la pantalla
screen_->clean(stringToColor(options.video.palette, "black")); Screen::get()->clean(stringToColor(options.video.palette, "black"));
// Dibuja los sprites // Dibuja los sprites
renderSprites(); renderSprites();
@@ -123,28 +113,28 @@ void Ending2::render()
renderTexts(); renderTexts();
// Dibuja una trama arriba y abajo // Dibuja una trama arriba y abajo
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0xFF);
for (int i = 0; i < 256; i += 2) for (int i = 0; i < 256; i += 2)
{ {
SDL_RenderDrawPoint(renderer_, i + 0, 0); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 0, 0);
SDL_RenderDrawPoint(renderer_, i + 1, 1); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 1);
SDL_RenderDrawPoint(renderer_, i + 0, 2); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 0, 2);
SDL_RenderDrawPoint(renderer_, i + 1, 3); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 3);
SDL_RenderDrawPoint(renderer_, i, 4); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 4);
SDL_RenderDrawPoint(renderer_, i, 6); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 6);
SDL_RenderDrawPoint(renderer_, i + 0, 191); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 0, 191);
SDL_RenderDrawPoint(renderer_, i + 1, 190); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 190);
SDL_RenderDrawPoint(renderer_, i + 0, 189); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 0, 189);
SDL_RenderDrawPoint(renderer_, i + 1, 188); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, 188);
SDL_RenderDrawPoint(renderer_, i, 187); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 187);
SDL_RenderDrawPoint(renderer_, i, 185); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 185);
} }
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
screen_->render(); Screen::get()->render();
} }
// Comprueba el manejador de eventos // Comprueba el manejador de eventos
@@ -166,7 +156,7 @@ void Ending2::checkInput()
// Bucle principal // Bucle principal
void Ending2::run() void Ending2::run()
{ {
JA_PlayMusic(music_); JA_PlayMusic(Resource::get()->getMusic("ending2.ogg"));
while (options.section.section == Section::ENDING2) while (options.section.section == Section::ENDING2)
{ {
@@ -292,7 +282,7 @@ void Ending2::loadSprites()
// Carga los sprites // Carga los sprites
for (const auto &sl : sprite_list_) for (const auto &sl : sprite_list_)
{ {
sprites_.emplace_back(std::make_shared<AnimatedSprite>(resource_->getTexture(sl + ".png"), resource_->getAnimations(sl + ".ani"))); sprites_.emplace_back(std::make_shared<AnimatedSprite>(Resource::get()->getTexture(sl + ".png"), Resource::get()->getAnimations(sl + ".ani")));
sprite_max_width_ = std::max(sprites_.back()->getWidth(), sprite_max_width_); sprite_max_width_ = std::max(sprites_.back()->getWidth(), sprite_max_width_);
sprite_max_height_ = std::max(sprites_.back()->getHeight(), sprite_max_height_); sprite_max_height_ = std::max(sprites_.back()->getHeight(), sprite_max_height_);
} }
@@ -389,14 +379,14 @@ void Ending2::placeSprites()
for (int i = 0; i < (int)sprites_.size(); ++i) for (int i = 0; i < (int)sprites_.size(); ++i)
{ {
const int X = i % 2 == 0 ? FIRST_COL_ : SECOND_COL_; const int X = i % 2 == 0 ? FIRST_COL_ : SECOND_COL_;
const int Y = (i / 1) * (sprite_max_height_ + dist_sprite_text_ + text_->getCharacterSize() + dist_sprite_sprite_) + GAMECANVAS_HEIGHT + 40; const int Y = (i / 1) * (sprite_max_height_ + DIST_SPRITE_TEXT_ + Resource::get()->getText("smb2")->getCharacterSize() + DIST_SPRITE_SPRITE_) + GAMECANVAS_HEIGHT + 40;
const int W = sprites_.at(i)->getWidth(); const int W = sprites_.at(i)->getWidth();
const int H = sprites_.at(i)->getHeight(); const int H = sprites_.at(i)->getHeight();
const int DX = -(W / 2); const int DX = -(W / 2);
const int DY = sprite_max_height_ - H; const int DY = sprite_max_height_ - H;
sprites_.at(i)->setPosition({X + DX, Y + DY, W, H}); sprites_.at(i)->setPosition({X + DX, Y + DY, W, H});
sprites_.at(i)->setVelY(sprite_desp_speed_); sprites_.at(i)->setVelY(SPRITE_DESP_SPEED_);
} }
// Recoloca el último sprite, que es el del jugador // Recoloca el último sprite, que es el del jugador
@@ -412,32 +402,41 @@ void Ending2::placeSprites()
void Ending2::createSpriteTexts() void Ending2::createSpriteTexts()
{ {
// Crea los sprites de texto a partir de la lista // Crea los sprites de texto a partir de la lista
for (int i = 0; i < (int)sprite_list_.size(); ++i) for (int i = 0; i < static_cast<int>(sprite_list_.size()); ++i)
{ {
// Calcula constantes auto text = Resource::get()->getText("smb2");
std::string txt = sprite_list_[i];
std::replace(txt.begin(), txt.end(), '_', ' ');
txt = txt == "player" ? "JAILDOCTOR" : txt; // Reemplaza el texto
const int w = text_->lenght(txt, 1);
const int h = text_->getCharacterSize();
const int x = i % 2 == 0 ? FIRST_COL_ : SECOND_COL_;
const int dx = -(w / 2);
const int y = sprites_.at(i)->getPosY() + sprites_.at(i)->getHeight() + dist_sprite_text_;
// Cambia la posición del último sprite // Procesa y ajusta el texto del sprite actual
const int X = (i == (int)sprite_list_.size() - 1) ? GAMECANVAS_CENTER_X - (w / 2) : x + dx; std::string txt = sprite_list_[i];
std::replace(txt.begin(), txt.end(), '_', ' '); // Reemplaza '_' por ' '
if (txt == "player")
{
txt = "JAILDOCTOR"; // Reemplaza "player" por "JAILDOCTOR"
}
// Calcula las dimensiones del texto
const int W = text->lenght(txt, 1);
const int H = text->getCharacterSize();
// Determina la columna y la posición X del texto
const int X = (i == static_cast<int>(sprite_list_.size()) - 1)
? (GAMECANVAS_CENTER_X - (W / 2))
: ((i % 2 == 0 ? FIRST_COL_ : SECOND_COL_) - (W / 2));
// 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 // Crea la textura
auto texture = std::make_shared<Texture>(renderer_); auto texture = std::make_shared<Texture>(Screen::get()->getRenderer());
texture->createBlank(w, h); texture->createBlank(W, H);
texture->setAsRenderTarget(renderer_); texture->setAsRenderTarget(Screen::get()->getRenderer());
texture->setBlendMode(SDL_BLENDMODE_BLEND); texture->setBlendMode(SDL_BLENDMODE_BLEND);
text_->write(0, 0, txt); text->write(0, 0, txt);
// Crea el sprite // Crea el sprite
SDL_Rect pos = {X, y, w, h}; SDL_Rect pos = {X, Y, W, H};
sprite_texts_.emplace_back(std::make_shared<MovingSprite>(texture, pos)); sprite_texts_.emplace_back(std::make_shared<MovingSprite>(texture, pos));
sprite_texts_.back()->setVelY(sprite_desp_speed_); sprite_texts_.back()->setVelY(SPRITE_DESP_SPEED_);
} }
} }
@@ -448,32 +447,34 @@ void Ending2::createTexts()
std::vector<std::string> list; std::vector<std::string> list;
list.push_back("STARRING"); list.push_back("STARRING");
auto text = Resource::get()->getText("smb2");
// Crea los sprites de texto a partir de la lista // Crea los sprites de texto a partir de la lista
for (int i = 0; i < (int)list.size(); ++i) for (int i = 0; i < (int)list.size(); ++i)
{ {
// Calcula constantes // Calcula constantes
const int w = text_->lenght(list[i], 1); const int w = text->lenght(list[i], 1);
const int h = text_->getCharacterSize(); const int h = text->getCharacterSize();
const int x = GAMECANVAS_CENTER_X; const int x = GAMECANVAS_CENTER_X;
const int dx = -(w / 2); const int dx = -(w / 2);
const int y = GAMECANVAS_HEIGHT + (text_->getCharacterSize() * (i * 2)); const int y = GAMECANVAS_HEIGHT + (text->getCharacterSize() * (i * 2));
// Crea la textura // Crea la textura
auto texture = std::make_shared<Texture>(renderer_); auto texture = std::make_shared<Texture>(Screen::get()->getRenderer());
texture->createBlank(w, h); texture->createBlank(w, h);
texture->setAsRenderTarget(renderer_); texture->setAsRenderTarget(Screen::get()->getRenderer());
texture->setBlendMode(SDL_BLENDMODE_BLEND); texture->setBlendMode(SDL_BLENDMODE_BLEND);
text_->write(0, 0, list[i]); text->write(0, 0, list[i]);
// Crea el sprite // Crea el sprite
SDL_Rect pos = {x + dx, y, w, h}; SDL_Rect pos = {x + dx, y, w, h};
texts_.emplace_back(std::make_shared<MovingSprite>(texture, pos)); texts_.emplace_back(std::make_shared<MovingSprite>(texture, pos));
texts_.back()->setVelY(sprite_desp_speed_); texts_.back()->setVelY(SPRITE_DESP_SPEED_);
} }
// Crea los últimos textos // Crea los últimos textos
// El primer texto va a continuación del ultimo spriteText // El primer texto va a continuación del ultimo spriteText
const int start = sprite_texts_.back()->getPosY() + text_->getCharacterSize() * 15; const int start = sprite_texts_.back()->getPosY() + text->getCharacterSize() * 15;
list.clear(); list.clear();
list.push_back("THANK YOU"); list.push_back("THANK YOU");
list.push_back("FOR PLAYING!"); list.push_back("FOR PLAYING!");
@@ -482,23 +483,23 @@ void Ending2::createTexts()
for (int i = 0; i < (int)list.size(); ++i) for (int i = 0; i < (int)list.size(); ++i)
{ {
// Calcula constantes // Calcula constantes
const int w = text_->lenght(list[i], 1); const int w = text->lenght(list[i], 1);
const int h = text_->getCharacterSize(); const int h = text->getCharacterSize();
const int x = GAMECANVAS_CENTER_X; const int x = GAMECANVAS_CENTER_X;
const int dx = -(w / 2); const int dx = -(w / 2);
const int y = start + (text_->getCharacterSize() * (i * 2)); const int y = start + (text->getCharacterSize() * (i * 2));
// Crea la textura // Crea la textura
auto texture = std::make_shared<Texture>(renderer_); auto texture = std::make_shared<Texture>(Screen::get()->getRenderer());
texture->createBlank(w, h); texture->createBlank(w, h);
texture->setAsRenderTarget(renderer_); texture->setAsRenderTarget(Screen::get()->getRenderer());
texture->setBlendMode(SDL_BLENDMODE_BLEND); texture->setBlendMode(SDL_BLENDMODE_BLEND);
text_->write(0, 0, list[i]); text->write(0, 0, list[i]);
// Crea el sprite // Crea el sprite
SDL_Rect pos = {x + dx, y, w, h}; SDL_Rect pos = {x + dx, y, w, h};
texts_.emplace_back(std::make_shared<MovingSprite>(texture, pos)); texts_.emplace_back(std::make_shared<MovingSprite>(texture, pos));
texts_.back()->setVelY(sprite_desp_speed_); texts_.back()->setVelY(SPRITE_DESP_SPEED_);
} }
} }
@@ -506,12 +507,12 @@ void Ending2::createTexts()
void Ending2::updateFinalFade() void Ending2::updateFinalFade()
{ {
// La variable step va de 0 a 40 en el tramo de postCounter que va de 500 a 540. Al dividirlo por 40, va de 0.0f a 1.0f // La variable step va de 0 a 40 en el tramo de postCounter que va de 500 a 540. Al dividirlo por 40, va de 0.0f a 1.0f
const float step = std::min(std::max(post_counter_, 500) - 500, 40) / 40.0f; const float STEP = std::min(std::max(post_counter_, 500) - 500, 40) / 40.0f;
const int index = (colors_.size() - 1) * step; const int INDEX = (colors_.size() - 1) * STEP;
for (const auto &t : texts_) for (const auto &text : texts_)
{ {
t->getTexture()->setColor(colors_[index].r, colors_[index].g, colors_[index].b); text->getTexture()->setColor(colors_.at(INDEX).r, colors_.at(INDEX).g, colors_.at(INDEX).b);
} }
} }

View File

@@ -20,16 +20,15 @@ class Ending2
{ {
private: private:
// Constantes // Constantes
static constexpr int FIRST_COL_ = GAMECANVAS_FIRST_QUARTER_X + (GAMECANVAS_WIDTH / 16); // Primera columna por donde desfilan los sprites static constexpr int FIRST_COL_ =
static constexpr int SECOND_COL_ = GAMECANVAS_THIRD_QUARTER_X - (GAMECANVAS_WIDTH / 16); // Segunda columna por donde desfilan los sprites 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 // 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> text_; // Objeto para escribir texto en pantalla
std::vector<std::shared_ptr<AnimatedSprite>> sprites_; // Vector con todos los sprites a dibujar std::vector<std::shared_ptr<AnimatedSprite>> sprites_; // Vector con todos los sprites a dibujar
std::vector<std::shared_ptr<MovingSprite>> sprite_texts_; // Vector con los sprites de texto de los sprites std::vector<std::shared_ptr<MovingSprite>> sprite_texts_; // Vector con los sprites de texto de los sprites
std::vector<std::shared_ptr<MovingSprite>> texts_; // Vector con los sprites de texto std::vector<std::shared_ptr<MovingSprite>> texts_; // Vector con los sprites de texto
@@ -40,14 +39,10 @@ private:
int post_counter_; // Contador posterior int post_counter_; // Contador posterior
bool post_counter_enabled_; // Indica si está habilitado el contador bool post_counter_enabled_; // Indica si está habilitado el contador
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
JA_Music_t *music_; // Musica que suena durante el final
std::vector<std::string> sprite_list_; // Lista con todos los sprites a dibujar std::vector<std::string> sprite_list_; // Lista con todos los sprites a dibujar
std::vector<Color> colors_; // Vector con los colores para el fade std::vector<Color> colors_; // Vector con los colores para el fade
int sprite_max_width_; // El valor de ancho del sprite mas ancho int sprite_max_width_; // El valor de ancho del sprite mas ancho
int sprite_max_height_; // El valor de alto del sprite mas alto int sprite_max_height_; // El valor de alto del sprite mas alto
int dist_sprite_text_; // Distancia entre el sprite y el texto que lo acompaña
int dist_sprite_sprite_; // Distancia entre dos sprites de la misma columna
float sprite_desp_speed_; // Velocidad de desplazamiento de los sprites
// Actualiza el objeto // Actualiza el objeto
void update(); void update();

View File

@@ -7,7 +7,7 @@
#include "texture.h" // for Texture #include "texture.h" // for Texture
// Constructor // Constructor
Enemy::Enemy(const EnemyData enemy) Enemy::Enemy(const EnemyData &enemy)
: sprite_(std::make_shared<AnimatedSprite>(Resource::get()->getTexture(enemy.texture_path), Resource::get()->getAnimations(enemy.animation_path))), : sprite_(std::make_shared<AnimatedSprite>(Resource::get()->getTexture(enemy.texture_path), Resource::get()->getAnimations(enemy.animation_path))),
color_string_(enemy.color), color_string_(enemy.color),
x1_(enemy.x1), x1_(enemy.x1),

View File

@@ -49,7 +49,7 @@ private:
public: public:
// Constructor // Constructor
explicit Enemy(const EnemyData enemy); explicit Enemy(const EnemyData &enemy);
// Destructor // Destructor
~Enemy() = default; ~Enemy() = default;

View File

@@ -32,13 +32,16 @@ Game::Game()
scoreboard_(std::make_shared<Scoreboard>(board_)), scoreboard_(std::make_shared<Scoreboard>(board_)),
room_tracker_(std::make_shared<RoomTracker>()), room_tracker_(std::make_shared<RoomTracker>()),
stats_(std::make_shared<Stats>(Asset::get()->get("stats.csv"), Asset::get()->get("stats_buffer.csv"))), stats_(std::make_shared<Stats>(Asset::get()->get("stats.csv"), Asset::get()->get("stats_buffer.csv"))),
// test_surface_(std::make_shared<Surface>(Screen::get()->getSurface(), "test.gif")), #ifdef DEBUG
current_room_("03.room"),
spawn_point_(PlayerSpawn(25 * BLOCK, 13 * BLOCK, 0, 0, 0, PlayerState::STANDING, SDL_FLIP_HORIZONTAL)) spawn_point_(PlayerSpawn(25 * BLOCK, 13 * BLOCK, 0, 0, 0, PlayerState::STANDING, SDL_FLIP_HORIZONTAL))
#else
current_room_("03.room"),
spawn_point_(PlayerSpawn(25 * BLOCK, 13 * BLOCK, 0, 0, 0, PlayerState::STANDING, SDL_FLIP_HORIZONTAL))
#endif
{ {
#ifdef DEBUG #ifdef DEBUG
current_room_ = "03.room"; Debug::get()->setEnabled(false);
spawn_point_ = PlayerSpawn(25 * BLOC, 13 * BLOCK, 0, 0, 0, PlayerState::STANDING, SDL_FLIP_HORIZONTAL);
debug_->setEnabled(false);
#endif #endif
// Crea objetos e inicializa variables // Crea objetos e inicializa variables
@@ -127,7 +130,7 @@ void Game::update()
checkInput(); checkInput();
#ifdef DEBUG #ifdef DEBUG
debug_->clear(); Debug::get()->clear();
#endif #endif
// Actualiza los objetos // Actualiza los objetos
@@ -182,15 +185,15 @@ void Game::render()
// Pasa la información de debug // Pasa la información de debug
void Game::updateDebugInfo() void Game::updateDebugInfo()
{ {
debug_->add("X = " + std::to_string(static_cast<int>(player_->x_)) + ", Y = " + std::to_string(static_cast<int>(player_->y_))); Debug::get()->add("X = " + std::to_string(static_cast<int>(player_->x_)) + ", Y = " + std::to_string(static_cast<int>(player_->y_)));
debug_->add("VX = " + std::to_string(player_->vx_).substr(0, 4) + ", VY = " + std::to_string(player_->vy_).substr(0, 4)); Debug::get()->add("VX = " + std::to_string(player_->vx_).substr(0, 4) + ", VY = " + std::to_string(player_->vy_).substr(0, 4));
debug_->add("STATE = " + std::to_string(static_cast<int>(player_->state_))); Debug::get()->add("STATE = " + std::to_string(static_cast<int>(player_->state_)));
} }
// Pone la información de debug en pantalla // Pone la información de debug en pantalla
void Game::renderDebugInfo() void Game::renderDebugInfo()
{ {
if (!debug_->getEnabled()) if (!Debug::get()->getEnabled())
{ {
return; return;
} }
@@ -212,8 +215,8 @@ void Game::renderDebugInfo()
} }
// Pinta el texto // Pinta el texto
debug_->setPos({1, 18 * 8}); Debug::get()->setPos({1, 18 * 8});
debug_->render(); Debug::get()->render();
} }
// Comprueba los eventos // Comprueba los eventos
@@ -639,7 +642,7 @@ void Game::checkEndGameCheevos()
} }
// Inicializa al jugador // Inicializa al jugador
void Game::initPlayer(PlayerSpawn spawn_point, std::shared_ptr<Room> room) void Game::initPlayer(const PlayerSpawn &spawn_point, std::shared_ptr<Room> 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.png" : "player.png";
std::string player_animations = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani"; std::string player_animations = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";

View File

@@ -8,7 +8,6 @@
#include "player.h" // Para playerSpawn_t #include "player.h" // Para playerSpawn_t
#include "scoreboard.h" // Para board_t #include "scoreboard.h" // Para board_t
#include "room.h" #include "room.h"
// #include "surface.h"
class Asset; class Asset;
class Cheevos; class Cheevos;
class Debug; class Debug;
@@ -36,17 +35,16 @@ private:
std::shared_ptr<Player> player_; // Objeto con el jugador std::shared_ptr<Player> player_; // Objeto con el jugador
std::shared_ptr<Stats> stats_; // Objeto encargado de gestionar las estadísticas std::shared_ptr<Stats> stats_; // Objeto encargado de gestionar las estadísticas
SDL_Texture *room_name_texture_; // Textura para escribir el nombre de la habitación SDL_Texture *room_name_texture_; // Textura para escribir el nombre de la habitación
// std::shared_ptr<Surface> test_surface_;
// Variables // Variables
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
std::string current_room_ = "03.room"; // Fichero de la habitación actual std::string current_room_; // Fichero de la habitación actual
PlayerSpawn spawn_point_; // Lugar de la habitación donde aparece el jugador PlayerSpawn spawn_point_; // Lugar de la habitación donde aparece el jugador
bool paused_ = false; // Indica si el juego se encuentra en pausa bool paused_ = false; // Indica si el juego se encuentra en pausa
bool black_screen_ = false; // Indica si la pantalla está en negro. Se utiliza para la muerte del jugador bool black_screen_ = false; // Indica si la pantalla está en negro. Se utiliza para la muerte del jugador
int black_screen_counter_ = 0; // Contador para temporizar la pantalla en negro int black_screen_counter_ = 0; // Contador para temporizar la pantalla en negro
int total_items_; // Cantidad total de items que hay en el mapeado del juego int total_items_; // Cantidad total de items que hay en el mapeado del juego
SDL_Rect room_name_rect_; // Rectangulo donde pintar la textura con el nombre de la habitación SDL_Rect room_name_rect_; // Rectangulo donde pintar la textura con el nombre de la habitación
// Actualiza el juego, las variables, comprueba la entrada, etc. // Actualiza el juego, las variables, comprueba la entrada, etc.
void update(); void update();
@@ -132,7 +130,7 @@ private:
void checkEndGameCheevos(); void checkEndGameCheevos();
// Inicializa al jugador // Inicializa al jugador
void initPlayer(PlayerSpawn spawn_point, std::shared_ptr<Room> room); void initPlayer(const PlayerSpawn &spawn_point, std::shared_ptr<Room> room);
// Crea la textura para poner el nombre de la habitación // Crea la textura para poner el nombre de la habitación
void createRoomNameTexture(); void createRoomNameTexture();

View File

@@ -212,10 +212,10 @@ struct OptionsStats
worst_nightmare("") {} worst_nightmare("") {}
// Constructor // Constructor
OptionsStats(int r, int i, const std::string wn) OptionsStats(int rooms, int items, const std::string &worst_nightmare)
: rooms(r), : rooms(rooms),
items(i), items(items),
worst_nightmare(wn) {} worst_nightmare(worst_nightmare) {}
}; };
// Estructura con opciones de la ventana // Estructura con opciones de la ventana

View File

@@ -1415,11 +1415,11 @@ bool Room::checkAutoSurfaces(SDL_Point *p)
} }
// Comprueba las colisiones // Comprueba las colisiones
int Room::checkLeftSlopes(v_line_t *line) int Room::checkLeftSlopes(const v_line_t *line)
{ {
for (auto s : left_slopes_) for (auto slope : left_slopes_)
{ {
const SDL_Point p = checkCollision(s, *line); const SDL_Point p = checkCollision(slope, *line);
if (p.x != -1) if (p.x != -1)
{ {
return p.y; return p.y;
@@ -1432,9 +1432,9 @@ int Room::checkLeftSlopes(v_line_t *line)
// Comprueba las colisiones // Comprueba las colisiones
bool Room::checkLeftSlopes(SDL_Point *p) bool Room::checkLeftSlopes(SDL_Point *p)
{ {
for (auto s : left_slopes_) for (auto slope : left_slopes_)
{ {
if (checkCollision(*p, s)) if (checkCollision(*p, slope))
{ {
return true; return true;
} }
@@ -1444,11 +1444,11 @@ bool Room::checkLeftSlopes(SDL_Point *p)
} }
// Comprueba las colisiones // Comprueba las colisiones
int Room::checkRightSlopes(v_line_t *line) int Room::checkRightSlopes(const v_line_t *line)
{ {
for (auto s : right_slopes_) for (auto slope : right_slopes_)
{ {
const SDL_Point p = checkCollision(s, *line); const SDL_Point p = checkCollision(slope, *line);
if (p.x != -1) if (p.x != -1)
{ {
return p.y; return p.y;
@@ -1461,9 +1461,9 @@ int Room::checkRightSlopes(v_line_t *line)
// Comprueba las colisiones // Comprueba las colisiones
bool Room::checkRightSlopes(SDL_Point *p) bool Room::checkRightSlopes(SDL_Point *p)
{ {
for (auto s : right_slopes_) for (auto slope : right_slopes_)
{ {
if (checkCollision(*p, s)) if (checkCollision(*p, slope))
{ {
return true; return true;
} }

View File

@@ -229,13 +229,13 @@ public:
bool checkAutoSurfaces(SDL_Point *p); bool checkAutoSurfaces(SDL_Point *p);
// Comprueba las colisiones // Comprueba las colisiones
int checkLeftSlopes(v_line_t *line); int checkLeftSlopes(const v_line_t *line);
// Comprueba las colisiones // Comprueba las colisiones
bool checkLeftSlopes(SDL_Point *p); bool checkLeftSlopes(SDL_Point *p);
// Comprueba las colisiones // Comprueba las colisiones
int checkRightSlopes(v_line_t *line); int checkRightSlopes(const v_line_t *line);
// Comprueba las colisiones // Comprueba las colisiones
bool checkRightSlopes(SDL_Point *p); bool checkRightSlopes(SDL_Point *p);

View File

@@ -101,27 +101,6 @@ Scoreboard::ClockData Scoreboard::getTime()
return time; return time;
} }
// Recarga la textura
void Scoreboard::reLoadTexture()
{
player_sprite_->getTexture()->reLoad();
// playerTexture->reLoad();
item_texture_->reLoad();
text_->reLoadTexture();
}
// Recarga la paleta
void Scoreboard::reLoadPalette()
{
// Reinicia el vector de colores
const std::vector<std::string> vColors = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"};
color_.clear();
for (auto v : vColors)
{
color_.push_back(stringToColor(options.video.palette, v));
}
}
// Pone el marcador en modo pausa // Pone el marcador en modo pausa
void Scoreboard::setPaused(bool value) void Scoreboard::setPaused(bool value)
{ {

View File

@@ -93,12 +93,6 @@ public:
// Actualiza las variables del objeto // Actualiza las variables del objeto
void update(); void update();
// Recarga la textura
void reLoadTexture();
// Recarga la paleta
void reLoadPalette();
// Pone el marcador en modo pausa // Pone el marcador en modo pausa
void setPaused(bool value); void setPaused(bool value);