From 072a488de6191ba1f4079a1c93358b81e1cad727 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 28 Sep 2022 09:48:55 +0200 Subject: [PATCH] Ya funciona la INTRO --- source/animatedsprite.cpp | 7 +- source/game.cpp | 12 +-- source/intro.cpp | 213 +++++++++++++++++++++++++++++++++++--- source/intro.h | 24 +++++ source/smartsprite.cpp | 4 +- source/title.cpp | 4 +- source/writer.cpp | 6 +- source/writer.h | 2 +- 8 files changed, 243 insertions(+), 29 deletions(-) diff --git a/source/animatedsprite.cpp b/source/animatedsprite.cpp index b1ea650..5a8988a 100644 --- a/source/animatedsprite.cpp +++ b/source/animatedsprite.cpp @@ -9,7 +9,10 @@ AnimatedSprite::AnimatedSprite(LTexture *texture, SDL_Renderer *renderer, std::s setRenderer(renderer); // Carga las animaciones - load(file); + if (file != "") + { + load(file); + } // Inicializa variables currentAnimation = 0; @@ -332,7 +335,7 @@ void AnimatedSprite::setAnimationFrames(Uint8 index_animation, Uint8 index_frame // OLD - Establece el contador para todas las animaciones void AnimatedSprite::setAnimationCounter(int value) { - for (auto &a:animation) + for (auto &a : animation) { a.counter = value; } diff --git a/source/game.cpp b/source/game.cpp index 0614823..142313a 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -434,7 +434,7 @@ void Game::init() m1000Bitmap->setAccelY(-0.1f); m1000Bitmap->setSpriteClip(0, 20, 26, 9); m1000Bitmap->setEnabled(false); - m1000Bitmap->setEnabledTimer(0); + m1000Bitmap->setEnabledCounter(0); m1000Bitmap->setDestX(0); m1000Bitmap->setDestY(0); @@ -449,7 +449,7 @@ void Game::init() m2500Bitmap->setAccelY(-0.1f); m2500Bitmap->setSpriteClip(26, 20, 28, 9); m2500Bitmap->setEnabled(false); - m2500Bitmap->setEnabledTimer(0); + m2500Bitmap->setEnabledCounter(0); m2500Bitmap->setDestX(0); m2500Bitmap->setDestY(0); @@ -464,7 +464,7 @@ void Game::init() m5000Bitmap->setAccelY(-0.1f); m5000Bitmap->setSpriteClip(54, 20, 28, 9); m5000Bitmap->setEnabled(false); - m5000Bitmap->setEnabledTimer(0); + m5000Bitmap->setEnabledCounter(0); m5000Bitmap->setDestX(0); m5000Bitmap->setDestY(0); @@ -2378,7 +2378,7 @@ void Game::createItemScoreSprite(int x, int y, SmartSprite *sprite) ss->setDestX(x); ss->setDestY(y - 15); ss->setEnabled(true); - ss->setEnabledTimer(100); + ss->setEnabledCounter(100); } // Dibuja el efecto de flash @@ -2428,7 +2428,7 @@ void Game::throwCoffee(int x, int y) ss->setDestX(x + (ss->getVelX() * 50)); ss->setDestY(GAME_HEIGHT + 1); ss->setEnabled(true); - ss->setEnabledTimer(1); + ss->setEnabledCounter(1); ss->setSpriteClip(80, 16, 16, 16); ss->setRotate(true); ss->setRotateSpeed(10); @@ -2457,7 +2457,7 @@ void Game::throwPlayer(int x, int y, Player *player) ss->setDestX(GAME_WIDTH * sentit); ss->setDestY(GAME_HEIGHT + 1); ss->setEnabled(true); - ss->setEnabledTimer(1); + ss->setEnabledCounter(1); ss->setSpriteClip(0, 0, 24, 24); } diff --git a/source/intro.cpp b/source/intro.cpp index 1f2f524..d98a1f9 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -22,6 +22,12 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang) section.subsection = 0; ticks = 0; ticksSpeed = 15; + scene1 = true; + scene2 = false; + scene3 = false; + scene4 = false; + scene5 = false; + scene6 = false; // Inicializa los bitmaps de la intro const int totalBitmaps = 6; @@ -94,7 +100,7 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang) w->setPosY(GAME_HEIGHT - (BLOCK * 6)); w->setKerning(-1); w->setEnabled(false); - w->setEnabledTimer(180); + w->setEnabledCounter(180); texts.push_back(w); } @@ -193,6 +199,193 @@ void Intro::checkEventHandler() } } +// Actualiza la escena 1 +void Intro::updateScene1() +{ + if (!scene1) + { + return; + } + + // Primera imagen - UPV + if (!bitmaps[0]->hasFinished()) + { + bitmaps[0]->setEnabled(true); + } + + // Primer texto de la primera imagen + if (bitmaps[0]->hasFinished() && !texts[0]->hasFinished()) + { + texts[0]->setEnabled(true); + } + + // Segundo texto de la primera imagen + if (texts[0]->hasFinished() && !texts[1]->hasFinished()) + { + texts[0]->setEnabled(false); + texts[1]->setEnabled(true); + } + + // Tercer texto de la primera imagen + if (texts[1]->hasFinished() && !texts[2]->hasFinished()) + { + texts[1]->setEnabled(false); + texts[2]->setEnabled(true); + } + + // Fin de la primera escena + if (texts[2]->hasFinished()) + { + bitmaps[0]->setEnabled(false); + texts[2]->setEnabled(false); + scene1 = false; + scene2 = true; + } +} + +// Actualiza la escena 2 +void Intro::updateScene2() +{ + if (!scene2) + { + return; + } + + // Segunda imagen - Máquina + if (!bitmaps[1]->hasFinished()) + { + bitmaps[1]->setEnabled(true); + } + + // Primer texto de la segunda imagen + if (bitmaps[1]->hasFinished() && !texts[3]->hasFinished()) + { + texts[3]->setEnabled(true); + } + + // Fin de la segunda escena + if (texts[3]->hasFinished()) + { + bitmaps[1]->setEnabled(false); + texts[3]->setEnabled(false); + scene2 = false; + scene3 = true; + } +} + +// Actualiza la escena 3 +void Intro::updateScene3() +{ + if (!scene3) + { + return; + } + + // Tercera imagen junto con primer texto - GRITO + if (!bitmaps[2]->hasFinished() && !texts[4]->hasFinished()) + { + bitmaps[2]->setEnabled(true); + texts[4]->setEnabled(true); + } + + // Fin de la tercera escena + if (bitmaps[2]->hasFinished() && texts[4]->hasFinished()) + { + bitmaps[2]->setEnabled(false); + texts[4]->setEnabled(false); + scene3 = false; + scene4 = true; + } +} + +// Actualiza la escena 4 +void Intro::updateScene4() +{ + if (!scene4) + { + return; + } + + // Cuarta imagen junto con primer texto - Reflexión + if (!bitmaps[3]->hasFinished() && !texts[5]->hasFinished()) + { + bitmaps[3]->setEnabled(true); + texts[5]->setEnabled(true); + } + + // Segundo texto de la cuarta imagen + if (texts[5]->hasFinished() && !texts[6]->hasFinished()) + { + texts[5]->setEnabled(false); + texts[6]->setEnabled(true); + } + + // Fin de la cuarta escena + if (bitmaps[3]->hasFinished() && texts[6]->hasFinished()) + { + bitmaps[3]->setEnabled(false); + texts[6]->setEnabled(false); + scene4 = false; + scene5 = true; + } +} + +// Actualiza la escena 5 +void Intro::updateScene5() +{ + if (!scene5) + { + return; + } + + // Quinta imagen - Patada + if (!bitmaps[4]->hasFinished()) + { + bitmaps[4]->setEnabled(true); + } + + // Primer texto de la quinta imagen + if (bitmaps[4]->hasFinished() && !texts[7]->hasFinished()) + { + texts[7]->setEnabled(true); + } + + // Fin de la quinta escena + if (bitmaps[4]->hasFinished() && texts[7]->hasFinished()) + { + bitmaps[4]->setEnabled(false); + texts[7]->setEnabled(false); + scene5 = false; + scene6 = true; + } +} + +// Actualiza la escena 6 +void Intro::updateScene6() +{ + if (!scene6) + { + return; + } + + // Sexta imagen junto con texto - Globos de café + if (!bitmaps[5]->hasFinished() && !texts[8]->hasFinished()) + { + bitmaps[5]->setEnabled(true); + texts[8]->setEnabled(true); + } + + // Acaba el último texto + if (bitmaps[5]->hasFinished() && texts[8]->hasFinished()) + { + bitmaps[5]->setEnabled(false); + texts[8]->setEnabled(false); + JA_StopMusic(); + section.name = PROG_SECTION_TITLE; + section.subsection = TITLE_SECTION_1; + } +} + // Actualiza las variables del objeto void Intro::update() { @@ -214,18 +407,12 @@ void Intro::update() text->update(); } - // Guión de eventos - // Primera imagen - UPV - if (!bitmaps[0]->hasFinished()) - { - bitmaps[0]->setEnabled(true); - } - - // Primer texto de la primera imagen - if (bitmaps[0]->hasFinished() && !texts[0]->hasFinished()) - { - texts[0]->setEnabled(true); - } + updateScene1(); + updateScene2(); + updateScene3(); + updateScene4(); + updateScene5(); + updateScene6(); /* // Guión de eventos diff --git a/source/intro.h b/source/intro.h index a1a8540..053b393 100644 --- a/source/intro.h +++ b/source/intro.h @@ -33,6 +33,12 @@ private: Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa section_t section; // Estado del bucle principal para saber si continua o se sale JA_Music music; // Musica para la intro + bool scene1; // Indica si la escena está activa + bool scene2; // Indica si la escena está activa + bool scene3; // Indica si la escena está activa + bool scene4; // Indica si la escena está activa + bool scene5; // Indica si la escena está activa + bool scene6; // Indica si la escena está activa // Actualiza las variables del objeto void update(); @@ -46,6 +52,24 @@ private: // Comprueba los eventos void checkEventHandler(); + // Actualiza la escena 1 + void updateScene1(); + + // Actualiza la escena 2 + void updateScene2(); + + // Actualiza la escena 3 + void updateScene3(); + + // Actualiza la escena 4 + void updateScene4(); + + // Actualiza la escena 5 + void updateScene5(); + + // Actualiza la escena 6 + void updateScene6(); + public: // Constructor Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang); diff --git a/source/smartsprite.cpp b/source/smartsprite.cpp index 404547d..356f63a 100644 --- a/source/smartsprite.cpp +++ b/source/smartsprite.cpp @@ -78,7 +78,7 @@ void SmartSprite::setEnabledCounter(int value) // Establece el valor de la variable void SmartSprite::setDestX(int x) { - destX = xPrev; + destX = x; } // Establece el valor de la variable @@ -182,7 +182,7 @@ void SmartSprite::update() { // Si esta en el destino comprueba su contador if (enabledCounter == 0) { // Si ha llegado a cero, deshabilita el objeto y lo marca como finalizado - enabled = false; + //enabled = false; finished = true; } else diff --git a/source/title.cpp b/source/title.cpp index c62e21c..fa709a4 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -162,7 +162,7 @@ void Title::init(bool demo, Uint8 subsection) mCoffeeBitmap->setAccelY(0.1f); mCoffeeBitmap->setSpriteClip(0, 0, 167, 46); mCoffeeBitmap->setEnabled(true); - mCoffeeBitmap->setEnabledTimer(0); + mCoffeeBitmap->setEnabledCounter(0); mCoffeeBitmap->setDestX(45); mCoffeeBitmap->setDestY(11); @@ -178,7 +178,7 @@ void Title::init(bool demo, Uint8 subsection) mCrisisBitmap->setAccelY(-0.1f); mCrisisBitmap->setSpriteClip(0, 46, 137, 46); mCrisisBitmap->setEnabled(true); - mCrisisBitmap->setEnabledTimer(0); + mCrisisBitmap->setEnabledCounter(0); mCrisisBitmap->setDestX(60); mCrisisBitmap->setDestY(57); diff --git a/source/writer.cpp b/source/writer.cpp index 0c61065..d65003d 100644 --- a/source/writer.cpp +++ b/source/writer.cpp @@ -60,7 +60,7 @@ void Writer::update() } else if (mEnabledTimer == 0) { - mEnabled = false; + //mEnabled = false; finished = true; } } @@ -121,9 +121,9 @@ bool Writer::IsEnabled() } // Establece el valor de la variable -void Writer::setEnabledTimer(int value) +void Writer::setEnabledCounter(int time) { - mEnabledTimer = value; + mEnabledTimer = time; } // Obtiene el valor de la variable diff --git a/source/writer.h b/source/writer.h index ac3f062..e08c4a3 100644 --- a/source/writer.h +++ b/source/writer.h @@ -64,7 +64,7 @@ public: bool IsEnabled(); // Establece el valor de la variable - void setEnabledTimer(int value); + void setEnabledCounter(int time); // Obtiene el valor de la variable int getEnabledTimer();