empezando a trabajar en la clase DefineButtons

This commit is contained in:
2024-07-06 13:25:15 +02:00
parent 78a689760d
commit c8cd375d81
4 changed files with 309 additions and 35 deletions

View File

@@ -36,6 +36,8 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset,
gameLogo = new GameLogo(renderer, screen, asset, param, GAMECANVAS_CENTER_X, GAMECANVAS_FIRST_QUARTER_Y + 20);
gameLogo->enable();
defineButtons = new DefineButtons(renderer, input, text2, param, options);
// Inicializa los valores
init();
}
@@ -57,6 +59,7 @@ Title::~Title()
delete background;
delete tiledbg;
delete gameLogo;
delete defineButtons;
}
// Inicializa los valores de las variables
@@ -88,6 +91,8 @@ void Title::update()
// Actualiza el objeto 'background'
background->update();
defineButtons->update();
// Comprueba el fade y si se ha acabado
fade->update();
if (fade->hasEnded())
@@ -130,7 +135,11 @@ void Title::update()
{
if (counter < param->titleCounter)
{
counter++;
// El contador solo sube si no estamos definiendo botones
if (!defineButtons->isEnabled())
{
counter++;
}
// Reproduce la música
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
@@ -165,13 +174,13 @@ void Title::render()
tiledbg->render();
// background->render();
// Dinuja el logo con el título del juego
// Dibuja el logo con el título del juego
gameLogo->render();
if (section->subsection == SUBSECTION_TITLE_2)
{
// 'PULSA 1P o 2P PARA JUGAR'
if (counter % 50 > 14)
if (counter % 50 > 14 && !defineButtons->isEnabled())
{
text1->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, param->pressStart, lang->getText(23), 1, noColor, 1, shdwTxtColor);
}
@@ -186,6 +195,8 @@ void Title::render()
text1->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, pos2, TEXT_COPYRIGHT, 1, noColor, 1, shdwTxtColor);
}
defineButtons->render();
// Fade
fade->render();
@@ -196,19 +207,23 @@ void Title::render()
// Comprueba los eventos
void Title::checkEvents()
{
// 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)
// Si defineButtons está habilitado, es él quien gestiona los eventos
if (!defineButtons->isEnabled())
{
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(eventHandler) != 0)
{
section->name = SECTION_PROG_QUIT;
break;
}
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section->name = SECTION_PROG_QUIT;
break;
}
else if (eventHandler->type == SDL_RENDER_DEVICE_RESET || eventHandler->type == SDL_RENDER_TARGETS_RESET)
{
reLoadTextures();
else if (eventHandler->type == SDL_RENDER_DEVICE_RESET || eventHandler->type == SDL_RENDER_TARGETS_RESET)
{
reLoadTextures();
}
}
}
}
@@ -216,12 +231,24 @@ void Title::checkEvents()
// Comprueba las entradas
void Title::checkInput()
{
// Comprueba todos los controladores para salir
for (int i = 0; i < numControllers; ++i)
// Comprueba los controladores solo si no se estan definiendo los botones
if (!defineButtons->isEnabled())
{
if (input->checkInput(input_exit, REPEAT_FALSE, options->game.input[i].deviceType, options->game.input[i].id))
// Comprueba todos los controladores para salir
for (int i = 0; i < numControllers; ++i)
{
section->name = SECTION_PROG_QUIT;
if (input->checkInput(input_exit, REPEAT_FALSE, options->game.input[i].deviceType, options->game.input[i].id))
{
section->name = SECTION_PROG_QUIT;
}
}
// Comprueba si se ha pulsado algún botón para empezar a jugar
const int index = input->checkAnyButtonPressed();
if (index)
{
fade->activate();
postFade = index;
}
}
@@ -231,16 +258,25 @@ void Title::checkInput()
section->name = SECTION_PROG_QUIT;
}
// Comprueba si se ha pulsado algún botón para empezar a jugar
const int index = input->checkAnyButtonPressed();
if (index)
// Comprueba si se ha pulsado la tecla 1 o 2 para definir los controladores
if (!defineButtons->isEnabled())
{
fade->activate();
postFade = index;
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
if (keyStates[SDL_SCANCODE_1] != 0)
{
defineButtons->enable(1);
}
else if (keyStates[SDL_SCANCODE_2] != 0)
{
defineButtons->enable(2);
}
}
// Comprueba el input para el resto de objetos
screen->checkInput();
defineButtons->checkInput();
}
// Bucle para el titulo del juego