Trabajando en el ending
This commit is contained in:
@@ -24,13 +24,16 @@ 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;
|
scene = 0;
|
||||||
sceneLenght.insert(sceneLenght.end(), {0, 100, 100, 100});
|
sceneLenght.insert(sceneLenght.end(), {0, 100, 100, 100});
|
||||||
pause = false;
|
pause = false;
|
||||||
|
|
||||||
// Inicializa los textos
|
// Inicializa los textos
|
||||||
iniTexts();
|
iniTexts();
|
||||||
|
|
||||||
|
// Inicializa las escenas
|
||||||
|
iniScenes();
|
||||||
|
|
||||||
// Cambia el color del borde
|
// Cambia el color del borde
|
||||||
screen->setBorderColor(stringToColor(options->palette, "black"));
|
screen->setBorderColor(stringToColor(options->palette, "black"));
|
||||||
|
|
||||||
@@ -57,7 +60,7 @@ Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset
|
|||||||
SDL_SetTextureBlendMode(coverTexture, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(coverTexture, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
// Rellena la textura segun la escena
|
// Rellena la textura segun la escena
|
||||||
fillTexture();
|
// fillTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -116,19 +119,27 @@ void Ending::render()
|
|||||||
// Dibuja la coverTexture
|
// Dibuja la coverTexture
|
||||||
// renderCoverTexture();
|
// renderCoverTexture();
|
||||||
|
|
||||||
if (scene == 0)
|
// if (scene == 0)
|
||||||
{
|
//{
|
||||||
spriteTexts.at(0).sprite->render();
|
// spriteTexts.at(0).sprite->render();
|
||||||
spriteTexts.at(1).sprite->render();
|
// spriteTexts.at(1).sprite->render();
|
||||||
spriteTexts.at(2).sprite->render();
|
// spriteTexts.at(2).sprite->render();
|
||||||
spriteTexts.at(3).sprite->render();
|
// spriteTexts.at(3).sprite->render();
|
||||||
|
//
|
||||||
|
// spriteTexts.at(0).coverSprite->render();
|
||||||
|
// spriteTexts.at(1).coverSprite->render();
|
||||||
|
// spriteTexts.at(2).coverSprite->render();
|
||||||
|
// spriteTexts.at(3).coverSprite->render();
|
||||||
|
//}
|
||||||
|
|
||||||
spriteTexts.at(0).coverSprite->render();
|
for (auto ti : scenes.at(scene).textIndex)
|
||||||
spriteTexts.at(1).coverSprite->render();
|
{
|
||||||
spriteTexts.at(2).coverSprite->render();
|
spriteTexts.at(ti.index).sprite->render();
|
||||||
spriteTexts.at(3).coverSprite->render();
|
spriteTexts.at(ti.index).coverSprite->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
text->write(0, 0, std::to_string(counter));
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
screen->blit();
|
||||||
}
|
}
|
||||||
@@ -195,12 +206,12 @@ void Ending::checkEventHandler()
|
|||||||
|
|
||||||
case SDL_SCANCODE_RIGHT:
|
case SDL_SCANCODE_RIGHT:
|
||||||
++scene %= 5;
|
++scene %= 5;
|
||||||
fillTexture();
|
// fillTexture();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_SCANCODE_LEFT:
|
case SDL_SCANCODE_LEFT:
|
||||||
--scene %= 5;
|
--scene %= 5;
|
||||||
fillTexture();
|
// fillTexture();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -308,10 +319,71 @@ void Ending::iniTexts()
|
|||||||
st.coverSprite->setPos({(GAMECANVAS_WIDTH - st.coverTexture->getWidth()) / 2, t.pos});
|
st.coverSprite->setPos({(GAMECANVAS_WIDTH - st.coverTexture->getWidth()) / 2, t.pos});
|
||||||
st.coverSprite->setSpriteClip(0, 8, -1, -1);
|
st.coverSprite->setSpriteClip(0, 8, -1, -1);
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
st.clipDesp = 8;
|
||||||
|
st.clipHeight = height;
|
||||||
|
|
||||||
spriteTexts.push_back(st);
|
spriteTexts.push_back(st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inicializa las escenas
|
||||||
|
void Ending::iniScenes()
|
||||||
|
{
|
||||||
|
// Crea el contenedor
|
||||||
|
scene_t sc;
|
||||||
|
|
||||||
|
// Inicializa el vector
|
||||||
|
scenes.clear();
|
||||||
|
|
||||||
|
// Crea la escena #0
|
||||||
|
sc.counterEnd = 600;
|
||||||
|
sc.pictureIndex = 0;
|
||||||
|
sc.textIndex.clear();
|
||||||
|
sc.textIndex.push_back({0, 50});
|
||||||
|
sc.textIndex.push_back({1, 100});
|
||||||
|
sc.textIndex.push_back({2, 150});
|
||||||
|
sc.textIndex.push_back({3, 200});
|
||||||
|
scenes.push_back(sc);
|
||||||
|
|
||||||
|
// Crea la escena #1
|
||||||
|
sc.counterEnd = 600;
|
||||||
|
sc.pictureIndex = 1;
|
||||||
|
sc.textIndex.clear();
|
||||||
|
sc.textIndex.push_back({4, 50});
|
||||||
|
sc.textIndex.push_back({5, 100});
|
||||||
|
sc.textIndex.push_back({6, 150});
|
||||||
|
sc.textIndex.push_back({7, 200});
|
||||||
|
sc.textIndex.push_back({8, 250});
|
||||||
|
sc.textIndex.push_back({9, 300});
|
||||||
|
scenes.push_back(sc);
|
||||||
|
|
||||||
|
// Crea la escena #2
|
||||||
|
sc.counterEnd = 600;
|
||||||
|
sc.pictureIndex = 2;
|
||||||
|
sc.textIndex.clear();
|
||||||
|
sc.textIndex.push_back({10, 50});
|
||||||
|
sc.textIndex.push_back({11, 100});
|
||||||
|
scenes.push_back(sc);
|
||||||
|
|
||||||
|
// Crea la escena #3
|
||||||
|
sc.counterEnd = 600;
|
||||||
|
sc.pictureIndex = 3;
|
||||||
|
sc.textIndex.clear();
|
||||||
|
sc.textIndex.push_back({12, 50});
|
||||||
|
sc.textIndex.push_back({13, 100});
|
||||||
|
scenes.push_back(sc);
|
||||||
|
|
||||||
|
// Crea la escena #4
|
||||||
|
sc.counterEnd = 600;
|
||||||
|
sc.pictureIndex = 4;
|
||||||
|
sc.textIndex.clear();
|
||||||
|
sc.textIndex.push_back({14, 50});
|
||||||
|
sc.textIndex.push_back({15, 100});
|
||||||
|
sc.textIndex.push_back({16, 150});
|
||||||
|
scenes.push_back(sc);
|
||||||
|
}
|
||||||
|
|
||||||
// Rellena la textura segun la escena
|
// Rellena la textura segun la escena
|
||||||
void Ending::fillTexture()
|
void Ending::fillTexture()
|
||||||
{
|
{
|
||||||
@@ -324,7 +396,7 @@ void Ending::fillTexture()
|
|||||||
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
const int size = text->getCharacterSize();
|
// const int size = text->getCharacterSize();
|
||||||
|
|
||||||
if (scene == 0)
|
if (scene == 0)
|
||||||
{ // Compone la escena #0
|
{ // Compone la escena #0
|
||||||
@@ -502,16 +574,48 @@ void Ending::updateCounter()
|
|||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
{
|
{
|
||||||
/*for (auto st : spriteTexts)
|
if (counter % 20 == 0)
|
||||||
{
|
{
|
||||||
const int height = st.sprite->getHeight() + 8;
|
for (auto ti : scenes.at(scene).textIndex)
|
||||||
const int width = st.sprite->getWidth();
|
{
|
||||||
const int offset = std::min(counter / 8, height / 2);
|
// spriteTexts.at(ti.index).sprite->render();
|
||||||
SDL_Rect srcRect = {0, 0, width, height - (offset * 2)};
|
// spriteTexts.at(ti.index).coverSprite->render();
|
||||||
SDL_Rect dstRect = {0, (offset * 2) - 8, width, height - (offset * 2)};
|
if (counter > ti.trigger)
|
||||||
st.texture->setAsRenderTarget(renderer);
|
{
|
||||||
SDL_RenderCopy(renderer, st.coverTexture->getSDLTexture(), &srcRect, &dstRect);
|
if (spriteTexts.at(ti.index).clipDesp > 0)
|
||||||
}*/
|
{
|
||||||
|
spriteTexts.at(ti.index).clipDesp -= 2;
|
||||||
|
}
|
||||||
|
else if (spriteTexts.at(ti.index).clipHeight > 0)
|
||||||
|
{
|
||||||
|
spriteTexts.at(ti.index).clipHeight -= 2;
|
||||||
|
spriteTexts.at(ti.index).coverSprite->setPosY(spriteTexts.at(ti.index).coverSprite->getPosY() + 2);
|
||||||
|
}
|
||||||
|
spriteTexts.at(ti.index).coverSprite->setSpriteClip(0, spriteTexts.at(ti.index).clipDesp, spriteTexts.at(ti.index).coverSprite->getWidth(), spriteTexts.at(ti.index).clipHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*for (auto &st : spriteTexts)
|
||||||
|
{
|
||||||
|
// const int height = st.sprite->getHeight() + 8;
|
||||||
|
// const int width = st.sprite->getWidth();
|
||||||
|
// const int offset = std::min(counter / 8, height / 2);
|
||||||
|
// SDL_Rect srcRect = {0, 0, width, height - (offset * 2)};
|
||||||
|
// SDL_Rect dstRect = {0, (offset * 2) - 8, width, height - (offset * 2)};
|
||||||
|
// st.texture->setAsRenderTarget(renderer);
|
||||||
|
// SDL_RenderCopy(renderer, st.coverTexture->getSDLTexture(), &srcRect, &dstRect);
|
||||||
|
if (st.clipDesp > 0)
|
||||||
|
{
|
||||||
|
st.clipDesp -= 2;
|
||||||
|
}
|
||||||
|
else if (st.clipHeight > 0)
|
||||||
|
{
|
||||||
|
st.clipHeight -= 2;
|
||||||
|
st.coverSprite->setPosY(st.coverSprite->getPosY() + 2);
|
||||||
|
}
|
||||||
|
st.coverSprite->setSpriteClip(0, st.clipDesp, st.coverSprite->getWidth(), st.clipHeight);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -525,10 +629,10 @@ void Ending::updateCounter()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si ha terminado la sección
|
// Comprueba si ha terminado la sección
|
||||||
if (counter > 600)
|
if (counter > scenes.at(scene).counterEnd)
|
||||||
{
|
{
|
||||||
scene++;
|
scene++;
|
||||||
fillTexture();
|
// fillTexture();
|
||||||
counter = 0;
|
counter = 0;
|
||||||
if (scene == 5)
|
if (scene == 5)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,18 +20,33 @@ class Ending
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Estructuras
|
// Estructuras
|
||||||
struct endingTexture_t
|
struct endingTexture_t // Estructura con dos texturas y sprites, uno para mostrar y el otro hace de cortinilla
|
||||||
{
|
{
|
||||||
Texture *texture;
|
Texture *texture; // Textura a mostrar
|
||||||
Sprite *sprite;
|
Sprite *sprite; // Sprite para mostrar la textura
|
||||||
Texture *coverTexture;
|
Texture *coverTexture; // Textura que cubre a la otra textura
|
||||||
Sprite *coverSprite;
|
Sprite *coverSprite; // Sprite para mostrar la textura que cubre a la otra textura
|
||||||
|
int clipDesp; // Desplazamiento del spriteClip de la textura de cobertura
|
||||||
|
int clipHeight; // Altura del spriteClip de la textura de cobertura
|
||||||
};
|
};
|
||||||
|
|
||||||
struct textAndPos_t
|
struct textAndPos_t // Estructura con un texto y su posición en el eje Y
|
||||||
{
|
{
|
||||||
std::string caption;
|
std::string caption; // Texto
|
||||||
int pos;
|
int pos; // Posición
|
||||||
|
};
|
||||||
|
|
||||||
|
struct asdhk
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
int trigger;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct scene_t // Estructura para crear cada una de las escenas del final
|
||||||
|
{
|
||||||
|
std::vector<asdhk> textIndex; // Indices del vector de textos a mostrar y su disparador
|
||||||
|
int pictureIndex; // Indice del vector de imagenes a mostrar
|
||||||
|
int counterEnd; // Valor del contador en el que finaliza la escena
|
||||||
};
|
};
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
@@ -48,16 +63,17 @@ private:
|
|||||||
Sprite *sprite; // Sprite para dibujar las imagenes
|
Sprite *sprite; // Sprite para dibujar las imagenes
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int counter; // Contador
|
int counter; // Contador
|
||||||
bool counterEnabled; // Indica si esta activo el contador
|
bool counterEnabled; // Indica si esta activo el contador
|
||||||
int subCounter; // Contador secundario
|
int subCounter; // Contador secundario
|
||||||
section_t section; // Estado del bucle principal para saber si continua o se sale
|
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 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<textAndPos_t> texts; // Vector con los textos
|
std::vector<textAndPos_t> texts; // Vector con los textos
|
||||||
std::vector<endingTexture_t> spriteTexts;
|
std::vector<endingTexture_t> spriteTexts; // Vector con los sprites de texto con su cortinilla
|
||||||
int scene; // Escena actual
|
int scene; // Escena actual
|
||||||
std::vector<int> sceneLenght; // Duracion de cada escena
|
std::vector<int> sceneLenght; // Duracion de cada escena
|
||||||
|
std::vector<scene_t> scenes; // Vector con los textos e imagenes de cada escena
|
||||||
bool pause;
|
bool pause;
|
||||||
|
|
||||||
// Actualiza el objeto
|
// Actualiza el objeto
|
||||||
@@ -72,6 +88,9 @@ private:
|
|||||||
// Inicializa los textos
|
// Inicializa los textos
|
||||||
void iniTexts();
|
void iniTexts();
|
||||||
|
|
||||||
|
// Inicializa las escenas
|
||||||
|
void iniScenes();
|
||||||
|
|
||||||
// Rellena la textura segun la escena
|
// Rellena la textura segun la escena
|
||||||
void fillTexture();
|
void fillTexture();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user