Finalizada la primera parte del ending
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.5 KiB |
@@ -13,12 +13,12 @@ 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);
|
||||
music = JA_LoadMusic(asset->get("ending1.ogg").c_str());
|
||||
|
||||
// Inicializa variables
|
||||
counter = 0;
|
||||
counter = -1;
|
||||
preCounter = 0;
|
||||
coverCounter = 0;
|
||||
section.name = SECTION_PROG_ENDING;
|
||||
section.subsection = 0;
|
||||
ticks = 0;
|
||||
@@ -37,17 +37,6 @@ Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset
|
||||
// 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 + 8);
|
||||
if (coverTexture == nullptr)
|
||||
@@ -58,6 +47,9 @@ Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset
|
||||
}
|
||||
}
|
||||
SDL_SetTextureBlendMode(coverTexture, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Rellena la textura para la cortinilla
|
||||
fillCoverTexture();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -66,8 +58,6 @@ Ending::~Ending()
|
||||
// Libera la memoria de los objetos
|
||||
delete eventHandler;
|
||||
delete text;
|
||||
delete sprite;
|
||||
SDL_DestroyTexture(canvasTexture);
|
||||
SDL_DestroyTexture(coverTexture);
|
||||
|
||||
for (auto st : spriteTexts)
|
||||
@@ -103,7 +93,7 @@ void Ending::update()
|
||||
checkEventHandler();
|
||||
|
||||
// Actualiza el contador
|
||||
updateCounter();
|
||||
updateCounters();
|
||||
|
||||
// Actualiza las cortinillas de los elementos
|
||||
updateSpriteCovers();
|
||||
@@ -136,6 +126,9 @@ void Ending::render()
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja la cortinilla de cambio de escena
|
||||
renderCoverTexture();
|
||||
|
||||
// text->write(0, 0, std::to_string(counter));
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
@@ -221,8 +214,8 @@ void Ending::iniTexts()
|
||||
|
||||
// Escena #0
|
||||
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({"TO GET TO THE JAIL", 42});
|
||||
texts.push_back({"WITH ALL HIS PROJECTS", 142});
|
||||
texts.push_back({"READY TO BE RELEASED", 152});
|
||||
|
||||
// Escena #1
|
||||
@@ -237,15 +230,15 @@ void Ending::iniTexts()
|
||||
|
||||
// Escena #2
|
||||
texts.push_back({"BUT SUDDENLY SOMETHING", 19});
|
||||
texts.push_back({"CAUGHT HIS ATTENTION", 31});
|
||||
texts.push_back({"CAUGHT HIS ATTENTION", 29});
|
||||
|
||||
// Escena #3
|
||||
texts.push_back({"A PILE OF JUNK!", 36});
|
||||
texts.push_back({"FULL OF NON WORKING THINGS!!", 49});
|
||||
texts.push_back({"FULL OF NON WORKING THINGS!!", 46});
|
||||
|
||||
// Escena #4
|
||||
texts.push_back({"AND THEN,", 26});
|
||||
texts.push_back({"FOURTY NEW PROJECTS", 36});
|
||||
texts.push_back({"AND THEN,", 36});
|
||||
texts.push_back({"FOURTY NEW PROJECTS", 46});
|
||||
texts.push_back({"WERE BORN...", 158});
|
||||
|
||||
// Crea los sprites
|
||||
@@ -435,7 +428,7 @@ void Ending::iniScenes()
|
||||
sc.textIndex.push_back({5, trigger});
|
||||
trigger += lapse;
|
||||
sc.textIndex.push_back({6, trigger});
|
||||
trigger += lapse * 2;
|
||||
trigger += lapse * 3;
|
||||
sc.textIndex.push_back({7, trigger});
|
||||
trigger += lapse;
|
||||
sc.textIndex.push_back({8, trigger});
|
||||
@@ -447,8 +440,8 @@ void Ending::iniScenes()
|
||||
sc.counterEnd = 1000;
|
||||
sc.pictureIndex = 2;
|
||||
sc.textIndex.clear();
|
||||
trigger = 148 * 2;
|
||||
//trigger += lapse / 2;
|
||||
trigger = 148 / 2;
|
||||
trigger += lapse;
|
||||
sc.textIndex.push_back({10, trigger});
|
||||
trigger += lapse;
|
||||
sc.textIndex.push_back({11, trigger});
|
||||
@@ -458,8 +451,8 @@ void Ending::iniScenes()
|
||||
sc.counterEnd = 800;
|
||||
sc.pictureIndex = 3;
|
||||
sc.textIndex.clear();
|
||||
trigger = 87 * 2;
|
||||
//trigger += lapse;
|
||||
trigger = 87 / 2;
|
||||
trigger += lapse;
|
||||
sc.textIndex.push_back({12, trigger});
|
||||
trigger += lapse / 2;
|
||||
sc.textIndex.push_back({13, trigger});
|
||||
@@ -495,13 +488,25 @@ section_t Ending::run()
|
||||
return section;
|
||||
}
|
||||
|
||||
// Actualiza el contador
|
||||
void Ending::updateCounter()
|
||||
// Actualiza los contadores
|
||||
void Ending::updateCounters()
|
||||
{
|
||||
// Incrementa el contador
|
||||
if (preCounter < 200)
|
||||
{
|
||||
preCounter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
|
||||
if (counter > scenes.at(scene).counterEnd - 100)
|
||||
{
|
||||
coverCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las cortinillas de los elementos
|
||||
void Ending::updateSpriteCovers()
|
||||
{ // Actualiza la cortinilla de los textos
|
||||
@@ -552,9 +557,57 @@ void Ending::checkChangeScene()
|
||||
{
|
||||
scene++;
|
||||
counter = 0;
|
||||
coverCounter = 0;
|
||||
if (scene == 5)
|
||||
{
|
||||
scene = 4;
|
||||
section.name = SECTION_PROG_QUIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rellena la textura para la cortinilla
|
||||
void Ending::fillCoverTexture()
|
||||
{
|
||||
// Rellena la textura que cubre el texto con color transparente
|
||||
SDL_SetRenderTarget(renderer, coverTexture);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// Los primeros 8 pixels crea una malla
|
||||
const color_t c = stringToColor(options->palette, "brack");
|
||||
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
||||
for (int i = 0; i < 256; i += 2)
|
||||
{
|
||||
SDL_RenderDrawPoint(renderer, i + 0, GAMECANVAS_HEIGHT + 0);
|
||||
SDL_RenderDrawPoint(renderer, i + 1, GAMECANVAS_HEIGHT + 1);
|
||||
SDL_RenderDrawPoint(renderer, i + 0, GAMECANVAS_HEIGHT + 2);
|
||||
SDL_RenderDrawPoint(renderer, i + 1, GAMECANVAS_HEIGHT + 3);
|
||||
|
||||
SDL_RenderDrawPoint(renderer, i, GAMECANVAS_HEIGHT + 4);
|
||||
SDL_RenderDrawPoint(renderer, i, GAMECANVAS_HEIGHT + 6);
|
||||
}
|
||||
|
||||
// El resto se rellena de color sólido
|
||||
SDL_Rect rect = {0, 0, 256, GAMECANVAS_HEIGHT};
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
}
|
||||
|
||||
// Dibuja la cortinilla de cambio de escena
|
||||
void Ending::renderCoverTexture()
|
||||
{
|
||||
if (coverCounter > 0)
|
||||
{ // Dibuja la textura que cubre el texto
|
||||
// const int offset = std::min(coverCounter, 200 / 2);
|
||||
// SDL_Rect srcRect = {0, 0, 256, 200 - (offset * 2)};
|
||||
// SDL_Rect dstRect = {0, offset * 2, 256, 200 - (offset * 2)};
|
||||
// SDL_RenderCopy(renderer, coverTexture, &srcRect, &dstRect);
|
||||
|
||||
const int offset = std::min(coverCounter, 100);
|
||||
SDL_Rect srcRect = {0, 200 - (coverCounter * 2), 256, offset * 2};
|
||||
SDL_Rect dstRect = {0, 0, 256, offset * 2};
|
||||
SDL_RenderCopy(renderer, coverTexture, &srcRect, &dstRect);
|
||||
}
|
||||
}
|
||||
@@ -57,13 +57,12 @@ private:
|
||||
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
|
||||
int preCounter; // Contador previo
|
||||
int coverCounter; // Contador para la cortinilla
|
||||
section_t section; // Estado del bucle principal para saber si continua o se sale
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
@@ -91,8 +90,8 @@ private:
|
||||
// Inicializa las escenas
|
||||
void iniScenes();
|
||||
|
||||
// Actualiza el contador
|
||||
void updateCounter();
|
||||
// Actualiza los contadores
|
||||
void updateCounters();
|
||||
|
||||
// Actualiza las cortinillas de los elementos
|
||||
void updateSpriteCovers();
|
||||
@@ -100,6 +99,12 @@ private:
|
||||
// Comprueba si se ha de cambiar de escena
|
||||
void checkChangeScene();
|
||||
|
||||
// Rellena la textura para la cortinilla
|
||||
void fillCoverTexture();
|
||||
|
||||
// Dibuja la cortinilla de cambio de escena
|
||||
void renderCoverTexture();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options);
|
||||
|
||||
Reference in New Issue
Block a user