forked from jaildesigner-jailgames/jaildoctors_dilemma
Añadida la clase credits
This commit is contained in:
126
source/credits.cpp
Normal file
126
source/credits.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
#include "credits.h"
|
||||
|
||||
// Constructor
|
||||
Credits::Credits(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
||||
{
|
||||
// Copia la dirección de los objetos
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->asset = asset;
|
||||
|
||||
// Reserva memoria para los punteros
|
||||
eventHandler = new SDL_Event();
|
||||
text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
|
||||
|
||||
// Inicializa variables
|
||||
counter = 0;
|
||||
section.name = SECTION_PROG_CREDITS;
|
||||
section.subsection = 0;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
|
||||
// Cambia el color del borde
|
||||
screen->setBorderColor(stringToColor("black"));
|
||||
|
||||
// Inicializa los textos
|
||||
texts.push_back("ESTE ES UN TEXTO DE PRUEBA");
|
||||
texts.push_back("PARA VER COMO FUNCIONA LA CLASE");
|
||||
texts.push_back("Y TENGO QUE PONER ALGUN TEXTO PARA PROBAR");
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Credits::~Credits()
|
||||
{
|
||||
delete eventHandler;
|
||||
delete text;
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Credits::checkEventHandler()
|
||||
{
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(eventHandler) != 0)
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (eventHandler->type == SDL_QUIT)
|
||||
{
|
||||
section.name = SECTION_PROG_QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
// Comprueba si se ha pulsado alguna tecla
|
||||
else if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0))
|
||||
{
|
||||
switch (eventHandler->key.keysym.scancode)
|
||||
{
|
||||
case SDL_SCANCODE_ESCAPE:
|
||||
section.name = SECTION_PROG_QUIT;
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_RETURN:
|
||||
section.name = SECTION_PROG_TITLE;
|
||||
section.subsection = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
void Credits::update()
|
||||
{
|
||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
checkEventHandler();
|
||||
|
||||
// Incrementa el contador
|
||||
counter++;
|
||||
|
||||
// Comprueba si ha terminado la sección
|
||||
if (counter>1000)
|
||||
{
|
||||
section.name = SECTION_PROG_LOGO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja en pantalla
|
||||
void Credits::render()
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean();
|
||||
|
||||
// Dibuja el contenido de la sección
|
||||
//const color_t color = stringToColor("black");
|
||||
//SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
|
||||
//SDL_RenderFillRect(renderer)
|
||||
text->write(8,8,texts[0]);
|
||||
text->write(8,16,texts[1]);
|
||||
text->write(8,24,texts[2]);
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->blit();
|
||||
}
|
||||
|
||||
// Bucle para el logo del juego
|
||||
section_t Credits::run()
|
||||
{
|
||||
while (section.name == SECTION_PROG_CREDITS)
|
||||
{
|
||||
update();
|
||||
render();
|
||||
}
|
||||
|
||||
return section;
|
||||
}
|
||||
Reference in New Issue
Block a user