Trabajando en el ending
This commit is contained in:
@@ -130,10 +130,9 @@ void Credits::checkEventHandler()
|
||||
}
|
||||
}
|
||||
|
||||
// Escribe el texto en la textura
|
||||
void Credits::fillTexture()
|
||||
// Inicializa los textos
|
||||
void Credits::iniTexts()
|
||||
{
|
||||
// Inicializa los textos
|
||||
texts.clear();
|
||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
||||
texts.push_back({"INSTRUCTIONS:", stringToColor(options->palette, "yellow")});
|
||||
@@ -162,7 +161,14 @@ void Credits::fillTexture()
|
||||
|
||||
texts.push_back({"I LOVE JAILGAMES! ", 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
|
||||
SDL_SetRenderTarget(renderer, textTexture);
|
||||
const color_t c = stringToColor(options->palette, "black");
|
||||
|
||||
@@ -58,6 +58,9 @@ private:
|
||||
// Actualiza el contador
|
||||
void updateCounter();
|
||||
|
||||
// Inicializa los textos
|
||||
void iniTexts();
|
||||
|
||||
// Escribe el texto en la textura
|
||||
void fillTexture();
|
||||
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -20,16 +20,17 @@ class Ending
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
Resource *resource; // Objeto con los recursos
|
||||
Asset *asset; // Objeto con los ficheros de recursos
|
||||
options_t *options; // Puntero a las opciones del juego
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
Text *text; // Objeto para escribir texto en pantalla
|
||||
SDL_Texture *textTexture; // Textura para dibujar el texto
|
||||
SDL_Texture *coverTexture; // Textura para cubrir el texto
|
||||
AnimatedSprite *sprite; // Sprite para el brillo del corazón
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
Resource *resource; // Objeto con los recursos
|
||||
Asset *asset; // Objeto con los ficheros de recursos
|
||||
options_t *options; // Puntero a las opciones del juego
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
Text *text; // Objeto para escribir texto en pantalla
|
||||
SDL_Texture *canvasTexture; // Textura para dibujar el texto y los dibujos
|
||||
SDL_Texture *coverTexture; // Textura para cubrir el texto
|
||||
Texture *texture; // Textura con los graficos
|
||||
Sprite *sprite; // Sprite para dibujar las imagenes
|
||||
|
||||
// Variables
|
||||
int counter; // Contador
|
||||
@@ -37,6 +38,8 @@ private:
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
std::vector<std::string> texts; // Vector con los textos
|
||||
int scene; // Escena actual
|
||||
std::vector<int> sceneLenght; // Duracion de cada escena
|
||||
|
||||
// Actualiza el objeto
|
||||
void update();
|
||||
@@ -47,6 +50,12 @@ private:
|
||||
// Comprueba el manejador de eventos
|
||||
void checkEventHandler();
|
||||
|
||||
// Inicializa los textos
|
||||
void iniTexts();
|
||||
|
||||
// Rellena la textura segun la escena
|
||||
void fillTexture();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options);
|
||||
|
||||
Reference in New Issue
Block a user