fix: s'havien fotut els dos finals, pero ja estan corregits

This commit is contained in:
2025-03-02 13:43:23 +01:00
parent cdf0b0a694
commit 0d74a8a29f
15 changed files with 214 additions and 277 deletions

View File

@@ -18,38 +18,21 @@
// Constructor // Constructor
Credits::Credits() Credits::Credits()
: shining_sprite_(std::make_shared<AnimatedSprite>(Resource::get()->getTexture("shine.png"), Resource::get()->getAnimations("shine.ani")))
{ {
// Reserva memoria para los punteros
sprite_ = std::make_shared<AnimatedSprite>(Resource::get()->getTexture("shine.png"), Resource::get()->getAnimations("shine.ani"));
// Inicializa variables // Inicializa variables
options.section.section = Section::CREDITS; options.section.section = Section::CREDITS;
options.section.subsection = Subsection::NONE; options.section.subsection = Subsection::NONE;
sprite_->setPosition({194, 174, 8, 8}); shining_sprite_->setPosition({194, 174, 8, 8});
// Cambia el color del borde // Cambia el color del borde
Screen::get()->setBorderColor(stringToColor(options.video.palette, "black")); Screen::get()->setBorderColor(stringToColor(options.video.palette, "black"));
// Crea la textura para el texto que se escribe en pantalla // Crea la textura para el texto que se escribe en pantalla
text_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); text_texture_ = createTexture(Screen::get()->getRenderer(), options.game.width, options.game.height);
if (text_texture_ == nullptr)
{
if (options.console)
{
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
SDL_SetTextureBlendMode(text_texture_, SDL_BLENDMODE_BLEND);
// Crea la textura para cubrir el rexto // Crea la textura para cubrir el rexto
cover_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); cover_texture_ = createTexture(Screen::get()->getRenderer(), options.game.width, options.game.height);
if (cover_texture_ == nullptr)
{
if (options.console)
{
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
SDL_SetTextureBlendMode(cover_texture_, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(cover_texture_, SDL_BLENDMODE_BLEND);
// Escribe el texto en la textura // Escribe el texto en la textura
@@ -190,7 +173,7 @@ void Credits::fillTexture()
text->writeColored(POS_X, 176, "}", stringToColor(options.video.palette, "bright_red")); text->writeColored(POS_X, 176, "}", stringToColor(options.video.palette, "bright_red"));
// Recoloca el sprite del brillo // Recoloca el sprite del brillo
sprite_->setPosX(POS_X + 2); shining_sprite_->setPosX(POS_X + 2);
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr); SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
@@ -268,7 +251,7 @@ void Credits::update()
// Actualiza el sprite con el brillo // Actualiza el sprite con el brillo
if (counter_ > 770) if (counter_ > 770)
{ {
sprite_->update(); shining_sprite_->update();
} }
} }
} }
@@ -294,7 +277,7 @@ void Credits::render()
SDL_RenderCopy(Screen::get()->getRenderer(), cover_texture_, &srcRect, &dstRect); SDL_RenderCopy(Screen::get()->getRenderer(), cover_texture_, &srcRect, &dstRect);
// Dibuja el sprite con el brillo // Dibuja el sprite con el brillo
sprite_->render(); shining_sprite_->render();
} }
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla

View File

@@ -20,7 +20,7 @@ private:
// Objetos y punteros // Objetos y punteros
SDL_Texture *text_texture_; // Textura para dibujar el texto SDL_Texture *text_texture_; // Textura para dibujar el texto
SDL_Texture *cover_texture_; // Textura para cubrir el texto SDL_Texture *cover_texture_; // Textura para cubrir el texto
std::shared_ptr<AnimatedSprite> sprite_; // Sprite para el brillo del corazón std::shared_ptr<AnimatedSprite> shining_sprite_; // Sprite para el brillo del corazón
// Variables // Variables
int counter_ = 0; // Contador int counter_ = 0; // Contador

View File

@@ -7,7 +7,7 @@
#include <SDL2/SDL_timer.h> // for SDL_GetTicks #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <algorithm> // for min #include <algorithm> // for min
#include <iostream> // for basic_ostream, operator<<, cout, endl #include <iostream> // for basic_ostream, operator<<, cout, endl
#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH #include "defines.h" // for GAMECANVAS_HEIGHT, options.game.width
#include "global_events.h" // for check #include "global_events.h" // for check
#include "global_inputs.h" // for check #include "global_inputs.h" // for check
#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM... #include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM...
@@ -42,15 +42,8 @@ Ending::Ending()
// Cambia el color del borde // Cambia el color del borde
Screen::get()->setBorderColor(stringToColor(options.video.palette, "black")); Screen::get()->setBorderColor(stringToColor(options.video.palette, "black"));
// Crea la textura para cubrir el rexto // Crea la textura para cubrir el texto
cover_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT + 8); cover_texture_ = createTexture(Screen::get()->getRenderer(), options.game.width, options.game.height + 8);
if (cover_texture_ == nullptr)
{
if (options.console)
{
std::cout << "Error: canvasTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
SDL_SetTextureBlendMode(cover_texture_, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(cover_texture_, SDL_BLENDMODE_BLEND);
// Rellena la textura para la cortinilla // Rellena la textura para la cortinilla
@@ -60,7 +53,6 @@ Ending::Ending()
// Destructor // Destructor
Ending::~Ending() Ending::~Ending()
{ {
// Libera la memoria de los objetos
SDL_DestroyTexture(cover_texture_); SDL_DestroyTexture(cover_texture_);
} }
@@ -99,19 +91,19 @@ void Ending::render()
Screen::get()->start(); Screen::get()->start();
// Limpia la pantalla // Limpia la pantalla
Screen::get()->clean(stringToColor(options.video.palette, "black")); Screen::get()->clean(stringToColor(options.video.palette, "yellow"));
// Dibuja las imagenes de la escena // Dibuja las imagenes de la escena
sprite_pics_[current_scene_].sprite->render(); sprite_pics_.at(current_scene_).image_sprite->render();
sprite_pics_[current_scene_].cover_sprite->render(); sprite_pics_.at(current_scene_).cover_sprite->render();
// Dibuja los textos de la escena // Dibuja los textos de la escena
for (auto ti : scenes_[current_scene_].text_index) for (const auto &ti : scenes_.at(current_scene_).text_index)
{ {
if (counter_ > ti.trigger) if (counter_ > ti.trigger)
{ {
sprite_texts_[ti.index].sprite->render(); sprite_texts_.at(ti.index).image_sprite->render();
sprite_texts_[ti.index].cover_sprite->render(); sprite_texts_.at(ti.index).cover_sprite->render();
} }
} }
@@ -176,26 +168,26 @@ void Ending::iniTexts()
// Crea los sprites // Crea los sprites
sprite_texts_.clear(); sprite_texts_.clear();
for (const auto &t : texts) for (const auto &txt : texts)
{ {
auto text = Resource::get()->getText("smb2"); auto text = Resource::get()->getText("smb2");
const int WIDTH = text->lenght(t.caption, 1) + 2 + 2; const int WIDTH = text->lenght(txt.caption, 1) + 2 + 2;
const int HEIGHT = text->getCharacterSize() + 2 + 2; const int HEIGHT = text->getCharacterSize() + 2 + 2;
Color color = stringToColor(options.video.palette, "black"); Color color = stringToColor(options.video.palette, "black");
EndingTexture st; EndingTexture st;
// Crea la texture // Crea la textura
st.texture = std::make_shared<Texture>(Screen::get()->getRenderer()); st.image_texture = std::make_shared<Texture>(Screen::get()->getRenderer());
st.texture->createBlank(WIDTH, HEIGHT); st.image_texture->createBlank(WIDTH, HEIGHT);
st.texture->setAsRenderTarget(Screen::get()->getRenderer()); st.image_texture->setAsRenderTarget(Screen::get()->getRenderer());
st.texture->setBlendMode(SDL_BLENDMODE_BLEND); st.image_texture->setBlendMode(SDL_BLENDMODE_BLEND);
text->writeDX(TEXT_STROKE, 2, 2, t.caption, 1, color, 2, color); text->writeDX(TEXT_STROKE, 2, 2, txt.caption, 1, color, 2, color);
// Crea el sprite // Crea el sprite
st.sprite = std::make_shared<Sprite>(st.texture, 0, 0, st.texture->getWidth(), st.texture->getHeight()); st.image_sprite = std::make_shared<Sprite>(st.image_texture, 0, 0, st.image_texture->getWidth(), st.image_texture->getHeight());
st.sprite->setPosition((GAMECANVAS_WIDTH - st.texture->getWidth()) / 2, t.pos); st.image_sprite->setPosition((options.game.width - st.image_texture->getWidth()) / 2, txt.pos);
// Crea la coverTexture // Crea la coverTexture
st.cover_texture = std::make_shared<Texture>(Screen::get()->getRenderer()); st.cover_texture = std::make_shared<Texture>(Screen::get()->getRenderer());
@@ -207,7 +199,7 @@ void Ending::iniTexts()
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);
SDL_RenderClear(Screen::get()->getRenderer()); SDL_RenderClear(Screen::get()->getRenderer());
// Los primeros 8 pixels crea una malla // Crea una malla de 8 pixels de alto
color = stringToColor(options.video.palette, "black"); color = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF);
for (int i = 0; i < WIDTH; i += 2) for (int i = 0; i < WIDTH; i += 2)
@@ -229,12 +221,12 @@ void Ending::iniTexts()
// Crea el sprite // Crea el sprite
st.cover_sprite = std::make_shared<Sprite>(st.cover_texture, 0, 0, st.cover_texture->getWidth(), st.cover_texture->getHeight() - 8); st.cover_sprite = std::make_shared<Sprite>(st.cover_texture, 0, 0, st.cover_texture->getWidth(), st.cover_texture->getHeight() - 8);
st.cover_sprite->setPosition((GAMECANVAS_WIDTH - st.cover_texture->getWidth()) / 2, t.pos); st.cover_sprite->setPosition((options.game.width - st.cover_texture->getWidth()) / 2, txt.pos);
st.cover_sprite->setClip(0, 8, -1, -1); st.cover_sprite->setClip(0, 8, st.cover_texture->getWidth(), st.cover_texture->getHeight());
// Inicializa variables // Inicializa variables
st.clip_desp = 8; st.cover_clip_desp = 8;
st.clip_height = HEIGHT; st.cover_clip_height = HEIGHT;
sprite_texts_.push_back(st); sprite_texts_.push_back(st);
} }
@@ -266,22 +258,22 @@ void Ending::iniPics()
// Crea los sprites // Crea los sprites
sprite_pics_.clear(); sprite_pics_.clear();
for (const auto &p : pics) for (const auto &pic : pics)
{ {
EndingTexture sp; EndingTexture sp;
// Crea la texture // Crea la texture
sp.texture = Resource::get()->getTexture(p.caption); sp.image_texture = Resource::get()->getTexture(pic.caption);
const int width = sp.texture->getWidth(); const int WIDTH = sp.image_texture->getWidth();
const int height = sp.texture->getHeight(); const int HEIGHT = sp.image_texture->getHeight();
// Crea el sprite // Crea el sprite
sp.sprite = std::make_shared<Sprite>(sp.texture, 0, 0, width, height); sp.image_sprite = std::make_shared<Sprite>(sp.image_texture, 0, 0, WIDTH, HEIGHT);
sp.sprite->setPosition((GAMECANVAS_WIDTH - width) / 2, p.pos); sp.image_sprite->setPosition((options.game.width - WIDTH) / 2, pic.pos);
// Crea la coverTexture // Crea la coverTexture
sp.cover_texture = std::make_shared<Texture>(Screen::get()->getRenderer()); sp.cover_texture = std::make_shared<Texture>(Screen::get()->getRenderer());
sp.cover_texture->createBlank(width, height + 8); sp.cover_texture->createBlank(WIDTH, HEIGHT + 8);
sp.cover_texture->setAsRenderTarget(Screen::get()->getRenderer()); sp.cover_texture->setAsRenderTarget(Screen::get()->getRenderer());
sp.cover_texture->setBlendMode(SDL_BLENDMODE_BLEND); sp.cover_texture->setBlendMode(SDL_BLENDMODE_BLEND);
@@ -289,10 +281,10 @@ void Ending::iniPics()
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);
SDL_RenderClear(Screen::get()->getRenderer()); SDL_RenderClear(Screen::get()->getRenderer());
// Los primeros 8 pixels crea una malla // Crea una malla en los primeros 8 pixels
Color c = stringToColor(options.video.palette, "black"); Color c = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), c.r, c.g, c.b, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), c.r, c.g, c.b, 0xFF);
for (int i = 0; i < width; i += 2) for (int i = 0; i < WIDTH; i += 2)
{ {
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 0); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 0);
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 2); SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, 2);
@@ -304,19 +296,19 @@ void Ending::iniPics()
} }
// El resto se rellena de color sólido // El resto se rellena de color sólido
SDL_Rect rect = {0, 8, width, height}; SDL_Rect rect = {0, 8, WIDTH, HEIGHT};
c = stringToColor(options.video.palette, "black"); c = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), c.r, c.g, c.b, 0xFF); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), c.r, c.g, c.b, 0xFF);
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect); SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
// Crea el sprite // Crea el sprite
sp.cover_sprite = std::make_shared<Sprite>(sp.cover_texture, 0, 0, sp.cover_texture->getWidth(), sp.cover_texture->getHeight() - 8); sp.cover_sprite = std::make_shared<Sprite>(sp.cover_texture, 0, 0, sp.cover_texture->getWidth(), sp.cover_texture->getHeight() - 8);
sp.cover_sprite->setPosition((GAMECANVAS_WIDTH - sp.cover_texture->getWidth()) / 2, p.pos); sp.cover_sprite->setPosition((options.game.width - sp.cover_texture->getWidth()) / 2, pic.pos);
sp.cover_sprite->setClip(0, 8, -1, -1); sp.cover_sprite->setClip(0, 8, sp.cover_texture->getWidth(), sp.cover_texture->getHeight());
// Inicializa variables // Inicializa variables
sp.clip_desp = 8; sp.cover_clip_desp = 8;
sp.clip_height = height; sp.cover_clip_height = HEIGHT;
sprite_pics_.push_back(sp); sprite_pics_.push_back(sp);
} }
@@ -327,7 +319,7 @@ void Ending::iniScenes()
{ {
// Variable para los tiempos // Variable para los tiempos
int trigger; int trigger;
const int lapse = 80; constexpr int LAPSE = 80;
// Crea el contenedor // Crea el contenedor
SceneData sc; SceneData sc;
@@ -340,13 +332,13 @@ void Ending::iniScenes()
sc.picture_index = 0; sc.picture_index = 0;
sc.text_index.clear(); sc.text_index.clear();
trigger = 85 * 2; trigger = 85 * 2;
trigger += lapse; trigger += LAPSE;
sc.text_index.push_back({0, trigger}); sc.text_index.push_back({0, trigger});
trigger += lapse; trigger += LAPSE;
sc.text_index.push_back({1, trigger}); sc.text_index.push_back({1, trigger});
trigger += lapse * 3; trigger += LAPSE * 3;
sc.text_index.push_back({2, trigger}); sc.text_index.push_back({2, trigger});
trigger += lapse; trigger += LAPSE;
sc.text_index.push_back({3, trigger}); sc.text_index.push_back({3, trigger});
scenes_.push_back(sc); scenes_.push_back(sc);
@@ -355,17 +347,17 @@ void Ending::iniScenes()
sc.picture_index = 1; sc.picture_index = 1;
sc.text_index.clear(); sc.text_index.clear();
trigger = 140 * 2; trigger = 140 * 2;
trigger += lapse; trigger += LAPSE;
sc.text_index.push_back({4, trigger}); sc.text_index.push_back({4, trigger});
trigger += lapse; trigger += LAPSE;
sc.text_index.push_back({5, trigger}); sc.text_index.push_back({5, trigger});
trigger += lapse; trigger += LAPSE;
sc.text_index.push_back({6, trigger}); sc.text_index.push_back({6, trigger});
trigger += lapse * 3; trigger += LAPSE * 3;
sc.text_index.push_back({7, trigger}); sc.text_index.push_back({7, trigger});
trigger += lapse; trigger += LAPSE;
sc.text_index.push_back({8, trigger}); sc.text_index.push_back({8, trigger});
trigger += lapse * 3; trigger += LAPSE * 3;
sc.text_index.push_back({9, trigger}); sc.text_index.push_back({9, trigger});
scenes_.push_back(sc); scenes_.push_back(sc);
@@ -374,9 +366,9 @@ void Ending::iniScenes()
sc.picture_index = 2; sc.picture_index = 2;
sc.text_index.clear(); sc.text_index.clear();
trigger = 148 / 2; trigger = 148 / 2;
trigger += lapse; trigger += LAPSE;
sc.text_index.push_back({10, trigger}); sc.text_index.push_back({10, trigger});
trigger += lapse; trigger += LAPSE;
sc.text_index.push_back({11, trigger}); sc.text_index.push_back({11, trigger});
scenes_.push_back(sc); scenes_.push_back(sc);
@@ -385,9 +377,9 @@ void Ending::iniScenes()
sc.picture_index = 3; sc.picture_index = 3;
sc.text_index.clear(); sc.text_index.clear();
trigger = 87 / 2; trigger = 87 / 2;
trigger += lapse; trigger += LAPSE;
sc.text_index.push_back({12, trigger}); sc.text_index.push_back({12, trigger});
trigger += lapse / 2; trigger += LAPSE / 2;
sc.text_index.push_back({13, trigger}); sc.text_index.push_back({13, trigger});
scenes_.push_back(sc); scenes_.push_back(sc);
@@ -396,11 +388,11 @@ void Ending::iniScenes()
sc.picture_index = 4; sc.picture_index = 4;
sc.text_index.clear(); sc.text_index.clear();
trigger = 91 * 2; trigger = 91 * 2;
trigger += lapse; trigger += LAPSE;
sc.text_index.push_back({14, trigger}); sc.text_index.push_back({14, trigger});
trigger += lapse * 2; trigger += LAPSE * 2;
sc.text_index.push_back({15, trigger}); sc.text_index.push_back({15, trigger});
trigger += lapse * 3; trigger += LAPSE * 3;
sc.text_index.push_back({16, trigger}); sc.text_index.push_back({16, trigger});
scenes_.push_back(sc); scenes_.push_back(sc);
} }
@@ -442,44 +434,45 @@ void Ending::updateCounters()
// Actualiza las cortinillas de los elementos // Actualiza las cortinillas de los elementos
void Ending::updateSpriteCovers() void Ending::updateSpriteCovers()
{ // Actualiza la cortinilla de los textos {
// Actualiza la cortinilla de los textos
if (counter_ % 4 == 0) if (counter_ % 4 == 0)
{ {
for (auto ti : scenes_[current_scene_].text_index) for (auto ti : scenes_.at(current_scene_).text_index)
{ {
if (counter_ > ti.trigger) if (counter_ > ti.trigger)
{ {
if (sprite_texts_[ti.index].clip_desp > 0) if (sprite_texts_.at(ti.index).cover_clip_desp > 0)
{ {
sprite_texts_[ti.index].clip_desp -= 2; sprite_texts_.at(ti.index).cover_clip_desp -= 2;
} }
else if (sprite_texts_[ti.index].clip_height > 0) else if (sprite_texts_.at(ti.index).cover_clip_height > 0)
{ {
sprite_texts_[ti.index].clip_height -= 2; sprite_texts_.at(ti.index).cover_clip_height -= 2;
sprite_texts_[ti.index].cover_sprite->setY(sprite_texts_[ti.index].cover_sprite->getY() + 2); sprite_texts_.at(ti.index).cover_sprite->setY(sprite_texts_.at(ti.index).cover_sprite->getY() + 2);
} }
sprite_texts_[ti.index].cover_sprite->setClip(0, sprite_texts_[ti.index].clip_desp, sprite_texts_[ti.index].cover_sprite->getWidth(), sprite_texts_[ti.index].clip_height); sprite_texts_.at(ti.index).cover_sprite->setClip(0, sprite_texts_.at(ti.index).cover_clip_desp, sprite_texts_.at(ti.index).cover_sprite->getWidth(), sprite_texts_.at(ti.index).cover_clip_height);
} }
} }
} }
// Actualiza la cortinilla de las imagenes // Actualiza la cortinilla de las imágenes
if (counter_ % 2 == 0) if (counter_ % 2 == 0)
{ {
if (sprite_pics_[current_scene_].clip_desp > 0) if (sprite_pics_.at(current_scene_).cover_clip_desp > 0)
{ {
sprite_pics_[current_scene_].clip_desp -= 2; sprite_pics_.at(current_scene_).cover_clip_desp -= 2;
} }
else if (sprite_pics_[current_scene_].clip_height > 0) else if (sprite_pics_.at(current_scene_).cover_clip_height > 0)
{ {
sprite_pics_[current_scene_].clip_height -= 2; sprite_pics_.at(current_scene_).cover_clip_height -= 2;
if (sprite_pics_[current_scene_].clip_height < 0) if (sprite_pics_.at(current_scene_).cover_clip_height < 0)
{ {
sprite_pics_[current_scene_].clip_height = 0; sprite_pics_.at(current_scene_).cover_clip_height = 0;
} }
sprite_pics_[current_scene_].cover_sprite->setY(sprite_pics_[current_scene_].cover_sprite->getY() + 2); sprite_pics_.at(current_scene_).cover_sprite->setY(sprite_pics_.at(current_scene_).cover_sprite->getY() + 2);
} }
sprite_pics_[current_scene_].cover_sprite->setClip(0, sprite_pics_[current_scene_].clip_desp, sprite_pics_[current_scene_].cover_sprite->getWidth(), sprite_pics_[current_scene_].clip_height); sprite_pics_.at(current_scene_).cover_sprite->setClip(0, sprite_pics_.at(current_scene_).cover_clip_desp, sprite_pics_.at(current_scene_).cover_sprite->getWidth(), sprite_pics_.at(current_scene_).cover_clip_height);
} }
} }
@@ -536,10 +529,11 @@ void Ending::fillCoverTexture()
void Ending::renderCoverTexture() void Ending::renderCoverTexture()
{ {
if (cover_counter_ > 0) if (cover_counter_ > 0)
{ // Dibuja la textura que cubre el texto {
const int offset = std::min(cover_counter_, 100); // Dibuja la textura que cubre el texto
SDL_Rect srcRect = {0, 200 - (cover_counter_ * 2), 256, offset * 2}; const int OFFSET = std::min(cover_counter_, 100);
SDL_Rect dstRect = {0, 0, 256, offset * 2}; SDL_Rect srcRect = {0, 200 - (cover_counter_ * 2), 256, OFFSET * 2};
SDL_Rect dstRect = {0, 0, 256, OFFSET * 2};
SDL_RenderCopy(Screen::get()->getRenderer(), cover_texture_, &srcRect, &dstRect); SDL_RenderCopy(Screen::get()->getRenderer(), cover_texture_, &srcRect, &dstRect);
} }
} }

View File

@@ -14,12 +14,12 @@ private:
// Estructuras // Estructuras
struct EndingTexture // Estructura con dos texturas y sprites, uno para mostrar y el otro hace de cortinilla struct EndingTexture // Estructura con dos texturas y sprites, uno para mostrar y el otro hace de cortinilla
{ {
std::shared_ptr<Texture> texture; // Textura a mostrar std::shared_ptr<Texture> image_texture; // Textura a mostrar
std::shared_ptr<Sprite> sprite; // Sprite para mostrar la textura std::shared_ptr<Sprite> image_sprite; // Sprite para mostrar la textura
std::shared_ptr<Texture> cover_texture; // Textura que cubre a la otra textura std::shared_ptr<Texture> cover_texture; // Textura que cubre a la otra textura
std::shared_ptr<Sprite> cover_sprite; // Sprite para mostrar la textura que cubre a la otra textura std::shared_ptr<Sprite> cover_sprite; // Sprite para mostrar la textura que cubre a la otra textura
int clip_desp; // Desplazamiento del spriteClip de la textura de cobertura int cover_clip_desp; // Desplazamiento del spriteClip de la textura de cobertura
int clip_height; // Altura del spriteClip de la textura de cobertura int cover_clip_height; // Altura del spriteClip de la textura de cobertura
}; };
struct TextAndPosition // Estructura con un texto y su posición en el eje Y struct TextAndPosition // Estructura con un texto y su posición en el eje Y

View File

@@ -6,7 +6,7 @@
#include <SDL2/SDL_timer.h> // for SDL_GetTicks #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <algorithm> // for max, min, replace #include <algorithm> // for max, min, replace
#include "animated_sprite.h" // for AnimatedSprite #include "animated_sprite.h" // for AnimatedSprite
#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_CENTER_X #include "defines.h" // for options.game.height, GAMECANVAS_CENTER_X
#include "global_events.h" // for check #include "global_events.h" // for check
#include "global_inputs.h" // for check #include "global_inputs.h" // for check
#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM... #include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM...
@@ -17,6 +17,7 @@
#include "text.h" // for Text #include "text.h" // for Text
#include "texture.h" // for Texture #include "texture.h" // for Texture
#include "utils.h" // for Color, stringToColor #include "utils.h" // for Color, stringToColor
#include <iostream>
// Constructor // Constructor
Ending2::Ending2() Ending2::Ending2()
@@ -279,9 +280,9 @@ void Ending2::loadSprites()
sprite_max_height_ = 0; sprite_max_height_ = 0;
// Carga los sprites // Carga los sprites
for (const auto &sl : sprite_list_) for (const auto &file : sprite_list_)
{ {
sprites_.emplace_back(std::make_shared<AnimatedSprite>(Resource::get()->getTexture(sl + ".png"), Resource::get()->getAnimations(sl + ".ani"))); sprites_.emplace_back(std::make_shared<AnimatedSprite>(Resource::get()->getTexture(file + ".png"), Resource::get()->getAnimations(file + ".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_);
} }
@@ -327,9 +328,9 @@ void Ending2::renderSprites()
const Color color = stringToColor(options.video.palette, "red"); const Color color = stringToColor(options.video.palette, "red");
for (auto sprite : sprites_) for (auto sprite : sprites_)
{ {
const bool a = sprite->getRect().y + sprite->getRect().h > 0; const bool A = sprite->getRect().y + sprite->getRect().h > 0;
const bool b = sprite->getRect().y < GAMECANVAS_HEIGHT; const bool B = sprite->getRect().y < options.game.height;
if (a && b) if (A && B)
{ {
sprite->getTexture()->setColor(color.r, color.g, color.b); sprite->getTexture()->setColor(color.r, color.g, color.b);
sprite->render(); sprite->render();
@@ -348,9 +349,9 @@ void Ending2::renderSpriteTexts()
const Color color = stringToColor(options.video.palette, "white"); const Color color = stringToColor(options.video.palette, "white");
for (auto sprite : sprite_texts_) for (auto sprite : sprite_texts_)
{ {
const bool a = sprite->getRect().y + sprite->getRect().h > 0; const bool A = sprite->getRect().y + sprite->getRect().h > 0;
const bool b = sprite->getRect().y < GAMECANVAS_HEIGHT; const bool B = sprite->getRect().y < options.game.height;
if (a && b) if (A && B)
{ {
sprite->getTexture()->setColor(color.r, color.g, color.b); sprite->getTexture()->setColor(color.r, color.g, color.b);
sprite->render(); sprite->render();
@@ -363,9 +364,9 @@ void Ending2::renderTexts()
{ {
for (auto sprite : texts_) for (auto sprite : texts_)
{ {
const bool a = sprite->getRect().y + sprite->getRect().h > 0; const bool A = sprite->getRect().y + sprite->getRect().h > 0;
const bool b = sprite->getRect().y < GAMECANVAS_HEIGHT; const bool B = sprite->getRect().y < options.game.height;
if (a && b) if (A && B)
{ {
sprite->render(); sprite->render();
} }
@@ -375,25 +376,23 @@ void Ending2::renderTexts()
// Coloca los sprites en su sito // Coloca los sprites en su sito
void Ending2::placeSprites() void Ending2::placeSprites()
{ {
for (int i = 0; i < (int)sprites_.size(); ++i) for (int i = 0; i < static_cast<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_ + Resource::get()->getText("smb2")->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_) + options.game.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)->setPos({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 sprite del jugador, que es el último de la lista
const int W = sprites_.back()->getWidth(); const int X = (options.game.width - sprites_.back()->getWidth()) / 2;
const int X = GAMECANVAS_CENTER_X - (W / 2);
const int Y = sprites_.back()->getPosY() + sprite_max_height_ * 2; const int Y = sprites_.back()->getPosY() + sprite_max_height_ * 2;
sprites_.back()->setPosX(X); sprites_.back()->setPos(X, Y);
sprites_.back()->setPosY(Y);
sprites_.back()->setCurrentAnimation("walk"); sprites_.back()->setCurrentAnimation("walk");
} }
@@ -456,7 +455,7 @@ void Ending2::createTexts()
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 = options.game.height + (text->getCharacterSize() * (i * 2));
// Crea la textura // Crea la textura
auto texture = std::make_shared<Texture>(Screen::get()->getRenderer()); auto texture = std::make_shared<Texture>(Screen::get()->getRenderer());
@@ -473,7 +472,7 @@ void Ending2::createTexts()
// 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!");
@@ -486,7 +485,7 @@ void Ending2::createTexts()
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>(Screen::get()->getRenderer()); auto texture = std::make_shared<Texture>(Screen::get()->getRenderer());

View File

@@ -663,20 +663,11 @@ 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_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, text->getCharacterSize() * 2); room_name_texture_ = createTexture(Screen::get()->getRenderer(), options.game.width, text->getCharacterSize() * 2);
if (room_name_texture_ == nullptr)
{
if (options.console)
{
std::cout << "Error: room_name_texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
// Establece el blend mode de la textura
SDL_SetTextureBlendMode(room_name_texture_, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(room_name_texture_, SDL_BLENDMODE_BLEND);
// Establece el destino de la textura // Establece el destino de la textura
room_name_rect_ = {0, PLAY_AREA_HEIGHT, GAMECANVAS_WIDTH, text->getCharacterSize() * 2}; room_name_rect_ = {0, PLAY_AREA_HEIGHT, options.game.width, text->getCharacterSize() * 2};
} }
// DEMO MODE: Inicializa las variables para el modo demo // DEMO MODE: Inicializa las variables para el modo demo

View File

@@ -33,14 +33,7 @@ LoadingScreen::LoadingScreen()
mono_loading_screen_sprite_ = std::make_shared<Sprite>(mono_loading_screen_texture_, 0, 0, mono_loading_screen_texture_->getWidth(), mono_loading_screen_texture_->getHeight()); mono_loading_screen_sprite_ = std::make_shared<Sprite>(mono_loading_screen_texture_, 0, 0, mono_loading_screen_texture_->getWidth(), mono_loading_screen_texture_->getHeight());
color_loading_screen_sprite_ = std::make_shared<Sprite>(color_loading_screen_texture_, 0, 0, color_loading_screen_texture_->getWidth(), color_loading_screen_texture_->getHeight()); color_loading_screen_sprite_ = std::make_shared<Sprite>(color_loading_screen_texture_, 0, 0, color_loading_screen_texture_->getWidth(), color_loading_screen_texture_->getHeight());
texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options.game.width, options.game.height); texture_ = createTexture(Screen::get()->getRenderer(), options.game.width, options.game.height);
if (texture_ == nullptr)
{
if (options.console)
{
std::cout << "LoadingScreen::texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
clearTexture(); clearTexture();
// Inicializa variables // Inicializa variables

View File

@@ -9,7 +9,7 @@ MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos, Rotat
rotate_(rotate), rotate_(rotate),
zoom_w_(zoom_w), zoom_w_(zoom_w),
zoom_h_(zoom_h), zoom_h_(zoom_h),
flip_(flip) {} flip_(flip) { Sprite::pos_ = pos; }
MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos) MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos)
: Sprite(texture, pos), : Sprite(texture, pos),
@@ -18,7 +18,7 @@ MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos)
rotate_(Rotate()), rotate_(Rotate()),
zoom_w_(1.0f), zoom_w_(1.0f),
zoom_h_(1.0f), zoom_h_(1.0f),
flip_(SDL_FLIP_NONE) {} flip_(SDL_FLIP_NONE) { Sprite::pos_ = pos; }
MovingSprite::MovingSprite(std::shared_ptr<Texture> texture) MovingSprite::MovingSprite(std::shared_ptr<Texture> texture)
: Sprite(texture), : Sprite(texture),

View File

@@ -21,7 +21,7 @@ void initOptions()
options = Options(); options = Options();
#ifdef DEBUG #ifdef DEBUG
options.section = SectionState(Section::DEMO, Subsection::NONE); options.section = SectionState(Section::ENDING2, Subsection::NONE);
options.console = true; options.console = true;
#else #else
options.section = SectionState(Section::LOGO, Subsection::LOGO_TO_INTRO); options.section = SectionState(Section::LOGO, Subsection::LOGO_TO_INTRO);

View File

@@ -415,15 +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_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT); map_texture_ = createTexture(Screen::get()->getRenderer(), PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT);
if (map_texture_ == nullptr)
{
if (options.console)
{
std::cout << "Error: mapTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
SDL_SetTextureBlendMode(map_texture_, SDL_BLENDMODE_BLEND);
// Pinta el mapa de la habitación en la textura // Pinta el mapa de la habitación en la textura
fillMapTexture(); fillMapTexture();

View File

@@ -27,14 +27,7 @@ Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
player_sprite_ = std::make_shared<AnimatedSprite>(player_texture, player_animations); player_sprite_ = std::make_shared<AnimatedSprite>(player_texture, player_animations);
player_sprite_->setCurrentAnimation("walk_menu"); player_sprite_->setCurrentAnimation("walk_menu");
texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, TEXTURE_WIDTH_, TEXTURE_HEIGHT_); texture_ = createTexture(Screen::get()->getRenderer(), TEXTURE_WIDTH_, TEXTURE_HEIGHT_);
if (texture_ == nullptr)
{
if (options.console)
{
std::cout << "Scorebard::texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
texture_dest_ = {0, options.game.height - TEXTURE_HEIGHT_, TEXTURE_WIDTH_, TEXTURE_HEIGHT_}; texture_dest_ = {0, options.game.height - TEXTURE_HEIGHT_, TEXTURE_WIDTH_, TEXTURE_HEIGHT_};
// Inicializa las variables // Inicializa las variables

View File

@@ -52,35 +52,13 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
SDL_RenderSetIntegerScale(renderer_, options.video.integer_scale ? SDL_TRUE : SDL_FALSE); SDL_RenderSetIntegerScale(renderer_, options.video.integer_scale ? SDL_TRUE : SDL_FALSE);
// Crea la textura donde se vuelcan las surfaces // Crea la textura donde se vuelcan las surfaces
surface_texture_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, options.game.width, options.game.height); surface_texture_ = createTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, options.game.width, options.game.height);
if (surface_texture_ == nullptr)
{
if (options.console)
{
std::cout << "surface_texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
//SDL_SetTextureBlendMode(surface_texture_, SDL_BLENDMODE_BLEND);
// Crea la textura donde se dibujan los graficos del juego // Crea la textura donde se dibujan los graficos del juego
game_texture_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options.game.width, options.game.height); game_texture_ = createTexture(renderer, options.game.width, options.game.height);
if (game_texture_ == nullptr)
{
if (options.console)
{
std::cout << "game_texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
// Crea la textura donde se dibuja el borde que rodea el area de juego // Crea la textura donde se dibuja el borde que rodea el area de juego
border_texture_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options.game.width + options.video.border.width * 2, options.game.height + options.video.border.height * 2); border_texture_ = createTexture(renderer,options.game.width + options.video.border.width * 2, options.game.height + options.video.border.height * 2);
if (border_texture_ == nullptr)
{
if (options.console)
{
std::cout << "border_texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
setBorderColor(border_color_); setBorderColor(border_color_);
// Crea la surface donde se pinta el juego // Crea la surface donde se pinta el juego

View File

@@ -27,14 +27,7 @@ Title::Title()
sprite_(std::make_shared<Sprite>(texture_, 0, 0, texture_->getWidth(), texture_->getHeight())) sprite_(std::make_shared<Sprite>(texture_, 0, 0, texture_->getWidth(), texture_->getHeight()))
{ {
// Crea la textura para los graficos que aparecen en el fondo de la pantalla de titulo // Crea la textura para los graficos que aparecen en el fondo de la pantalla de titulo
bg_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); bg_texture_ = createTexture(Screen::get()->getRenderer(), options.game.width, options.game.height);
if (bg_texture_ == nullptr)
{
if (options.console)
{
std::cout << "Error: bgTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
SDL_SetTextureBlendMode(bg_texture_, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(bg_texture_, SDL_BLENDMODE_BLEND);
// Carga la surface con los gráficos de la pantalla de carga // Carga la surface con los gráficos de la pantalla de carga

View File

@@ -551,3 +551,21 @@ void fillTextureWithColor(SDL_Renderer *renderer, SDL_Texture *texture, Uint8 r,
// Restaurar el render target previo // Restaurar el render target previo
SDL_SetRenderTarget(renderer, previous_target); SDL_SetRenderTarget(renderer, previous_target);
} }
// Crea un SDL_Texture
SDL_Texture *createTexture(SDL_Renderer *renderer, int width, int height, Uint32 format, int access, bool logError)
{
// Crear la textura
SDL_Texture *texture = SDL_CreateTexture(renderer, format, access, width, height);
if (texture == nullptr)
{
// Registrar el error si está habilitado
if (logError)
{
std::cerr << "Error: Texture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
return nullptr;
}
return texture;
}

View File

@@ -134,3 +134,6 @@ void playMusic(const std::string &music_path);
// Rellena una textura de un color // Rellena una textura de un color
void fillTextureWithColor(SDL_Renderer *renderer, SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b, Uint8 a); void fillTextureWithColor(SDL_Renderer *renderer, SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
// Crea un SDL_Texture
SDL_Texture *createTexture(SDL_Renderer *renderer, int width, int height, Uint32 format = SDL_PIXELFORMAT_RGBA8888, int access = SDL_TEXTUREACCESS_TARGET, bool logError = false);