Trabajando en el ending

This commit is contained in:
2022-11-03 12:42:11 +01:00
parent d514ed451f
commit c6779bfd77
4 changed files with 155 additions and 21 deletions

View File

@@ -12,6 +12,9 @@ Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset
// Reserva memoria para los punteros a objetos
eventHandler = new SDL_Event();
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
texture = resource->getTexture("ending1.png");
sprite = new Sprite({0, 0, texture->getWidth(), texture->getHeight()}, texture, renderer);
// Inicializa variables
counter = 0;
@@ -19,15 +22,36 @@ Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset
section.subsection = 0;
ticks = 0;
ticksSpeed = 15;
scene = 1;
sceneLenght.insert(sceneLenght.end(), {0, 100, 100, 100});
// Textos
texts.push_back("HE FINALLY MANAGED TO GET TO THE JAIL WITH ALL HIS PROJECTS READY TO BE RELEASED");
texts.push_back("ALL THE JAILERS WERE THERE WAITING FOR THE JAILGAMES TO BE RELEASED");
texts.push_back("THERE WERE EVEN BARRULLS AND BEGINNERS AMONG THE CROWD");
texts.push_back("BRY WAS CRYING...");
texts.push_back("BUT SUDDENLY SOMETHING CAUGHT HIS ATTENTION");
texts.push_back("A PILE OF JUNK! FULL OF NON WORKING THINGS!!");
texts.push_back("AND THEN, FOURTY NEW PROJECTS WERE BORN...");
// Inicializa los textos
iniTexts();
// Cambia el color del borde
screen->setBorderColor(stringToColor(options->palette, "black"));
// Crea la textura para el texto que se escribe en pantalla
canvasTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
if (canvasTexture == nullptr)
{
if (options->console)
{
std::cout << "Error: canvasTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
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);
if (coverTexture == nullptr)
{
if (options->console)
{
std::cout << "Error: canvasTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
SDL_SetTextureBlendMode(coverTexture, SDL_BLENDMODE_BLEND);
}
// Destructor
@@ -35,6 +59,10 @@ Ending::~Ending()
{
// Libera la memoria de los objetos
delete eventHandler;
delete text;
delete sprite;
SDL_DestroyTexture(canvasTexture);
SDL_DestroyTexture(coverTexture);
}
// Actualiza el objeto
@@ -60,6 +88,9 @@ void Ending::render()
// Limpia la pantalla
screen->clean();
// Dibuja la textura con el texto en pantalla
SDL_RenderCopy(renderer, canvasTexture, nullptr, nullptr);
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}
@@ -129,6 +160,91 @@ void Ending::checkEventHandler()
}
}
// Inicializa los textos
void Ending::iniTexts()
{
// Reinicia el vector
texts.clear();
// Escena #1
texts.push_back("HE FINALLY MANAGED TO GET");
texts.push_back("TO THE JAIL WITH ALL HIS");
texts.push_back("PROJECTS READY TO BE RELEASED");
// Escena #2
texts.push_back("ALL THE JAILERS WERE THERE");
texts.push_back("WAITING FOR THE JAILGAMES");
texts.push_back("TO BE RELEASED");
// Escena #3
texts.push_back("THERE WERE EVEN BARRULLS AND");
texts.push_back("BEGINNERS AMONG THE CROWD");
texts.push_back("BRY WAS CRYING...");
// Escena #4
texts.push_back("BUT SUDDENLY SOMETHING");
texts.push_back("CAUGHT HIS ATTENTION");
// Escena #5
texts.push_back("A PILE OF JUNK!");
texts.push_back("FULL OF NON WORKING THINGS!!");
texts.push_back("AND THEN, FOURTY NEW PROJECTS");
texts.push_back("WERE BORN...");
}
// Rellena la textura segun la escena
void Ending::fillTexture()
{
// Inicializa los textos
iniTexts();
// 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);
SDL_RenderClear(renderer);
// Escribe el texto en la textura
const int size = text->getCharacterSize();
int y = 20;
for (int i = 0; i < 3; ++i)
{
text->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, y, texts.at(i), 1, c);
y += size;
}
// Dibuja el sprite
const int x = (PLAY_AREA_WIDTH - texture->getWidth()) / 2;
sprite->setPos({x, y + 10});
SDL_SetRenderTarget(renderer, nullptr);
// Rellena la textura que cubre el texto
SDL_SetRenderTarget(renderer, coverTexture);
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0x00);
SDL_RenderClear(renderer);
// Los primeros 8 pixels crea una malla
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
for (int i = 0; i < 256; i += 2)
{
SDL_RenderDrawPoint(renderer, i, 0);
SDL_RenderDrawPoint(renderer, i, 2);
SDL_RenderDrawPoint(renderer, i, 4);
SDL_RenderDrawPoint(renderer, i, 6);
SDL_RenderDrawPoint(renderer, i + 1, 5);
SDL_RenderDrawPoint(renderer, i + 1, 7);
}
// El resto se rellena de color sólido
SDL_Rect rect = {0, 8, 256, 192};
SDL_RenderFillRect(renderer, &rect);
SDL_SetRenderTarget(renderer, nullptr);
}
// Bucle principal
section_t Ending::run()
{