Començan a treballar en la secció Credits
This commit is contained in:
94
source/credits.cpp
Normal file
94
source/credits.cpp
Normal 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();
|
||||
}
|
||||
36
source/credits.h
Normal file
36
source/credits.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include "SDL2/SDL.h"
|
||||
#include <memory>
|
||||
#include "balloon_manager.h"
|
||||
|
||||
class Credits
|
||||
{
|
||||
private:
|
||||
// Objetos
|
||||
std::unique_ptr<BalloonManager> 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();
|
||||
};
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <string> // Para operator+, char_traits, allocator
|
||||
#include <vector> // 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>();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user