Trabajando en el ending

This commit is contained in:
2022-11-03 21:25:39 +01:00
parent a2d8312bb7
commit 0b1b9f2d15
3 changed files with 198 additions and 52 deletions

View File

@@ -18,12 +18,15 @@ Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset
// Inicializa variables
counter = 0;
counterEnabled = true;
subCounter = 0;
section.name = SECTION_PROG_ENDING;
section.subsection = 0;
ticks = 0;
ticksSpeed = 15;
scene = 0;
scene = -1;
sceneLenght.insert(sceneLenght.end(), {0, 100, 100, 100});
pause = false;
// Inicializa los textos
iniTexts();
@@ -43,7 +46,7 @@ Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset
SDL_SetTextureBlendMode(canvasTexture, SDL_BLENDMODE_BLEND);
// Crea la textura para cubrir el rexto
coverTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
coverTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT + 8);
if (coverTexture == nullptr)
{
if (options->console)
@@ -79,6 +82,14 @@ void Ending::update()
// Comprueba el manejador de eventos
checkEventHandler();
if (pause)
{
return;
}
// Actualiza el contador
updateCounter();
}
}
@@ -91,9 +102,12 @@ void Ending::render()
// Limpia la pantalla
screen->clean();
// Dibuja la textura con el texto en pantalla
// Dibuja la canvasTexture
SDL_RenderCopy(renderer, canvasTexture, nullptr, nullptr);
// Dibuja la coverTexture
renderCoverTexture();
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}
@@ -120,6 +134,10 @@ void Ending::checkEventHandler()
// section.name = SECTION_PROG_QUIT;
break;
case SDL_SCANCODE_P:
pause = !pause;
break;
case SDL_SCANCODE_B:
screen->switchBorder();
resource->reLoadTextures();
@@ -180,33 +198,57 @@ void Ending::iniTexts()
texts.clear();
// Escena #0
texts.push_back("HE FINALLY MANAGED");
texts.push_back("TO GET TO THE JAIL");
texts.push_back("WITH ALL HIS PROJECTS");
texts.push_back("READY TO BE RELEASED");
texts.push_back({"HE FINALLY MANAGED", 32});
texts.push_back({"TO GET TO THE JAIL", 43});
texts.push_back({"WITH ALL HIS PROJECTS", 141});
texts.push_back({"READY TO BE RELEASED", 152});
// Escena #1
texts.push_back("ALL THE JAILERS WERE THERE");
texts.push_back("WAITING FOR THE JAILGAMES");
texts.push_back("TO BE RELEASED");
texts.push_back({"ALL THE JAILERS WERE THERE", 1});
texts.push_back({"WAITING FOR THE JAILGAMES", 11});
texts.push_back({"TO BE RELEASED", 21});
texts.push_back("THERE WERE EVEN BARRULLS AND");
texts.push_back("BEGINNERS AMONG THE CROWD");
texts.push_back({"THERE WERE EVEN BARRULLS AND", 161});
texts.push_back({"BEGINNERS AMONG THE CROWD", 171});
texts.push_back("BRY WAS CRYING...");
texts.push_back({"BRY WAS CRYING...", 181});
// Escena #2
texts.push_back("BUT SUDDENLY SOMETHING");
texts.push_back("CAUGHT HIS ATTENTION");
texts.push_back({"BUT SUDDENLY SOMETHING", 19});
texts.push_back({"CAUGHT HIS ATTENTION", 31});
// Escena #3
texts.push_back("A PILE OF JUNK!");
texts.push_back("FULL OF NON WORKING THINGS!!");
texts.push_back({"A PILE OF JUNK!", 36});
texts.push_back({"FULL OF NON WORKING THINGS!!", 49});
// Escena #4
texts.push_back("AND THEN,");
texts.push_back("FOURTY NEW PROJECTS");
texts.push_back("WERE BORN...");
texts.push_back({"AND THEN,", 26});
texts.push_back({"FOURTY NEW PROJECTS", 36});
texts.push_back({"WERE BORN...", 158});
// Crea los sprites
for (auto st : spriteTexts)
{
delete st.sprite;
delete st.texture;
}
spriteTexts.clear();
for (auto t : texts)
{
endingTexture_t st;
const int width = text->lenght(t.caption, 1) + 2 + 2;
const int height = text->getCharacterSize() + 2 + 2;
const color_t c = stringToColor(options->palette, "black");
st.texture = new Texture(renderer);
st.texture->createBlank(renderer, width, height, SDL_TEXTUREACCESS_TARGET);
st.texture->setAsRenderTarget(renderer);
st.texture->setBlendMode(SDL_BLENDMODE_BLEND);
text->writeDX(TXT_STROKE, 2, 2, t.caption, 1, c, 2, c);
st.sprite = new Sprite({0, 0, st.texture->getWidth(), st.texture->getHeight()}, st.texture, renderer);
st.sprite->setPos({(GAMECANVAS_WIDTH - st.texture->getWidth()) / 2, t.pos});
spriteTexts.push_back(st);
}
}
// Rellena la textura segun la escena
@@ -217,8 +259,8 @@ void Ending::fillTexture()
// Rellena la canvasTexture de color
SDL_SetRenderTarget(renderer, canvasTexture);
const color_t c = stringToColor(options->palette, "black");
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0x00);
color_t c = stringToColor(options->palette, "green");
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
SDL_RenderClear(renderer);
const int size = text->getCharacterSize();
@@ -235,15 +277,19 @@ void Ending::fillTexture()
sprite->render();
// Dos lineas de texto
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 34, texts.at(0), 1, c, 2, c);
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 45, texts.at(1), 1, c, 2, c);
// text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 34, texts.at(0), 1, c, 2, c);
// text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 45, texts.at(1), 1, c, 2, c);
spriteTexts.at(0).sprite->render();
spriteTexts.at(1).sprite->render();
// Dos lineas más de texto
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 143, texts.at(2), 1, c, 2, c);
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 154, texts.at(3), 1, c, 2, c);
// text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 143, texts.at(2), 1, c, 2, c);
// text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 154, texts.at(3), 1, c, 2, c);
spriteTexts.at(2).sprite->render();
spriteTexts.at(3).sprite->render();
}
if (scene == 1)
else if (scene == 1)
{ // Compone la escena #1
// Dibuja el sprite
@@ -256,19 +302,25 @@ void Ending::fillTexture()
sprite->render();
// Tres lineas de texto
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 3, texts.at(4), 1, c, 2, c);
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 13, texts.at(5), 1, c, 2, c);
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 23, texts.at(6), 1, c, 2, c);
// text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 3, texts.at(4), 1, c, 2, c);
// text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 13, texts.at(5), 1, c, 2, c);
// text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 23, texts.at(6), 1, c, 2, c);
spriteTexts.at(4).sprite->render();
spriteTexts.at(5).sprite->render();
spriteTexts.at(6).sprite->render();
// Dos lineas más de texto
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 163, texts.at(7), 1, c, 2, c);
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 173, texts.at(8), 1, c, 2, c);
// text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 163, texts.at(7), 1, c, 2, c);
// text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 173, texts.at(8), 1, c, 2, c);
spriteTexts.at(7).sprite->render();
spriteTexts.at(8).sprite->render();
// Una linea mas
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 183, texts.at(9), 1, c, 2, c);
// text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 183, texts.at(9), 1, c, 2, c);
spriteTexts.at(9).sprite->render();
}
if (scene == 2)
else if (scene == 2)
{ // Compone la escena #2
// Dibuja el sprite
@@ -280,11 +332,13 @@ void Ending::fillTexture()
sprite->render();
// Dos lineas de texto
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 21, texts.at(10), 1, c, 2, c);
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 33, texts.at(11), 1, c, 2, c);
// text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 21, texts.at(10), 1, c, 2, c);
// text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 33, texts.at(11), 1, c, 2, c);
spriteTexts.at(10).sprite->render();
spriteTexts.at(11).sprite->render();
}
if (scene == 3)
else if (scene == 3)
{ // Compone la escena #3
// Dibuja el sprite
@@ -296,11 +350,13 @@ void Ending::fillTexture()
sprite->render();
// Dos lineas de texto
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 38, texts.at(12), 1, c, 2, c);
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 51, texts.at(13), 1, c, 2, c);
// text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 38, texts.at(12), 1, c, 2, c);
// text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 51, texts.at(13), 1, c, 2, c);
spriteTexts.at(12).sprite->render();
spriteTexts.at(13).sprite->render();
}
if (scene == 4)
else if (scene == 4)
{ // Compone la escena #4
// Dibuja el sprite
@@ -312,21 +368,32 @@ void Ending::fillTexture()
sprite->render();
// Dos lineas de texto
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 28, texts.at(14), 1, c, 2, c);
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 38, texts.at(15), 1, c, 2, c);
// text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 28, texts.at(14), 1, c, 2, c);
// text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 38, texts.at(15), 1, c, 2, c);
spriteTexts.at(14).sprite->render();
spriteTexts.at(15).sprite->render();
// Una linea mas
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 160, texts.at(16), 1, c, 2, c);
// text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, 160, texts.at(16), 1, c, 2, c);
spriteTexts.at(16).sprite->render();
}
else if (scene == -1)
{ // Compone la escena # -1
text->write(0, 182, "SCENE -1");
spriteTexts.at(0).sprite->render();
}
SDL_SetRenderTarget(renderer, nullptr);
// Rellena la textura que cubre el texto
// Rellena la coverTexture con color transparente
SDL_SetRenderTarget(renderer, coverTexture);
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0x00);
SDL_RenderClear(renderer);
// Los primeros 8 pixels crea una malla
c = stringToColor(options->palette, "red");
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
for (int i = 0; i < 256; i += 2)
{
@@ -341,6 +408,8 @@ void Ending::fillTexture()
// El resto se rellena de color sólido
SDL_Rect rect = {0, 8, 256, 192};
c = stringToColor(options->palette, "cyan");
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
SDL_RenderFillRect(renderer, &rect);
SDL_SetRenderTarget(renderer, nullptr);
@@ -356,4 +425,58 @@ section_t Ending::run()
}
return section;
}
// Actualiza el contador
void Ending::updateCounter()
{
if (scene == -1)
{
return;
}
// Incrementa el contador
if (counterEnabled)
{
counter++;
}
else
{
subCounter++;
if (subCounter == 100)
{
counterEnabled = true;
subCounter = 0;
}
}
// Comprueba si ha terminado la sección
if (counter > 600)
{
scene++;
fillTexture();
counter = 0;
if (scene == 5)
{
section.name = SECTION_PROG_QUIT;
}
}
}
// Dibuja la coverTexture
void Ending::renderCoverTexture()
{
if (scene == -1)
{
return;
}
if (counter < 1150)
{
// Dibuja la textura que cubre el texto
const int offset = std::min(counter / 2, 200 / 2);
SDL_Rect srcRect = {0, 0, 256, 200 - (offset * 2)};
SDL_Rect dstRect = {0, (offset * 2) - 8, 256, 200 - (offset * 2)};
SDL_RenderCopy(renderer, coverTexture, &srcRect, &dstRect);
}
}