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

@@ -130,10 +130,9 @@ void Credits::checkEventHandler()
} }
} }
// Escribe el texto en la textura
void Credits::fillTexture()
{
// Inicializa los textos // Inicializa los textos
void Credits::iniTexts()
{
texts.clear(); texts.clear();
texts.push_back({"", stringToColor(options->palette, "white")}); texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"INSTRUCTIONS:", stringToColor(options->palette, "yellow")}); texts.push_back({"INSTRUCTIONS:", stringToColor(options->palette, "yellow")});
@@ -162,6 +161,13 @@ void Credits::fillTexture()
texts.push_back({"I LOVE JAILGAMES! ", stringToColor(options->palette, "white")}); texts.push_back({"I LOVE JAILGAMES! ", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")}); texts.push_back({"", stringToColor(options->palette, "white")});
}
// Escribe el texto en la textura
void Credits::fillTexture()
{
// Inicializa los textos
iniTexts();
// Rellena la textura de texto // Rellena la textura de texto
SDL_SetRenderTarget(renderer, textTexture); SDL_SetRenderTarget(renderer, textTexture);

View File

@@ -58,6 +58,9 @@ private:
// Actualiza el contador // Actualiza el contador
void updateCounter(); void updateCounter();
// Inicializa los textos
void iniTexts();
// Escribe el texto en la textura // Escribe el texto en la textura
void fillTexture(); void fillTexture();

View File

@@ -12,6 +12,9 @@ Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset
// Reserva memoria para los punteros a objetos // Reserva memoria para los punteros a objetos
eventHandler = new SDL_Event(); 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 // Inicializa variables
counter = 0; counter = 0;
@@ -19,15 +22,36 @@ Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset
section.subsection = 0; section.subsection = 0;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
scene = 1;
sceneLenght.insert(sceneLenght.end(), {0, 100, 100, 100});
// Textos // Inicializa los textos
texts.push_back("HE FINALLY MANAGED TO GET TO THE JAIL WITH ALL HIS PROJECTS READY TO BE RELEASED"); iniTexts();
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"); // Cambia el color del borde
texts.push_back("BRY WAS CRYING..."); screen->setBorderColor(stringToColor(options->palette, "black"));
texts.push_back("BUT SUDDENLY SOMETHING CAUGHT HIS ATTENTION");
texts.push_back("A PILE OF JUNK! FULL OF NON WORKING THINGS!!"); // Crea la textura para el texto que se escribe en pantalla
texts.push_back("AND THEN, FOURTY NEW PROJECTS WERE BORN..."); 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 // Destructor
@@ -35,6 +59,10 @@ Ending::~Ending()
{ {
// Libera la memoria de los objetos // Libera la memoria de los objetos
delete eventHandler; delete eventHandler;
delete text;
delete sprite;
SDL_DestroyTexture(canvasTexture);
SDL_DestroyTexture(coverTexture);
} }
// Actualiza el objeto // Actualiza el objeto
@@ -60,6 +88,9 @@ void Ending::render()
// Limpia la pantalla // Limpia la pantalla
screen->clean(); screen->clean();
// Dibuja la textura con el texto en pantalla
SDL_RenderCopy(renderer, canvasTexture, nullptr, nullptr);
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
screen->blit(); 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 // Bucle principal
section_t Ending::run() section_t Ending::run()
{ {

View File

@@ -27,9 +27,10 @@ private:
options_t *options; // Puntero a las opciones del juego options_t *options; // Puntero a las opciones del juego
SDL_Event *eventHandler; // Manejador de eventos SDL_Event *eventHandler; // Manejador de eventos
Text *text; // Objeto para escribir texto en pantalla Text *text; // Objeto para escribir texto en pantalla
SDL_Texture *textTexture; // Textura para dibujar el texto SDL_Texture *canvasTexture; // Textura para dibujar el texto y los dibujos
SDL_Texture *coverTexture; // Textura para cubrir el texto SDL_Texture *coverTexture; // Textura para cubrir el texto
AnimatedSprite *sprite; // Sprite para el brillo del corazón Texture *texture; // Textura con los graficos
Sprite *sprite; // Sprite para dibujar las imagenes
// Variables // Variables
int counter; // Contador int counter; // Contador
@@ -37,6 +38,8 @@ private:
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
std::vector<std::string> texts; // Vector con los textos std::vector<std::string> texts; // Vector con los textos
int scene; // Escena actual
std::vector<int> sceneLenght; // Duracion de cada escena
// Actualiza el objeto // Actualiza el objeto
void update(); void update();
@@ -47,6 +50,12 @@ private:
// Comprueba el manejador de eventos // Comprueba el manejador de eventos
void checkEventHandler(); void checkEventHandler();
// Inicializa los textos
void iniTexts();
// Rellena la textura segun la escena
void fillTexture();
public: public:
// Constructor // Constructor
Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options); Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options);