diff --git a/source/credits.cpp b/source/credits.cpp new file mode 100644 index 0000000..c9cca36 --- /dev/null +++ b/source/credits.cpp @@ -0,0 +1,94 @@ +#include "credits.h" +#include "section.h" // Para Name, name, Options, options +#include "global_inputs.h" // Para check +#include "input.h" // Para Input +#include "jail_audio.h" // Para JA_StopMusic +#include "screen.h" // Para Screen +#include "balloon_manager.h" // Para BalloonManager + +// Constructor +Credits::Credits() + : balloon_manager_(std::make_unique()) + +{ + section::name = section::Name::CREDITS; + balloon_manager_->createTwoBigBalloons(); +} + +// Destructor +Credits::~Credits() +{ +} + +// Bucle principal +void Credits::run() +{ + while (section::name == section::Name::CREDITS) + { + checkInput(); + update(); + checkEvents(); // Tiene que ir antes del render + render(); + } +} + +// Actualiza las variables +void Credits::update() +{ + constexpr int TICKS_SPEED = 15; + + if (SDL_GetTicks() - ticks_ > TICKS_SPEED) + { + ticks_ = SDL_GetTicks(); + balloon_manager_->update(); + } +} + +// Dibuja Credits::en patalla +void Credits::render() +{ + // Prepara para empezar a dibujar en la textura de juego + Screen::get()->start(); + + // Limpia la pantalla + Screen::get()->clean(); + + balloon_manager_->render(); + + // Vuelca el contenido del renderizador en pantalla + Screen::get()->blit(); +} + +// Comprueba el manejador de eventos +void Credits::checkEvents() +{ + SDL_Event event; + + // Comprueba los eventos que hay en la cola + while (SDL_PollEvent(&event)) + { + // Evento de salida de la aplicación + if (event.type == SDL_QUIT) + { + section::name = section::Name::QUIT; + section::options = section::Options::QUIT_FROM_EVENT; + break; + } + } +} + +// Comprueba las entradas +void Credits::checkInput() +{ + // Comprueba si se ha pulsado cualquier botón (de los usados para jugar) + if (Input::get()->checkAnyButtonPressed()) + { + JA_StopMusic(); + section::name = section::Name::TITLE; + section::options = section::Options::TITLE_1; + return; + } + + // Comprueba los inputs que se pueden introducir en cualquier sección del juego + globalInputs::check(); +} \ No newline at end of file diff --git a/source/credits.h b/source/credits.h new file mode 100644 index 0000000..feb7695 --- /dev/null +++ b/source/credits.h @@ -0,0 +1,36 @@ +#pragma once +#include "SDL2/SDL.h" +#include +#include "balloon_manager.h" + +class Credits +{ +private: + // Objetos + std::unique_ptr balloon_manager_; // Objeto para gestionar los globos + + // Variables + Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa + + // Actualiza las variables + void update(); + + // Dibuja en pantalla + void render(); + + // Comprueba el manejador de eventos + void checkEvents(); + + // Comprueba las entradas + void checkInput(); + +public: + // Constructor + Credits(); + + // Destructor + ~Credits(); + + // Bucle principal + void run(); +}; \ No newline at end of file diff --git a/source/director.cpp b/source/director.cpp index 998cf26..86dbedd 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -20,6 +20,7 @@ #include // Para operator+, char_traits, allocator #include // Para vector #include "asset.h" // Para Asset, AssetType +#include "credits.h" #include "dbgtxt.h" // Para dbg_init #include "game.h" // Para Game, GAME_MODE_DEMO_OFF, GAME_... #include "global_inputs.h" // Para init @@ -59,8 +60,8 @@ Director::Director(int argc, const char *argv[]) section::name = section::Name::GAME; section::options = section::Options::GAME_PLAY_1P; #elif DEBUG - section::name = section::Name::LOGO; -#else + section::name = section::Name::CREDITS; +#else // NORMAL GAME section::name = section::Name::LOGO; section::attract_mode = section::AttractMode::TITLE_TO_DEMO; #endif @@ -630,6 +631,13 @@ void Director::runInstructions() instructions->run(); } +// Ejecuta la sección donde se muestran los creditos del programa +void Director::runCredits() +{ + auto credits = std::make_unique(); + credits->run(); +} + // Ejecuta la sección donde se muestra la tabla de puntuaciones void Director::runHiScoreTable() { @@ -677,6 +685,9 @@ int Director::run() case section::Name::INSTRUCTIONS: runInstructions(); break; + case section::Name::CREDITS: + runCredits(); + break; default: break; } diff --git a/source/director.h b/source/director.h index 62b3f34..40b6231 100644 --- a/source/director.h +++ b/source/director.h @@ -58,6 +58,9 @@ private: // Ejecuta la sección donde se muestran las instrucciones void runInstructions(); + // Ejecuta la sección donde se muestran los creditos del programa + void runCredits(); + // Ejecuta la sección donde se muestra la tabla de puntuaciones void runHiScoreTable(); diff --git a/source/section.h b/source/section.h index a920eaa..0eae34f 100644 --- a/source/section.h +++ b/source/section.h @@ -13,7 +13,8 @@ namespace section HI_SCORE_TABLE = 5, GAME_DEMO = 6, INSTRUCTIONS = 7, - QUIT = 8, + CREDITS = 8, + QUIT = 9, }; // Opciones para la sección