Solventat bug amb el punter a ScoreboardData

This commit is contained in:
2025-02-27 14:17:00 +01:00
parent c6474cb2da
commit 0cec9f8556
20 changed files with 246 additions and 223 deletions

View File

@@ -11,17 +11,17 @@
#include "texture.h" // for Texture
// Constructor
Scoreboard::Scoreboard(ScoreboardData *board)
Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
: renderer_(Screen::get()->getRenderer()),
resource_(Resource::get()),
asset_(Asset::get()),
board_(board)
data_(data)
{
// Reserva memoria para los objetos
item_texture_ = resource_->getTexture("items.png");
const std::string playerPNG = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png";
const std::string playerANI = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
player_sprite_ = std::make_shared<AnimatedSprite>(resource_->getTexture(playerPNG), resource_->getAnimation(playerANI));
auto player_texture = resource_->getTexture(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png");
auto player_animations = resource_->getAnimations(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani");
player_sprite_ = std::make_shared<AnimatedSprite>(player_texture, player_animations);
player_sprite_->setCurrentAnimation("walk_menu");
text_ = resource_->getText("smb2");
@@ -58,7 +58,7 @@ void Scoreboard::render()
const int frame = desp % 4;
player_sprite_->setCurrentAnimationFrame(frame);
player_sprite_->setPosY(line2);
for (int i = 0; i < board_->lives; ++i)
for (int i = 0; i < data_->lives; ++i)
{
player_sprite_->setPosX(8 + (16 * i) + desp);
const int index = i % color_.size();
@@ -67,9 +67,9 @@ void Scoreboard::render()
}
// Muestra si suena la música
if (board_->music)
if (data_->music)
{
const Color c = board_->color;
const Color 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);
@@ -77,13 +77,13 @@ void Scoreboard::render()
// Escribe los textos
const std::string timeTxt = std::to_string((clock_.minutes % 100) / 10) + std::to_string(clock_.minutes % 10) + clock_.separator + std::to_string((clock_.seconds % 60) / 10) + std::to_string(clock_.seconds % 10);
const std::string itemsTxt = std::to_string(board_->items / 100) + std::to_string((board_->items % 100) / 10) + std::to_string(board_->items % 10);
this->text_->writeColored(BLOCK, line1, "Items collected ", board_->color);
const std::string itemsTxt = std::to_string(data_->items / 100) + std::to_string((data_->items % 100) / 10) + std::to_string(data_->items % 10);
this->text_->writeColored(BLOCK, line1, "Items collected ", data_->color);
this->text_->writeColored(17 * BLOCK, line1, itemsTxt, items_color_);
this->text_->writeColored(20 * BLOCK, line1, " Time ", board_->color);
this->text_->writeColored(20 * BLOCK, line1, " Time ", data_->color);
this->text_->writeColored(26 * BLOCK, line1, timeTxt, stringToColor(options.video.palette, "white"));
const std::string roomsTxt = std::to_string(board_->rooms / 100) + std::to_string((board_->rooms % 100) / 10) + std::to_string(board_->rooms % 10);
const std::string roomsTxt = std::to_string(data_->rooms / 100) + std::to_string((data_->rooms % 100) / 10) + std::to_string(data_->rooms % 10);
this->text_->writeColored(22 * BLOCK, line2, "Rooms", stringToColor(options.video.palette, "white"));
this->text_->writeColored(28 * BLOCK, line2, roomsTxt, stringToColor(options.video.palette, "white"));
}
@@ -107,7 +107,7 @@ void Scoreboard::update()
// Obtiene el tiempo transcurrido de partida
Scoreboard::ClockData Scoreboard::getTime()
{
const Uint32 timeElapsed = SDL_GetTicks() - board_->ini_clock - paused_time_elapsed_;
const Uint32 timeElapsed = SDL_GetTicks() - data_->ini_clock - paused_time_elapsed_;
ClockData time;
time.hours = timeElapsed / 3600000;
@@ -156,7 +156,7 @@ void Scoreboard::resume()
// Actualiza el color de la cantidad de items recogidos
void Scoreboard::updateItemsColor()
{
if (!board_->jail_is_open)
if (!data_->jail_is_open)
{
return;
}