Transició a surface: crec que falta room.cpp

This commit is contained in:
2025-03-03 21:33:59 +01:00
parent b320030547
commit b940d627d6
9 changed files with 121 additions and 157 deletions

View File

@@ -4,7 +4,7 @@
#include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <iostream> // 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<ScoreboardData> 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<AnimatedSprite>(player_texture, player_animations);
player_sprite_ = std::make_shared<SAnimatedSprite>(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<ScoreboardData> 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<std::string> 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);