diff --git a/source/director.cpp b/source/director.cpp index 835f119..8bc587b 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -9,7 +9,7 @@ Director::Director(int argc, char *argv[]) section.name = SECTION_PROG_LOGO; section.subsection = SUBSECTION_LOGO_TO_INTRO; - section.name = SECTION_PROG_GAME; + //section.name = SECTION_PROG_GAME; // Crea e inicializa las opciones del programa iniOptions(); diff --git a/source/game.cpp b/source/game.cpp index aeb1b5f..b1671a1 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -19,10 +19,10 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as this->options = options; // **** - currentRoom = "03.room"; - const int x = 29; - const int y = 13; - spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL}; + //currentRoom = "03.room"; + //const int x = 29; + //const int y = 13; + //spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL}; // **** // Crea los objetos @@ -40,7 +40,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as // Inicializa el resto de variables ticks = 0; ticksSpeed = 15; - board.lives = 0; + board.lives = 9; board.items = 0; board.rooms = 1; board.music = true; diff --git a/source/game_over.cpp b/source/game_over.cpp index e8bc995..3605393 100644 --- a/source/game_over.cpp +++ b/source/game_over.cpp @@ -18,13 +18,14 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A music = JA_LoadMusic(asset->get("game_over.ogg").c_str()); // Inicializa variables + preCounter = 0; counter = 0; section.name = SECTION_PROG_GAME_OVER; section.subsection = 0; ticks = 0; ticksSpeed = 15; - endSection = 350; - iniFade = 260; + endSection = 400; + iniFade = 310; fadeLenght = 20; playerSprite->setPosX(GAMECANVAS_CENTER_X + 10); playerSprite->setPosY(GAMECANVAS_CENTER_Y + 10); @@ -37,7 +38,7 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A { colors.push_back(stringToColor(options->palette, cl)); } - color = colors.at(0); + color = colors.back(); } // Destructor @@ -66,25 +67,12 @@ void GameOver::update() // Actualiza el color usado para renderizar los textos e imagenes updateColor(); + // Actualiza los contadores + updateCounters(); + // Actualiza los dos sprites playerSprite->update(); tvSprite->update(); - - // Actualiza el contador - counter++; - - // Hace sonar la música - if (counter == 30) - { - JA_PlayMusic(music, 0); - } - - // Comprueba si ha terminado la sección - if (counter == endSection) - { - section.name = SECTION_PROG_LOGO; - section.subsection = SUBSECTION_LOGO_TO_TITLE; - } } } @@ -190,9 +178,21 @@ section_t GameOver::run() // Actualiza el color usado para renderizar los textos e imagenes void GameOver::updateColor() { - const float step = std::min(std::max(counter, iniFade) - iniFade, fadeLenght) / (float)fadeLenght; - const int index = (colors.size() - 1) * step; - color = colors.at(index); + const int half = endSection / 2; + + if (counter < half) + { + //const float step = std::min(std::max(counter, iniFade) - iniFade, fadeLenght) / (float)fadeLenght; + const float step = std::min(counter, fadeLenght) / (float)fadeLenght; + const int index = (colors.size() - 1) - int((colors.size() - 1) * step); + color = colors.at(index); + } + else + { + const float step = std::min(std::max(counter, iniFade) - iniFade, fadeLenght) / (float)fadeLenght; + const int index = (colors.size() - 1) * step; + color = colors.at(index); + } } // Dibuja los sprites @@ -203,4 +203,31 @@ void GameOver::renderSprites() tvSprite->getTexture()->setColor(color.r, color.g, color.b); tvSprite->render(); +} + +// Actualiza los contadores +void GameOver::updateCounters() +{ + // Actualiza el contador + if (preCounter < 50) + { + preCounter++; + } + else + { + counter++; + } + + // Hace sonar la música + if (counter == 1) + { + JA_PlayMusic(music, 0); + } + + // Comprueba si ha terminado la sección + else if (counter == endSection) + { + section.name = SECTION_PROG_LOGO; + section.subsection = SUBSECTION_LOGO_TO_TITLE; + } } \ No newline at end of file diff --git a/source/game_over.h b/source/game_over.h index 829dd82..83f65fa 100644 --- a/source/game_over.h +++ b/source/game_over.h @@ -30,6 +30,7 @@ private: AnimatedSprite *tvSprite; // Sprite con el televisor // Variables + int preCounter; // Contador previo int counter; // Contador 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 @@ -56,6 +57,9 @@ private: // Dibuja los sprites void renderSprites(); + // Actualiza los contadores + void updateCounters(); + public: // Constructor GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options);