El juego ya no se cierra al terminar de definir los botones

This commit is contained in:
2024-07-08 11:59:56 +02:00
parent dfc14da179
commit e85d3c2494
6 changed files with 36 additions and 23 deletions

View File

@@ -12,9 +12,9 @@ venetianSize 16
#SCOREBOARD #SCOREBOARD
scoreboard.x 0 scoreboard.x 0
scoreboard.y 208 scoreboard.y 200
scoreboard.w 320 scoreboard.w 320
scoreboard.h 32 scoreboard.h 40
#TITLE #TITLE
pressStart 160 pressStart 160

View File

@@ -14,15 +14,9 @@
#define WIDTH 320 #define WIDTH 320
#define HEIGHT 240 #define HEIGHT 240
// Marcador
const int SCOREBOARD_WIDTH = WIDTH;
const int SCOREBOARD_HEIGHT = 32;
const int SCOREBOARD_X = 0;
const int SCOREBOARD_Y = HEIGHT - SCOREBOARD_HEIGHT;
// Zona de juego // Zona de juego
const SDL_Rect windowArea = {0, 0, WIDTH, HEIGHT}; const SDL_Rect windowArea = {0, 0, WIDTH, HEIGHT};
const SDL_Rect playArea = {0, 0, WIDTH, HEIGHT - SCOREBOARD_HEIGHT}; const SDL_Rect playArea = {0, 0, WIDTH, 200};
const int PLAY_AREA_TOP = 0; const int PLAY_AREA_TOP = 0;
const int PLAY_AREA_BOTTOM = playArea.h; const int PLAY_AREA_BOTTOM = playArea.h;
const int PLAY_AREA_LEFT = 0; const int PLAY_AREA_LEFT = 0;

View File

@@ -1,7 +1,7 @@
#include "define_buttons.h" #include "define_buttons.h"
// Constructor // Constructor
DefineButtons::DefineButtons(SDL_Renderer *renderer, Input *input, Text *text, param_t *param, options_t *options) DefineButtons::DefineButtons(SDL_Renderer *renderer, Input *input, Text *text, param_t *param, options_t *options, section_t *section)
{ {
// Copia punteros a los objetos // Copia punteros a los objetos
this->renderer = renderer; this->renderer = renderer;
@@ -9,6 +9,7 @@ DefineButtons::DefineButtons(SDL_Renderer *renderer, Input *input, Text *text, p
this->text = text; this->text = text;
this->param = param; this->param = param;
this->options = options; this->options = options;
this->section = section;
// Inicializa variables // Inicializa variables
enabled = false; enabled = false;
@@ -109,6 +110,13 @@ void DefineButtons::checkInput()
// Comprueba los eventos que hay en la cola // Comprueba los eventos que hay en la cola
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
// Evento de salida de la aplicación
if (event.type == SDL_QUIT)
{
section->name = SECTION_PROG_QUIT;
break;
}
if (event.type == SDL_CONTROLLERBUTTONDOWN) if (event.type == SDL_CONTROLLERBUTTONDOWN)
doControllerButtonDown(&event.cbutton); doControllerButtonDown(&event.cbutton);
} }
@@ -143,7 +151,7 @@ void DefineButtons::incIndexButton()
// Guarda los cambios en las opciones // Guarda los cambios en las opciones
saveBindingsToOptions(); saveBindingsToOptions();
//input->allActive(indexController); input->allActive(indexController);
// Reinicia variables // Reinicia variables
indexButton = 0; indexButton = 0;

View File

@@ -3,6 +3,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "common/input.h" #include "common/input.h"
#include "common/text.h" #include "common/text.h"
#include "const.h"
#ifndef DEFINE_BUTTONS_H #ifndef DEFINE_BUTTONS_H
#define DEFINE_BUTTONS_H #define DEFINE_BUTTONS_H
@@ -26,6 +27,7 @@ private:
// Variables // Variables
options_t *options; // Variable con todas las variables de las opciones del programa options_t *options; // Variable con todas las variables de las opciones del programa
param_t *param; // Puntero con todos los parametros del programa param_t *param; // Puntero con todos los parametros del programa
section_t *section; // Indicador para el bucle del titulo
bool enabled; // Indica si el objeto está habilitado bool enabled; // Indica si el objeto está habilitado
int x; // Posición donde dibujar el texto int x; // Posición donde dibujar el texto
int y; // Posición donde dibujar el texto int y; // Posición donde dibujar el texto
@@ -48,7 +50,7 @@ private:
public: public:
// Constructor // Constructor
DefineButtons(SDL_Renderer *renderer, Input *input, Text *text, param_t *param, options_t *options); DefineButtons(SDL_Renderer *renderer, Input *input, Text *text, param_t *param, options_t *options, section_t *section);
// Destructor // Destructor
~DefineButtons(); ~DefineButtons();

View File

@@ -2653,7 +2653,7 @@ void Game::renderSeparator()
{ {
// Dibuja la linea que separa el marcador de la zona de juego // Dibuja la linea que separa el marcador de la zona de juego
SDL_SetRenderDrawColor(renderer, separator.r, separator.g, separator.b, 255); SDL_SetRenderDrawColor(renderer, separator.r, separator.g, separator.b, 255);
SDL_RenderDrawLine(renderer, SCOREBOARD_X, SCOREBOARD_Y, SCOREBOARD_X + SCOREBOARD_WIDTH, SCOREBOARD_Y); SDL_RenderDrawLine(renderer, param->scoreboard.x, param->scoreboard.y, param->scoreboard.x + param->scoreboard.w, param->scoreboard.y);
} }
// Dibuja los elementos de la zona de juego en su textura // Dibuja los elementos de la zona de juego en su textura

View File

@@ -36,7 +36,7 @@ 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 = new GameLogo(renderer, screen, asset, param, GAMECANVAS_CENTER_X, GAMECANVAS_FIRST_QUARTER_Y + 20);
gameLogo->enable(); gameLogo->enable();
defineButtons = new DefineButtons(renderer, input, text2, param, options); defineButtons = new DefineButtons(renderer, input, text2, param, options, section);
// Inicializa los valores // Inicializa los valores
init(); init();
@@ -220,10 +220,22 @@ void Title::checkEvents()
break; break;
} }
// Recarga las texturas
else if (eventHandler->type == SDL_RENDER_DEVICE_RESET || eventHandler->type == SDL_RENDER_TARGETS_RESET) else if (eventHandler->type == SDL_RENDER_DEVICE_RESET || eventHandler->type == SDL_RENDER_TARGETS_RESET)
{ {
reLoadTextures(); reLoadTextures();
} }
// Comprueba en el primer mando el botón de salir del programa
else if (eventHandler->type == SDL_CONTROLLERBUTTONDOWN)
{
if ((SDL_GameControllerButton)eventHandler->cbutton.which == 0)
if ((SDL_GameControllerButton)eventHandler->cbutton.button == input->getControllerBinding(0, input_exit))
{
section->name = SECTION_PROG_QUIT;
break;
}
}
} }
} }
} }
@@ -241,17 +253,14 @@ void Title::checkInput()
fade->activate(); fade->activate();
postFade = index; postFade = index;
} }
}
// Comprueba el teclado para salir // Comprueba el teclado para salir
if (input->checkInput(input_exit, DO_NOT_ALLOW_REPEAT)) if (input->checkInput(input_exit, DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
{ {
section->name = SECTION_PROG_QUIT; section->name = SECTION_PROG_QUIT;
} }
// Comprueba si se ha pulsado la tecla 1 o 2 para definir los controladores // Comprueba si se ha pulsado la tecla 1 o 2 para definir los controladores
if (!defineButtons->isEnabled())
{
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr); const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
if (keyStates[SDL_SCANCODE_1] != 0) if (keyStates[SDL_SCANCODE_1] != 0)