i per fi ja comença a tornar tot a la normalitat

This commit is contained in:
2025-03-05 20:52:34 +01:00
parent 5a8747cc4b
commit 241732752a
25 changed files with 75 additions and 81 deletions

View File

Before

Width:  |  Height:  |  Size: 379 B

After

Width:  |  Height:  |  Size: 379 B

View File

Before

Width:  |  Height:  |  Size: 379 B

After

Width:  |  Height:  |  Size: 379 B

View File

Before

Width:  |  Height:  |  Size: 379 B

After

Width:  |  Height:  |  Size: 379 B

View File

Before

Width:  |  Height:  |  Size: 379 B

After

Width:  |  Height:  |  Size: 379 B

View File

Before

Width:  |  Height:  |  Size: 379 B

After

Width:  |  Height:  |  Size: 379 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 145 B

After

Width:  |  Height:  |  Size: 145 B

View File

@@ -29,10 +29,10 @@ Credits::Credits()
Screen::get()->setBorderColor(stringToColor("black")); Screen::get()->setBorderColor(stringToColor("black"));
// Crea la textura para el texto que se escribe en pantalla // Crea la textura para el texto que se escribe en pantalla
text_surface_ = std::make_shared<Surface>(Screen::get()->getRendererSurface(), options.game.width, options.game.height); text_surface_ = std::make_shared<Surface>(options.game.width, options.game.height);
// Crea la textura para cubrir el rexto // Crea la textura para cubrir el rexto
cover_surface_ = std::make_shared<Surface>(Screen::get()->getRendererSurface(), options.game.width, options.game.height); cover_surface_ = std::make_shared<Surface>(options.game.width, options.game.height);
// Escribe el texto en la textura // Escribe el texto en la textura
fillTexture(); fillTexture();
@@ -143,7 +143,7 @@ void Credits::fillTexture()
// Rellena la textura de texto // Rellena la textura de texto
Screen::get()->setRendererSurface(text_surface_); Screen::get()->setRendererSurface(text_surface_);
Screen::get()->clearSurface(stringToColor("black")); text_surface_->clear(stringToColor("black"));
auto text = Resource::get()->getText("smb2"); auto text = Resource::get()->getText("smb2");
@@ -168,7 +168,7 @@ void Credits::fillTexture()
// Rellena la textura que cubre el texto con color transparente // Rellena la textura que cubre el texto con color transparente
Screen::get()->setRendererSurface(text_surface_); Screen::get()->setRendererSurface(text_surface_);
Screen::get()->clearSurface(stringToColor("transparent")); text_surface_->clear(stringToColor("transparent"));
// Los primeros 8 pixels crea una malla // Los primeros 8 pixels crea una malla
auto surface = Screen::get()->getRendererSurface(); auto surface = Screen::get()->getRendererSurface();

View File

@@ -394,11 +394,11 @@ bool Director::setFileList()
Asset::get()->add(prefix + "/data/font/8bithud.txt", AssetType::FONT); Asset::get()->add(prefix + "/data/font/8bithud.txt", AssetType::FONT);
// Paletas // Paletas
Asset::get()->add(prefix + "/data/palette/zx-spectrum-8x.gif", AssetType::PALETTE); Asset::get()->add(prefix + "/data/palette/zx-spectrum.gif", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/zx-spectrum-adjusted-8x.gif", AssetType::PALETTE); Asset::get()->add(prefix + "/data/palette/zx-spectrum-adjusted.gif", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/ruzx-spectrum-8x.gif", AssetType::PALETTE); Asset::get()->add(prefix + "/data/palette/ruzx-spectrum.gif", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/ruzx-spectrum-revision-2-8x.gif", AssetType::PALETTE); Asset::get()->add(prefix + "/data/palette/ruzx-spectrum-revision-2.gif", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/zxarne-5-2-8x.gif", AssetType::PALETTE); Asset::get()->add(prefix + "/data/palette/zxarne-5-2.gif", AssetType::PALETTE);
// Shaders // Shaders
Asset::get()->add(prefix + "/data/shaders/crtpi_192.glsl", AssetType::DATA); Asset::get()->add(prefix + "/data/shaders/crtpi_192.glsl", AssetType::DATA);

View File

@@ -43,7 +43,7 @@ Ending::Ending()
Screen::get()->setBorderColor(stringToColor("black")); Screen::get()->setBorderColor(stringToColor("black"));
// Crea la textura para cubrir el texto // Crea la textura para cubrir el texto
cover_surface_ = std::make_shared<Surface>(Screen::get()->getRendererSurface(), options.game.width, options.game.height + 8); cover_surface_ = std::make_shared<Surface>(options.game.width, options.game.height + 8);
// Rellena la textura para la cortinilla // Rellena la textura para la cortinilla
fillCoverTexture(); fillCoverTexture();
@@ -172,7 +172,7 @@ void Ending::iniTexts()
EndingSurface st; EndingSurface st;
// Crea la textura // Crea la textura
st.image_surface = std::make_shared<Surface>(Screen::get()->getRendererSurface(), WIDTH, HEIGHT); st.image_surface = std::make_shared<Surface>(WIDTH, HEIGHT);
Screen::get()->setRendererSurface(st.image_surface); Screen::get()->setRendererSurface(st.image_surface);
text->writeDX(TEXT_STROKE, 2, 2, txt.caption, 1, color, 2, color); text->writeDX(TEXT_STROKE, 2, 2, txt.caption, 1, color, 2, color);
@@ -181,11 +181,11 @@ void Ending::iniTexts()
st.image_sprite->setPosition((options.game.width - st.image_surface->getWidth()) / 2, txt.pos); st.image_sprite->setPosition((options.game.width - st.image_surface->getWidth()) / 2, txt.pos);
// Crea la cover_surface // Crea la cover_surface
st.cover_surface = std::make_shared<Surface>(Screen::get()->getRendererSurface(), WIDTH, HEIGHT + 8); st.cover_surface = std::make_shared<Surface>(WIDTH, HEIGHT + 8);
Screen::get()->setRendererSurface(st.cover_surface); Screen::get()->setRendererSurface(st.cover_surface);
// Rellena la cover_surface con color transparente // Rellena la cover_surface con color transparente
Screen::get()->clearSurface(stringToColor("transparent")); st.cover_surface->clear(stringToColor("transparent"));
// Crea una malla de 8 pixels de alto // Crea una malla de 8 pixels de alto
auto surface = Screen::get()->getRendererSurface(); auto surface = Screen::get()->getRendererSurface();
@@ -248,11 +248,11 @@ void Ending::iniPics()
sp.image_sprite->setPosition((options.game.width - WIDTH) / 2, pic.pos); sp.image_sprite->setPosition((options.game.width - WIDTH) / 2, pic.pos);
// Crea la cover_surface // Crea la cover_surface
sp.cover_surface = std::make_shared<Surface>(Screen::get()->getRendererSurface(), WIDTH, HEIGHT + 8); sp.cover_surface = std::make_shared<Surface>(WIDTH, HEIGHT + 8);
Screen::get()->setRendererSurface(sp.cover_surface); Screen::get()->setRendererSurface(sp.cover_surface);
// Rellena la cover_surface con color transparente // Rellena la cover_surface con color transparente
Screen::get()->clearSurface(stringToColor("transparent")); sp.cover_surface->clear(stringToColor("transparent"));
// Crea una malla en los primeros 8 pixels // Crea una malla en los primeros 8 pixels
auto surface = Screen::get()->getRendererSurface(); auto surface = Screen::get()->getRendererSurface();
@@ -473,7 +473,7 @@ void Ending::fillCoverTexture()
{ {
// Rellena la textura que cubre el texto con color transparente // Rellena la textura que cubre el texto con color transparente
Screen::get()->setRendererSurface(cover_surface_); Screen::get()->setRendererSurface(cover_surface_);
Screen::get()->clearSurface(stringToColor("transparent")); cover_surface_->clear(stringToColor("transparent"));
// Los primeros 8 pixels crea una malla // Los primeros 8 pixels crea una malla
const Uint8 color = stringToColor("black"); const Uint8 color = stringToColor("black");

View File

@@ -423,7 +423,7 @@ void Ending2::createSpriteTexts()
const int Y = sprites_.at(i)->getPosY() + sprites_.at(i)->getHeight() + DIST_SPRITE_TEXT_; const int Y = sprites_.at(i)->getPosY() + sprites_.at(i)->getHeight() + DIST_SPRITE_TEXT_;
// Crea la surface // Crea la surface
auto surface = std::make_shared<Surface>(Screen::get()->getRendererSurface(), W, H); auto surface = std::make_shared<Surface>(W, H);
Screen::get()->setRendererSurface(surface); Screen::get()->setRendererSurface(surface);
text->write(0, 0, txt); text->write(0, 0, txt);
@@ -455,7 +455,7 @@ void Ending2::createTexts()
const int y = options.game.height + (text->getCharacterSize() * (i * 2)); const int y = options.game.height + (text->getCharacterSize() * (i * 2));
// Crea la surface // Crea la surface
auto surface = std::make_shared<Surface>(Screen::get()->getRendererSurface(), w, h); auto surface = std::make_shared<Surface>(w, h);
Screen::get()->setRendererSurface(surface); Screen::get()->setRendererSurface(surface);
text->write(0, 0, list[i]); text->write(0, 0, list[i]);
@@ -484,7 +484,7 @@ void Ending2::createTexts()
const int y = START + (text->getCharacterSize() * (i * 2)); const int y = START + (text->getCharacterSize() * (i * 2));
// Crea la surface // Crea la surface
auto surface = std::make_shared<Surface>(Screen::get()->getRendererSurface(), w, h); auto surface = std::make_shared<Surface>(w, h);
Screen::get()->setRendererSurface(surface); Screen::get()->setRendererSurface(surface);
text->write(0, 0, list[i]); text->write(0, 0, list[i]);

View File

@@ -31,6 +31,8 @@ Enemy::Enemy(const EnemyData &enemy)
collider_ = getRect(); collider_ = getRect();
color_ = stringToColor(color_string_);
// Coloca un frame al azar o el designado // 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);
} }

View File

@@ -565,7 +565,7 @@ void Game::fillRoomNameTexture()
Screen::get()->setRendererSurface(room_name_surface_); Screen::get()->setRendererSurface(room_name_surface_);
// Rellena la textura de color // Rellena la textura de color
Screen::get()->clearSurface(stringToColor("white")); room_name_surface_->clear(stringToColor("white"));
// Escribe el texto en la textura // Escribe el texto en la textura
auto text = Resource::get()->getText("smb2"); auto text = Resource::get()->getText("smb2");
@@ -662,7 +662,7 @@ void Game::initPlayer(const PlayerSpawn &spawn_point, std::shared_ptr<Room> room
void Game::createRoomNameTexture() void Game::createRoomNameTexture()
{ {
auto text = Resource::get()->getText("smb2"); auto text = Resource::get()->getText("smb2");
room_name_surface_ = std::make_shared<Surface>(Screen::get()->getRendererSurface(), options.game.width, text->getCharacterSize() * 2); room_name_surface_ = std::make_shared<Surface>(options.game.width, text->getCharacterSize() * 2);
// Establece el destino de la textura // Establece el destino de la textura
room_name_rect_ = {0, PLAY_AREA_HEIGHT, options.game.width, text->getCharacterSize() * 2}; room_name_rect_ = {0, PLAY_AREA_HEIGHT, options.game.width, text->getCharacterSize() * 2};

View File

@@ -22,7 +22,7 @@ LoadingScreen::LoadingScreen()
color_loading_screen_surface_(Resource::get()->getSurface("loading_screen_color.gif")), color_loading_screen_surface_(Resource::get()->getSurface("loading_screen_color.gif")),
mono_loading_screen_sprite_(std::make_shared<SSprite>(mono_loading_screen_surface_, 0, 0, mono_loading_screen_surface_->getWidth(), mono_loading_screen_surface_->getHeight())), mono_loading_screen_sprite_(std::make_shared<SSprite>(mono_loading_screen_surface_, 0, 0, mono_loading_screen_surface_->getWidth(), mono_loading_screen_surface_->getHeight())),
color_loading_screen_sprite_(std::make_shared<SSprite>(color_loading_screen_surface_, 0, 0, color_loading_screen_surface_->getWidth(), color_loading_screen_surface_->getHeight())), color_loading_screen_sprite_(std::make_shared<SSprite>(color_loading_screen_surface_, 0, 0, color_loading_screen_surface_->getWidth(), color_loading_screen_surface_->getHeight())),
screen_surface_(std::make_shared<Surface>(Screen::get()->getRendererSurface(), options.game.width, options.game.height)) screen_surface_(std::make_shared<Surface>(options.game.width, options.game.height))
{ {
// Configura la superficie donde se van a pintar los sprites // Configura la superficie donde se van a pintar los sprites
screen_surface_->clear(stringToColor("white")); screen_surface_->clear(stringToColor("white"));

View File

@@ -234,32 +234,31 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, in
n.rect = {desp_h, y_pos, width, height}; n.rect = {desp_h, y_pos, width, height};
// Crea la textura // Crea la textura
n.surface = std::make_shared<Surface>(Screen::get()->getRendererSurface(), width, height); n.surface = std::make_shared<Surface>(width, height);
// Prepara para dibujar en la textura // Prepara para dibujar en la textura
Screen::get()->setRendererSurface(n.surface); Screen::get()->setRendererSurface(n.surface);
// Dibuja el fondo de la notificación // Dibuja el fondo de la notificación
SDL_Rect rect; SDL_Rect rect;
auto surface = Screen::get()->getRendererSurface();
if (shape == NotificationShape::ROUNDED) if (shape == NotificationShape::ROUNDED)
{ {
rect = {4, 0, width - (4 * 2), height}; rect = {4, 0, width - (4 * 2), height};
surface->fillRect(&rect, bg_color_); n.surface->fillRect(&rect, bg_color_);
rect = {4 / 2, 1, width - 4, height - 2}; rect = {4 / 2, 1, width - 4, height - 2};
surface->fillRect(&rect, bg_color_); n.surface->fillRect(&rect, bg_color_);
rect = {1, 4 / 2, width - 2, height - 4}; rect = {1, 4 / 2, width - 2, height - 4};
surface->fillRect(&rect, bg_color_); n.surface->fillRect(&rect, bg_color_);
rect = {0, 4, width, height - (4 * 2)}; rect = {0, 4, width, height - (4 * 2)};
surface->fillRect(&rect, bg_color_); n.surface->fillRect(&rect, bg_color_);
} }
else if (shape == NotificationShape::SQUARED) else if (shape == NotificationShape::SQUARED)
{ {
Screen::get()->clearSurface(bg_color_); n.surface->clear(bg_color_);
} }
// Dibuja el icono de la notificación // Dibuja el icono de la notificación

View File

@@ -712,12 +712,12 @@ void Player::applySpawnValues(const PlayerSpawn &spawn)
} }
// Inicializa el sprite del jugador // Inicializa el sprite del jugador
void Player::initSprite(const std::string &texture_path, const std::string &animations_path) void Player::initSprite(const std::string &surface_path, const std::string &animations_path)
{ {
auto texture = Resource::get()->getSurface(texture_path); auto surface = Resource::get()->getSurface(surface_path);
auto animations = Resource::get()->getAnimations(animations_path); auto animations = Resource::get()->getAnimations(animations_path);
sprite_ = std::make_shared<SAnimatedSprite>(texture, animations); sprite_ = std::make_shared<SAnimatedSprite>(surface, animations);
sprite_->setWidth(WIDTH_); sprite_->setWidth(WIDTH_);
sprite_->setHeight(HEIGHT_); sprite_->setHeight(HEIGHT_);
sprite_->setCurrentAnimation("walk"); sprite_->setCurrentAnimation("walk");

View File

@@ -247,7 +247,7 @@ void Resource::loadSurfaces()
for (const auto &l : list) for (const auto &l : list)
{ {
auto name = getFileName(l); auto name = getFileName(l);
surfaces_.emplace_back(ResourceSurface(name, std::make_shared<Surface>(Screen::get()->getRendererSurface(), l))); surfaces_.emplace_back(ResourceSurface(name, std::make_shared<Surface>(l)));
updateLoadingProgress(); updateLoadingProgress();
} }
} }

View File

@@ -415,7 +415,7 @@ Room::Room(const std::string &room_path, std::shared_ptr<ScoreboardData> data)
setAnimatedTiles(); setAnimatedTiles();
// Crea la textura para el mapa de tiles de la habitación // Crea la textura para el mapa de tiles de la habitación
map_surface_ = std::make_shared<Surface>(Screen::get()->getRendererSurface(), PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT); map_surface_ = std::make_shared<Surface>(PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT);
// Pinta el mapa de la habitación en la textura // Pinta el mapa de la habitación en la textura
fillMapTexture(); fillMapTexture();
@@ -475,7 +475,7 @@ void Room::fillMapTexture()
{ {
const Uint8 color = stringToColor(bg_color_); const Uint8 color = stringToColor(bg_color_);
Screen::get()->setRendererSurface(map_surface_); Screen::get()->setRendererSurface(map_surface_);
Screen::get()->clearSurface(color); map_surface_->clear(color);
// Los tileSetFiles son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo // Los tileSetFiles son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo

View File

@@ -27,7 +27,7 @@ Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
player_sprite_ = std::make_shared<SAnimatedSprite>(player_texture, player_animations); player_sprite_ = std::make_shared<SAnimatedSprite>(player_texture, player_animations);
player_sprite_->setCurrentAnimation("walk_menu"); player_sprite_->setCurrentAnimation("walk_menu");
surface_ = std::make_shared<Surface>(Screen::get()->getRendererSurface(), SURFACE_WIDTH_, SURFACE_HEIGHT_); surface_ = std::make_shared<Surface>(SURFACE_WIDTH_, SURFACE_HEIGHT_);
surface_dest_ = {0, options.game.height - SURFACE_HEIGHT_, SURFACE_WIDTH_, SURFACE_HEIGHT_}; surface_dest_ = {0, options.game.height - SURFACE_HEIGHT_, SURFACE_WIDTH_, SURFACE_HEIGHT_};
// Inicializa las variables // Inicializa las variables
@@ -139,7 +139,7 @@ void Scoreboard::fillTexture()
Screen::get()->setRendererSurface(surface_); Screen::get()->setRendererSurface(surface_);
// Limpia la textura // Limpia la textura
Screen::get()->clearSurface(stringToColor("black")); surface_->clear(stringToColor("black"));
// Anclas // Anclas
constexpr int LINE1 = BLOCK; constexpr int LINE1 = BLOCK;

View File

@@ -75,13 +75,14 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
} }
// Crea la surface donde se dibujan los graficos del juego // Crea la surface donde se dibujan los graficos del juego
game_surface_ = std::make_shared<Surface>(nullptr, options.game.width, options.game.height); game_surface_ = std::make_shared<Surface>(options.game.width, options.game.height);
game_surface_->loadPalette(palettes_.front()); game_surface_->loadPalette(palettes_.front());
// Crea la surface donde se dibujan los graficos del juego // Crea la surface donde se dibujan los graficos del juego
border_surface_ = std::make_shared<Surface>(nullptr, options.game.width + options.video.border.width * 2, options.game.height + options.video.border.height * 2); border_surface_ = std::make_shared<Surface>(options.game.width + options.video.border.width * 2, options.game.height + options.video.border.height * 2);
border_surface_->loadPalette(palettes_.front()); border_surface_->loadPalette(palettes_.front());
// Establece la surface que actuará como renderer para recibir las llamadas a render()
renderer_surface_ = std::make_shared<std::shared_ptr<Surface>>(game_surface_); renderer_surface_ = std::make_shared<std::shared_ptr<Surface>>(game_surface_);
// Establece el modo de video // Establece el modo de video
@@ -127,11 +128,12 @@ void Screen::startDrawOnBorder()
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
void Screen::render() void Screen::render()
{ {
// Renderiza sobre game_surface_ los overlays
//renderNotifications();
// Copia la surface a game_texture_ // Copia la surface a game_texture_
game_surface_->copyToTexture(renderer_, game_texture_); game_surface_->copyToTexture(renderer_, game_texture_);
// Renderiza sobre gameCanvas los overlays
// renderNotifications();
// Si está el borde activo, vuelca gameCanvas sobre borderCanvas // Si está el borde activo, vuelca gameCanvas sobre borderCanvas
if (options.video.border.enabled) if (options.video.border.enabled)
@@ -381,9 +383,7 @@ void Screen::resetShaders()
// Establece el renderizador para las surfaces // Establece el renderizador para las surfaces
void Screen::setRendererSurface(std::shared_ptr<Surface> surface) void Screen::setRendererSurface(std::shared_ptr<Surface> surface)
{ {
(surface) ? (surface) ? renderer_surface_ = std::make_shared<std::shared_ptr<Surface>>(surface) : renderer_surface_ = std::make_shared<std::shared_ptr<Surface>>(game_surface_);
renderer_surface_ = std::make_shared<std::shared_ptr<Surface>>(surface):
renderer_surface_ = std::make_shared<std::shared_ptr<Surface>>(game_surface_);
} }
// Cambia la paleta // Cambia la paleta

View File

@@ -32,7 +32,7 @@ private:
SDL_Texture *border_texture_; // Textura donde se dibuja el borde del juego SDL_Texture *border_texture_; // Textura donde se dibuja el borde del juego
std::shared_ptr<Surface> game_surface_; // Surface principal para manejar game_surface_data_ std::shared_ptr<Surface> game_surface_; // Surface principal para manejar game_surface_data_
std::shared_ptr<Surface> border_surface_; // Surface para pintar el el borde de la pantalla std::shared_ptr<Surface> border_surface_; // Surface para pintar el el borde de la pantalla
std::shared_ptr<std::shared_ptr<Surface>> renderer_surface_; std::shared_ptr<std::shared_ptr<Surface>> renderer_surface_; // Puntero a la Surface que actua
// Variables // Variables
int window_width_; // Ancho de la pantalla o ventana int window_width_; // Ancho de la pantalla o ventana

View File

@@ -9,17 +9,15 @@
#include <vector> // for vector #include <vector> // for vector
#include "asset.h" // for Asset #include "asset.h" // for Asset
#include "screen.h" #include "screen.h"
#include "gif.h" // for LoadGif, LoadPalette #include "gif.h" // for LoadGif, LoadPalette
// Constructor // Constructor
Surface::Surface(std::shared_ptr<Surface> surface_dest, int w, int h) Surface::Surface(int w, int h)
: surface_dest_(surface_dest), : surface_data_(std::make_shared<SurfaceData>(w, h)),
surface_data_(std::make_shared<SurfaceData>(w, h)), transparent_color_(0) {}
transparent_color_(0){}
Surface::Surface(std::shared_ptr<Surface> surface_dest, const std::string &file_path) Surface::Surface(const std::string &file_path)
: surface_dest_(surface_dest), : transparent_color_(0)
transparent_color_(0)
{ {
SurfaceData loadedData = loadSurface(file_path); SurfaceData loadedData = loadSurface(file_path);
surface_data_ = std::make_shared<SurfaceData>(std::move(loadedData)); surface_data_ = std::make_shared<SurfaceData>(std::move(loadedData));
@@ -209,7 +207,7 @@ void Surface::render(int dx, int dy, int sx, int sy, int w, int h)
void Surface::render(int x, int y, SDL_Rect *srcRect, SDL_RendererFlip flip) void Surface::render(int x, int y, SDL_Rect *srcRect, SDL_RendererFlip flip)
{ {
auto surface_data = Screen::get()->getRendererSurface()->getSurfaceData(); auto surface_data = Screen::get()->getRendererSurface()->getSurfaceData();
// Determina la región de origen (clip) a renderizar // Determina la región de origen (clip) a renderizar
int sx = (srcRect) ? srcRect->x : 0; int sx = (srcRect) ? srcRect->x : 0;
int sy = (srcRect) ? srcRect->y : 0; int sy = (srcRect) ? srcRect->y : 0;
@@ -349,7 +347,7 @@ void Surface::renderWithColorReplace(int x, int y, Uint8 source_color, Uint8 tar
// Vuelca la superficie a una textura // Vuelca la superficie a una textura
void Surface::copyToTexture(SDL_Renderer *renderer, SDL_Texture *texture) void Surface::copyToTexture(SDL_Renderer *renderer, SDL_Texture *texture)
{ {
if (!renderer || !texture) if (!renderer || !texture || !surface_data_)
{ {
throw std::runtime_error("Renderer or texture is null."); throw std::runtime_error("Renderer or texture is null.");
} }

View File

@@ -60,15 +60,14 @@ struct SurfaceData
class Surface class Surface
{ {
private: private:
std::shared_ptr<Surface> surface_dest_; // Surface remota donde dibujar la surface_data_
std::shared_ptr<SurfaceData> surface_data_; // Datos a dibujar std::shared_ptr<SurfaceData> surface_data_; // Datos a dibujar
std::array<Uint32, 256> palette_; // Paleta para volcar la SurfaceData a una Textura std::array<Uint32, 256> palette_; // Paleta para volcar la SurfaceData a una Textura
int transparent_color_; // Indice de la paleta que se omite en la copia de datos int transparent_color_; // Indice de la paleta que se omite en la copia de datos
public: public:
// Constructor // Constructor
Surface(std::shared_ptr<Surface> surface_dest, int w, int h); Surface(int w, int h);
Surface(std::shared_ptr<Surface> surface_dest, const std::string &file_path); Surface(const std::string &file_path);
// Destructor // Destructor
~Surface() = default; ~Surface() = default;
@@ -111,10 +110,6 @@ public:
// Dibuja una linea // Dibuja una linea
void drawLine(int x1, int y1, int x2, int y2, Uint8 color); void drawLine(int x1, int y1, int x2, int y2, Uint8 color);
// Métodos para gestionar surface_dest_
std::shared_ptr<Surface> getSurfaceDest() const { return surface_dest_; }
void setSurfaceDest(std::shared_ptr<Surface> new_surface_dest) { surface_dest_ = new_surface_dest; }
// Metodos para gestionar surface_data_ // Metodos para gestionar surface_data_
std::shared_ptr<SurfaceData> getSurfaceData() const { return surface_data_; } std::shared_ptr<SurfaceData> getSurfaceData() const { return surface_data_; }
void setSurfaceData(std::shared_ptr<SurfaceData> new_data) { surface_data_ = new_data; } void setSurfaceData(std::shared_ptr<SurfaceData> new_data) { surface_data_ = new_data; }

View File

@@ -146,9 +146,9 @@ std::shared_ptr<Surface> Text::writeToSurface(const std::string &text, int zoom,
{ {
auto width = lenght(text, kerning) * zoom; auto width = lenght(text, kerning) * zoom;
auto height = box_height_ * zoom; auto height = box_height_ * zoom;
auto surface = std::make_shared<Surface>(Screen::get()->getRendererSurface(), width, height); auto surface = std::make_shared<Surface>(width, height);
Screen::get()->setRendererSurface(surface); Screen::get()->setRendererSurface(surface);
Screen::get()->clearSurface(stringToColor("transparent")); surface->clear(stringToColor("transparent"));
write(0, 0, text, kerning); write(0, 0, text, kerning);
Screen::get()->setRendererSurface(nullptr); Screen::get()->setRendererSurface(nullptr);
@@ -160,9 +160,9 @@ std::shared_ptr<Surface> Text::writeDXToSurface(Uint8 flags, const std::string &
{ {
auto width = Text::lenght(text, kerning) + shadow_distance; auto width = Text::lenght(text, kerning) + shadow_distance;
auto height = box_height_ + shadow_distance; auto height = box_height_ + shadow_distance;
auto surface = std::make_shared<Surface>(Screen::get()->getRendererSurface(), width, height); auto surface = std::make_shared<Surface>(width, height);
Screen::get()->setRendererSurface(surface); Screen::get()->setRendererSurface(surface);
Screen::get()->clearSurface(stringToColor("transparent")); surface->clear(stringToColor("transparent"));
writeDX(flags, 0, 0, text, kerning, textColor, shadow_distance, shadow_color, lenght); writeDX(flags, 0, 0, text, kerning, textColor, shadow_distance, shadow_color, lenght);
Screen::get()->setRendererSurface(nullptr); Screen::get()->setRendererSurface(nullptr);

View File

@@ -25,7 +25,7 @@
Title::Title() Title::Title()
: title_logo_surface_(Resource::get()->getSurface("title_logo.gif")), : title_logo_surface_(Resource::get()->getSurface("title_logo.gif")),
title_logo_sprite_(std::make_shared<SSprite>(title_logo_surface_, 0, 0, title_logo_surface_->getWidth(), title_logo_surface_->getHeight())), title_logo_sprite_(std::make_shared<SSprite>(title_logo_surface_, 0, 0, title_logo_surface_->getWidth(), title_logo_surface_->getHeight())),
bg_surface_(std::make_shared<Surface>(Screen::get()->getRendererSurface(), options.game.width, options.game.height)) bg_surface_(std::make_shared<Surface>(options.game.width, options.game.height))
{ {
// Carga la surface con los gráficos de la pantalla de carga // Carga la surface con los gráficos de la pantalla de carga
pInit(Screen::get()->getRenderer(), 256, 128); pInit(Screen::get()->getRenderer(), 256, 128);
@@ -347,14 +347,14 @@ void Title::createCheevosTexture()
constexpr int CHEEVOS_PADDING = 10; constexpr int CHEEVOS_PADDING = 10;
const int CHEEVO_HEIGHT = CHEEVOS_PADDING + (TEXT->getCharacterSize() * 2) + 1; const int CHEEVO_HEIGHT = CHEEVOS_PADDING + (TEXT->getCharacterSize() * 2) + 1;
const int CHEEVOS_TEXTURE_HEIGHT = (CHEEVO_HEIGHT * CHEEVOS_LIST.size()) + 2 + TEXT->getCharacterSize() + 8; const int CHEEVOS_TEXTURE_HEIGHT = (CHEEVO_HEIGHT * CHEEVOS_LIST.size()) + 2 + TEXT->getCharacterSize() + 8;
cheevos_surface_ = std::make_shared<Surface>(Screen::get()->getRendererSurface(), CHEEVOS_TEXTURE_WIDTH, CHEEVOS_TEXTURE_HEIGHT); cheevos_surface_ = std::make_shared<Surface>(CHEEVOS_TEXTURE_WIDTH, CHEEVOS_TEXTURE_HEIGHT);
// Prepara para dibujar sobre la textura // Prepara para dibujar sobre la textura
Screen::get()->setRendererSurface(cheevos_surface_); Screen::get()->setRendererSurface(cheevos_surface_);
// Rellena la textura con color sólido // Rellena la textura con color sólido
const Uint8 CHEEVOS_BG_COLOR = stringToColor("black"); const Uint8 CHEEVOS_BG_COLOR = stringToColor("black");
Screen::get()->clearSurface(CHEEVOS_BG_COLOR); cheevos_surface_->clear(CHEEVOS_BG_COLOR);
// Escribe la lista de logros en la textura // Escribe la lista de logros en la textura
const std::string CHEEVOS_OWNER = "ACHIEVEMENTS"; const std::string CHEEVOS_OWNER = "ACHIEVEMENTS";

View File

@@ -366,18 +366,18 @@ Uint8 stringToColor(const std::string &str)
{"transparent", 0}, {"transparent", 0},
{"black", 1}, {"black", 1},
{"bright_black", 2}, {"bright_black", 2},
{"blue", 3}, {"red", 3},
{"bright_blue", 4}, {"bright_red", 4},
{"red", 5}, {"green", 5},
{"bright_red", 6}, {"bright_green", 6},
{"magenta", 7}, {"yellow", 7},
{"bright_magenta", 8}, {"bright_yellow", 8},
{"green", 9}, {"blue", 9},
{"bright_green", 10}, {"bright_blue", 10},
{"cyan", 11}, {"magenta", 11},
{"bright_cyan", 12}, {"bright_magenta", 12},
{"yellow", 13}, {"cyan", 13},
{"bright_yellow", 14}, {"bright_cyan", 14},
{"white", 15}, {"white", 15},
{"bright_white", 16}}; {"bright_white", 16}};