diff --git a/source/common/animatedsprite.h b/source/common/animatedsprite.h index 3851e51..39f6f90 100644 --- a/source/common/animatedsprite.h +++ b/source/common/animatedsprite.h @@ -74,8 +74,8 @@ public: bool animationIsCompleted(); // Devuelve el rectangulo de una animación y frame concreto - SDL_Rect getAnimationClip(std::string name, Uint8 index); - SDL_Rect getAnimationClip(int indexA, Uint8 indexF); + SDL_Rect getAnimationClip(std::string name = "default", Uint8 index = 0); + SDL_Rect getAnimationClip(int indexA = 0, Uint8 indexF = 0); // Obtiene el indice de la animación a partir del nombre int getIndex(std::string name); diff --git a/source/ending2.cpp b/source/ending2.cpp index 8d4d708..4be8235 100644 --- a/source/ending2.cpp +++ b/source/ending2.cpp @@ -83,10 +83,25 @@ void Ending2::render() screen->clean(stringToColor(options->palette, "black")); // Dibuja los sprites - void renderSprites(); + renderSprites(); - const std::string txt = std::to_string(preCounter) + " - " + std::to_string(counter); - text->write(0, 0, txt); + 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, 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 screen->blit(); @@ -158,7 +173,7 @@ void Ending2::checkEventHandler() // Bucle principal section_t Ending2::run() { - JA_PlayMusic(music); + // JA_PlayMusic(music); while (section.name == SECTION_PROG_ENDING2) { @@ -166,7 +181,7 @@ section_t Ending2::run() render(); } - JA_StopMusic(); + // JA_StopMusic(); return section; } @@ -175,7 +190,7 @@ section_t Ending2::run() void Ending2::updateCounters() { // Incrementa el contador - if (preCounter < 200) + if (preCounter < 20) { preCounter++; } @@ -242,16 +257,25 @@ void Ending2::iniSpriteList() // Carga todos los sprites desde una lista void Ending2::loadSprites() { + maxSpriteWidth = 0; + maxSpriteHeight = 0; + for (auto sl : spriteList) { 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) { - const int x = (i * 20) % 220; - const int y = (i / 11) * 20; - sprites.at(i)->setPos({x, y}); + 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}); } } @@ -267,8 +291,11 @@ void Ending2::updateSprites() // Dibuja los sprites void Ending2::renderSprites() { + const color_t color = stringToColor(options->palette, "red"); for (auto sprite : sprites) { + sprite->getTexture()->setColor(color.r, color.g, color.b); sprite->render(); + sprite->getTexture()->setColor(255, 255, 255); } } \ No newline at end of file diff --git a/source/ending2.h b/source/ending2.h index 7cd3a4e..7c6f4bb 100644 --- a/source/ending2.h +++ b/source/ending2.h @@ -37,6 +37,8 @@ private: Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa JA_Music music; // Musica que suena durante el final std::vector 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 void update();