forked from jaildesigner-jailgames/jaildoctors_dilemma
Trabajando en la sección EnterID
This commit is contained in:
135
source/enter_id.cpp
Normal file
135
source/enter_id.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
#include "enter_id.h"
|
||||
#include "const.h"
|
||||
#include "common/jail_audio.h"
|
||||
|
||||
// Constructor
|
||||
EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options)
|
||||
{
|
||||
// Copia la dirección de los objetos
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->asset = asset;
|
||||
this->options = options;
|
||||
|
||||
// Reserva memoria para los punteros
|
||||
eventHandler = new SDL_Event();
|
||||
texture = new Texture(renderer, asset->get("smb2.png"));
|
||||
text = new Text(asset->get("smb2.txt"), texture, renderer);
|
||||
|
||||
// Inicializa variables
|
||||
counter = 0;
|
||||
section.name = SECTION_PROG_ENTER_ID;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
EnterID::~EnterID()
|
||||
{
|
||||
delete eventHandler;
|
||||
delete text;
|
||||
delete texture;
|
||||
}
|
||||
|
||||
// Bucle para el logo del juego
|
||||
section_t EnterID::run()
|
||||
{
|
||||
// Detiene la música
|
||||
JA_StopMusic();
|
||||
|
||||
while (section.name == SECTION_PROG_ENTER_ID)
|
||||
{
|
||||
update();
|
||||
render();
|
||||
}
|
||||
|
||||
return section;
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void EnterID::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 las teclas que se han pulsado
|
||||
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
||||
{
|
||||
switch (eventHandler->key.keysym.scancode)
|
||||
{
|
||||
case SDL_SCANCODE_ESCAPE:
|
||||
section.name = SECTION_PROG_QUIT;
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F1:
|
||||
screen->setWindowSize(1);
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F2:
|
||||
screen->setWindowSize(2);
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F3:
|
||||
screen->setWindowSize(3);
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F4:
|
||||
screen->setWindowSize(4);
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F5:
|
||||
// switchPalette();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
void EnterID::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();
|
||||
|
||||
// Actualiza el contador
|
||||
counter++;
|
||||
|
||||
// Comprueba el contador
|
||||
if (counter > 200)
|
||||
{
|
||||
section.name = SECTION_PROG_INTRO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja en pantalla
|
||||
void EnterID::render()
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean();
|
||||
|
||||
// Escribe texto
|
||||
text->writeCentered(GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y, "SECCION ENTER_ID");
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->blit();
|
||||
}
|
||||
Reference in New Issue
Block a user