Trabajando en el ending2

This commit is contained in:
2022-11-04 23:22:10 +01:00
parent 73ec66d228
commit 0b55d8558f
3 changed files with 40 additions and 11 deletions

View File

@@ -74,8 +74,8 @@ public:
bool animationIsCompleted(); bool animationIsCompleted();
// Devuelve el rectangulo de una animación y frame concreto // Devuelve el rectangulo de una animación y frame concreto
SDL_Rect getAnimationClip(std::string name, Uint8 index); SDL_Rect getAnimationClip(std::string name = "default", Uint8 index = 0);
SDL_Rect getAnimationClip(int indexA, Uint8 indexF); SDL_Rect getAnimationClip(int indexA = 0, Uint8 indexF = 0);
// Obtiene el indice de la animación a partir del nombre // Obtiene el indice de la animación a partir del nombre
int getIndex(std::string name); int getIndex(std::string name);

View File

@@ -83,10 +83,25 @@ void Ending2::render()
screen->clean(stringToColor(options->palette, "black")); screen->clean(stringToColor(options->palette, "black"));
// Dibuja los sprites // Dibuja los sprites
void renderSprites(); renderSprites();
const std::string txt = std::to_string(preCounter) + " - " + std::to_string(counter); const std::string txt = std::to_string(preCounter) + " - " + std::to_string(counter) + " - W:" + std::to_string(maxSpriteWidth) + " - H:" + std::to_string(maxSpriteHeight);
text->write(0, 0, txt); text->write(0, 192 - 8, txt);
// Dibuja la cuadricula
{
SDL_SetRenderDrawColor(renderer, 128, 128, 128, 255);
const int sw = maxSpriteWidth + 6;
const int sh = maxSpriteHeight + 6;
for (int i = 0; i < (int)sprites.size(); ++i)
{
const int x = (i * sw) % (256 - sw);
const int y = (i / (256 / sw)) * sh;
const int w = sprites.at(i)->getAnimationClip(0, 0).w;
const int h = sprites.at(i)->getAnimationClip(0, 0).h;
sprites.at(i)->setRect({x, y, w, h});
}
}
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
screen->blit(); screen->blit();
@@ -158,7 +173,7 @@ void Ending2::checkEventHandler()
// Bucle principal // Bucle principal
section_t Ending2::run() section_t Ending2::run()
{ {
JA_PlayMusic(music); // JA_PlayMusic(music);
while (section.name == SECTION_PROG_ENDING2) while (section.name == SECTION_PROG_ENDING2)
{ {
@@ -166,7 +181,7 @@ section_t Ending2::run()
render(); render();
} }
JA_StopMusic(); // JA_StopMusic();
return section; return section;
} }
@@ -175,7 +190,7 @@ section_t Ending2::run()
void Ending2::updateCounters() void Ending2::updateCounters()
{ {
// Incrementa el contador // Incrementa el contador
if (preCounter < 200) if (preCounter < 20)
{ {
preCounter++; preCounter++;
} }
@@ -242,16 +257,25 @@ void Ending2::iniSpriteList()
// Carga todos los sprites desde una lista // Carga todos los sprites desde una lista
void Ending2::loadSprites() void Ending2::loadSprites()
{ {
maxSpriteWidth = 0;
maxSpriteHeight = 0;
for (auto sl : spriteList) for (auto sl : spriteList)
{ {
sprites.push_back(new AnimatedSprite(renderer, resource->getAnimation(sl + ".ani"))); sprites.push_back(new AnimatedSprite(renderer, resource->getAnimation(sl + ".ani")));
maxSpriteWidth = std::max(sprites.back()->getAnimationClip(0, 0).w, maxSpriteWidth);
maxSpriteHeight = std::max(sprites.back()->getAnimationClip(0, 0).h, maxSpriteHeight);
} }
const int sw = maxSpriteWidth + 6;
const int sh = maxSpriteHeight + 6;
for (int i = 0; i < (int)sprites.size(); ++i) for (int i = 0; i < (int)sprites.size(); ++i)
{ {
const int x = (i * 20) % 220; const int x = (i * sw) % (256 - sw);
const int y = (i / 11) * 20; const int y = (i / (256 / sw)) * sh;
sprites.at(i)->setPos({x, y}); const int w = sprites.at(i)->getAnimationClip(0, 0).w;
const int h = sprites.at(i)->getAnimationClip(0, 0).h;
sprites.at(i)->setRect({x, y, w, h});
} }
} }
@@ -267,8 +291,11 @@ void Ending2::updateSprites()
// Dibuja los sprites // Dibuja los sprites
void Ending2::renderSprites() void Ending2::renderSprites()
{ {
const color_t color = stringToColor(options->palette, "red");
for (auto sprite : sprites) for (auto sprite : sprites)
{ {
sprite->getTexture()->setColor(color.r, color.g, color.b);
sprite->render(); sprite->render();
sprite->getTexture()->setColor(255, 255, 255);
} }
} }

View File

@@ -37,6 +37,8 @@ private:
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
JA_Music music; // Musica que suena durante el final JA_Music music; // Musica que suena durante el final
std::vector<std::string> spriteList; // Lista con todos los sprites a dibujar std::vector<std::string> spriteList; // Lista con todos los sprites a dibujar
int maxSpriteWidth; // El valor de ancho del sprite mas ancho
int maxSpriteHeight; // El valor de alto del sprite mas alto
// Actualiza el objeto // Actualiza el objeto
void update(); void update();