Trabajando en hacer que puedas entrar a la jail

This commit is contained in:
2022-11-05 20:56:09 +01:00
parent 1bcdadb6c0
commit 45fc923be9
10 changed files with 248 additions and 110 deletions

View File

@@ -17,18 +17,27 @@ Ending2::Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Ass
music = JA_LoadMusic(asset->get("ending2.ogg").c_str());
// Inicializa variables
counter = -1;
counterEnabled = false;
preCounter = 0;
postCounter = 0;
postCounterEnabled = false;
section.name = SECTION_PROG_ENDING2;
section.subsection = 0;
ticks = 0;
ticksSpeed = 15;
distSpriteText = 8;
distSpriteSprite = 0;
despSpeed = -1.6f;
despSpeed = -0.2f;
firstCol = GAMECANVAS_FIRST_QUARTER_X + (GAMECANVAS_WIDTH / 16);
secondCol = GAMECANVAS_THIRD_QUARTER_X - (GAMECANVAS_WIDTH / 16);
// Inicializa el vector de colores
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
for (auto cl : colorList)
{
colors.push_back(stringToColor(options->palette, cl));
}
// Cambia el color del borde
screen->setBorderColor(stringToColor(options->palette, "black"));
@@ -76,14 +85,23 @@ void Ending2::update()
// Actualiza los contadores
updateCounters();
// Actualiza los sprites
updateSprites();
if (counterEnabled)
{
// Actualiza los sprites
updateSprites();
// Actualiza los sprites de texto
updateTextSprites();
// Actualiza los sprites de texto
updateTextSprites();
// Actualiza los sprites de texto del final
updateTexts();
// Actualiza los sprites de texto del final
updateTexts();
}
// Actualiza el fade final
updateFinalFade();
// Actualiza el volumen de la musica
updateMusicVolume();
}
}
@@ -105,7 +123,7 @@ void Ending2::render()
// Dibuja los sprites con el texto del final
renderTexts();
const std::string txt = std::to_string(preCounter) + " - " + std::to_string(counter) + " - W:" + std::to_string(maxSpriteWidth) + " - H:" + std::to_string(maxSpriteHeight);
const std::string txt = std::to_string(postCounter);
// text->write(0, 192 - 8, txt);
// Dibuja la cuadricula
@@ -124,6 +142,7 @@ void Ending2::render()
}*/
{
// Dibuja una trama arriba y abajo
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
for (int i = 0; i < 256; i += 2)
{
@@ -219,7 +238,7 @@ void Ending2::checkEventHandler()
// Bucle principal
section_t Ending2::run()
{
// JA_PlayMusic(music);
JA_PlayMusic(music);
while (section.name == SECTION_PROG_ENDING2)
{
@@ -227,7 +246,8 @@ section_t Ending2::run()
render();
}
// JA_StopMusic();
JA_StopMusic();
JA_SetVolume(128);
return section;
}
@@ -236,13 +256,24 @@ section_t Ending2::run()
void Ending2::updateCounters()
{
// Incrementa el contador
if (preCounter < 100)
if (preCounter < 200)
{
preCounter++;
}
else
{
counter++;
counterEnabled = true;
}
if (postCounterEnabled)
{
postCounter++;
}
if (postCounter > 600)
{
section.name = SECTION_PROG_LOGO;
section.subsection = SUBSECTION_LOGO_TO_INTRO;
}
}
@@ -342,13 +373,17 @@ void Ending2::updateTextSprites()
// Actualiza los sprites de texto del final
void Ending2::updateTexts()
{
for (auto sprite : texts)
if (texts.back()->getPosY() > GAMECANVAS_CENTER_Y)
{
if (sprite->getPosY() > GAMECANVAS_CENTER_Y)
for (auto sprite : texts)
{
sprite->update();
}
}
else
{
postCounterEnabled = true;
}
}
// Dibuja los sprites
@@ -363,7 +398,6 @@ void Ending2::renderSprites()
{
sprite->getTexture()->setColor(color.r, color.g, color.b);
sprite->render();
sprite->getTexture()->setColor(255, 255, 255);
}
}
@@ -371,7 +405,6 @@ void Ending2::renderSprites()
const color_t c = stringToColor(options->palette, "white");
sprites.back()->getTexture()->setColor(c.r, c.g, c.b);
sprites.back()->render();
sprites.back()->getTexture()->setColor(255, 255, 255);
}
// Dibuja los sprites con el texto
@@ -386,7 +419,6 @@ void Ending2::renderSpriteTexts()
{
sprite->getTexture()->setColor(color.r, color.g, color.b);
sprite->render();
sprite->getTexture()->setColor(255, 255, 255);
}
}
}
@@ -394,16 +426,13 @@ void Ending2::renderSpriteTexts()
// Dibuja los sprites con el texto del final
void Ending2::renderTexts()
{
const color_t color = stringToColor(options->palette, "white");
for (auto sprite : texts)
{
const bool a = sprite->getRect().y + sprite->getRect().h > 0;
const bool b = sprite->getRect().y < GAMECANVAS_HEIGHT;
if (a && b)
{
sprite->getTexture()->setColor(color.r, color.g, color.b);
sprite->render();
sprite->getTexture()->setColor(255, 255, 255);
}
}
}
@@ -414,7 +443,7 @@ void Ending2::placeSprites()
for (int i = 0; i < (int)sprites.size(); ++i)
{
const int x = i % 2 == 0 ? firstCol : secondCol;
const int y = (i / 1) * (maxSpriteHeight + distSpriteText + text->getCharacterSize() + distSpriteSprite) + GAMECANVAS_HEIGHT;
const int y = (i / 1) * (maxSpriteHeight + distSpriteText + text->getCharacterSize() + distSpriteSprite) + GAMECANVAS_HEIGHT + 40;
const int w = sprites.at(i)->getAnimationClip(0, 0).w;
const int h = sprites.at(i)->getAnimationClip(0, 0).h;
const int dx = -(w / 2);
@@ -474,8 +503,36 @@ void Ending2::createTexts()
// Borra la memoria ocupada por los sprites con las texturas de los textos del final
deleteTexts();
const int start = spriteTexts.back()->getPosY() + text->getCharacterSize() * 6;
// Crea los primeros textos
std::vector<std::string> list;
list.push_back("STARRING");
// Crea los sprites de texto a partir de la lista
for (int i = 0; i < (int)list.size(); ++i)
{
// Calcula constantes
const int w = text->lenght(list.at(i), 1);
const int h = text->getCharacterSize();
const int x = GAMECANVAS_CENTER_X;
const int dx = -(w / 2);
const int y = GAMECANVAS_HEIGHT + (text->getCharacterSize() * (i * 2));
// Crea la textura
Texture *texture = new Texture(renderer);
texture->createBlank(renderer, w, h, SDL_TEXTUREACCESS_TARGET);
texture->setAsRenderTarget(renderer);
texture->setBlendMode(SDL_BLENDMODE_BLEND);
text->write(0, 0, list.at(i));
// Crea el sprite
MovingSprite *sprite = new MovingSprite(x + dx, y, w, h, 0.0f, despSpeed, 0.0f, 0.0f, texture, renderer);
texts.push_back(sprite);
}
// Crea los últimos textos
// El primer texto va a continuación del ultimo spriteText
const int start = spriteTexts.back()->getPosY() + text->getCharacterSize() * 6;
list.clear();
list.push_back("THANK YOU");
list.push_back("FOR PLAYING!");
@@ -531,4 +588,28 @@ void Ending2::deleteTexts()
delete text;
}
texts.clear();
}
// Actualiza el fade final
void Ending2::updateFinalFade()
{
// La variable step va de 0 a 40 en el tramo de postCounter que va de 500 a 540. Al dividirlo por 40, va de 0.0f a 1.0f
const float step = std::min(std::max(postCounter, 500) - 500, 40) / 40.0f;
const int index = (colors.size() - 1) * step;
for (auto t : texts)
{
t->getTexture()->setColor(colors.at(index).r, colors.at(index).g, colors.at(index).b);
}
}
// Actualiza el volumen de la musica
void Ending2::updateMusicVolume()
{
if (postCounter > 0)
{
const float step = (600.0f - postCounter) / 600.0f;
const int volume = 128 * step;
JA_SetVolume(volume);
}
}