Transició a surface acabada. Ja compila
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <algorithm> // for min
|
||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||
#include "defines.h" // for GAMECANVAS_HEIGHT, options.game.width
|
||||
#include "defines.h" // for options.game.height, options.game.width
|
||||
#include "global_events.h" // for check
|
||||
#include "global_inputs.h" // for check
|
||||
#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM...
|
||||
@@ -43,19 +43,12 @@ Ending::Ending()
|
||||
Screen::get()->setBorderColor(stringToColor("black"));
|
||||
|
||||
// Crea la textura para cubrir el texto
|
||||
cover_surface_ = createTexture(Screen::get()->getRenderer(), options.game.width, options.game.height + 8);
|
||||
SDL_SetTextureBlendMode(cover_surface_, SDL_BLENDMODE_BLEND);
|
||||
cover_surface_ = std::make_shared<Surface>(Screen::get()->getRenderSurfaceData(), options.game.width, options.game.height + 8);
|
||||
|
||||
// Rellena la textura para la cortinilla
|
||||
fillCoverTexture();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Ending::~Ending()
|
||||
{
|
||||
SDL_DestroyTexture(cover_surface_);
|
||||
}
|
||||
|
||||
// Actualiza el objeto
|
||||
void Ending::update()
|
||||
{
|
||||
@@ -91,7 +84,7 @@ void Ending::render()
|
||||
Screen::get()->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
Screen::get()->clean(stringToColor("yellow"));
|
||||
Screen::get()->clear(stringToColor("yellow"));
|
||||
|
||||
// Dibuja las imagenes de la escena
|
||||
sprite_pics_.at(current_scene_).image_sprite->render();
|
||||
@@ -176,7 +169,7 @@ void Ending::iniTexts()
|
||||
const int HEIGHT = text->getCharacterSize() + 2 + 2;
|
||||
Uint8 color = stringToColor("black");
|
||||
|
||||
EndingTexture st;
|
||||
EndingSurface st;
|
||||
|
||||
// Crea la textura
|
||||
st.image_surface = std::make_shared<Surface>(Screen::get()->getRenderSurfaceData(), WIDTH, HEIGHT);
|
||||
@@ -192,7 +185,7 @@ void Ending::iniTexts()
|
||||
Screen::get()->setRenderSurfaceData(st.cover_surface);
|
||||
|
||||
// Rellena la cover_surface con color transparente
|
||||
Screen::get()->clean(stringToColor("transparent"));
|
||||
Screen::get()->clear(stringToColor("transparent"));
|
||||
|
||||
// Crea una malla de 8 pixels de alto
|
||||
auto surface = Screen::get()->getRenderSurfaceData();
|
||||
@@ -243,7 +236,7 @@ void Ending::iniPics()
|
||||
|
||||
for (const auto &pic : pics)
|
||||
{
|
||||
EndingTexture sp;
|
||||
EndingSurface sp;
|
||||
|
||||
// Crea la texture
|
||||
sp.image_surface = Resource::get()->getSurface(pic.caption);
|
||||
@@ -259,7 +252,7 @@ void Ending::iniPics()
|
||||
Screen::get()->setRenderSurfaceData(sp.cover_surface);
|
||||
|
||||
// Rellena la cover_surface con color transparente
|
||||
Screen::get()->clean(stringToColor("transparent"));
|
||||
Screen::get()->clear(stringToColor("transparent"));
|
||||
|
||||
// Crea una malla en los primeros 8 pixels
|
||||
auto surface = Screen::get()->getRenderSurfaceData();
|
||||
@@ -479,29 +472,29 @@ void Ending::checkChangeScene()
|
||||
void Ending::fillCoverTexture()
|
||||
{
|
||||
// Rellena la textura que cubre el texto con color transparente
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), cover_surface_);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);
|
||||
SDL_RenderClear(Screen::get()->getRenderer());
|
||||
Screen::get()->setRenderSurfaceData(cover_surface_);
|
||||
Screen::get()->clear(stringToColor("transparent"));
|
||||
|
||||
// Los primeros 8 pixels crea una malla
|
||||
const Uint8 color = stringToColor("black");
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF);
|
||||
auto surface = Screen::get()->getRenderSurfaceData();
|
||||
for (int i = 0; i < 256; i += 2)
|
||||
{
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 0, GAMECANVAS_HEIGHT + 0);
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, GAMECANVAS_HEIGHT + 1);
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 0, GAMECANVAS_HEIGHT + 2);
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i + 1, GAMECANVAS_HEIGHT + 3);
|
||||
|
||||
cover_surface_->putPixel(surface, i + 0, options.game.height + 0, color);
|
||||
cover_surface_->putPixel(surface, i + 1, options.game.height + 1, color);
|
||||
cover_surface_->putPixel(surface, i + 0, options.game.height + 2, color);
|
||||
cover_surface_->putPixel(surface, i + 1, options.game.height + 3, color);
|
||||
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, GAMECANVAS_HEIGHT + 4);
|
||||
SDL_RenderDrawPoint(Screen::get()->getRenderer(), i, GAMECANVAS_HEIGHT + 6);
|
||||
cover_surface_->putPixel(surface, i, options.game.height + 4, color);
|
||||
cover_surface_->putPixel(surface, i, options.game.height + 6, color);
|
||||
}
|
||||
|
||||
// El resto se rellena de color sólido
|
||||
SDL_Rect rect = {0, 0, 256, GAMECANVAS_HEIGHT};
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
|
||||
SDL_Rect rect = {0, 0, 256, options.game.height};
|
||||
cover_surface_->fillRect(surface, &rect, color);
|
||||
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
|
||||
Screen::get()->setRenderSurfaceData(nullptr);
|
||||
}
|
||||
|
||||
// Dibuja la cortinilla de cambio de escena
|
||||
@@ -513,7 +506,7 @@ void Ending::renderCoverTexture()
|
||||
const int OFFSET = std::min(cover_counter_, 100);
|
||||
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_surface_, &srcRect, &dstRect);
|
||||
cover_surface_->render(&srcRect, &dstRect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user