Començan a treballar en la secció Credits

This commit is contained in:
2024-11-22 20:48:52 +01:00
parent 8941072357
commit b8d4c8f17c
5 changed files with 148 additions and 3 deletions

94
source/credits.cpp Normal file
View File

@@ -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<BalloonManager>())
{
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();
}