Correcciones en el botón de servicio

This commit is contained in:
2024-09-15 15:27:12 +02:00
parent 41e57064cb
commit 333c905b1a
21 changed files with 224 additions and 105 deletions

View File

@@ -60,7 +60,7 @@ private:
Texture *textTexture; // Textura para la fuente de las notificaciones
Texture *iconTexture; // Textura para los iconos de las notificaciones
Text *text; // Objeto para dibujar texto
options_t *options; // Variable con todas las opciones del programa
options_t *options; // Opciones del programa
// Variables
color_t bgColor; // Color de fondo de las notificaciones

View File

@@ -7,6 +7,7 @@
#include "jshader.h"
#endif
#include "dbgtxt.h"
#include "../service.h"
// Constructor
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *input, options_t *options)
@@ -142,7 +143,7 @@ void Screen::setVideoMode(int videoMode)
{
#ifdef ARCADE
videoMode = SCREEN_VIDEO_MODE_WINDOW;
//videoMode = SCREEN_VIDEO_MODE_FULLSCREEN;
// videoMode = SCREEN_VIDEO_MODE_FULLSCREEN;
#endif
// Si está activo el modo ventana quita el borde
@@ -350,6 +351,12 @@ void Screen::checkInput()
{
showInfo = !showInfo;
}
// Comprueba el botón de SERVICE
if (checkServiceButton(input) == SERVICE_SHADERS)
{
switchShaders();
}
}
// Agita la pantalla

View File

@@ -24,7 +24,7 @@ private:
Input *input; // Objeto para leer las entradas de teclado o mando
Notify *notify; // Pinta notificaciones en pantalla
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
options_t *options; // Variable con todas las opciones del programa
options_t *options; // Opciones del programa
// Variables
int windowWidth; // Ancho de la pantalla o ventana

View File

@@ -21,7 +21,7 @@ private:
Text *text; // Objeto para escribir texto
// Variables
options_t *options; // Variable con todas las variables de las opciones del programa
options_t *options; // Opciones 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

View File

@@ -854,7 +854,7 @@ void Director::deleteMusics()
// Ejecuta la sección con el logo
void Director::runLogo()
{
logo = new Logo(screen, asset, input, param, section);
logo = new Logo(screen, asset, input, options, param, section);
logo->run();
delete logo;
}
@@ -862,7 +862,7 @@ void Director::runLogo()
// Ejecuta la sección con la secuencia de introducción
void Director::runIntro()
{
intro = new Intro(screen, asset, input, lang, param, section, getMusic(musics, "intro.ogg"));
intro = new Intro(screen, asset, input, lang, options, param, section, getMusic(musics, "intro.ogg"));
intro->run();
delete intro;
}
@@ -870,7 +870,7 @@ void Director::runIntro()
// Ejecuta la sección con el titulo del juego
void Director::runTitle()
{
title = new Title(screen, asset, input, options, lang, param, section, getMusic(musics, "title.ogg"));
title = new Title(screen, asset, input, lang, options, param, section, getMusic(musics, "title.ogg"));
title->run();
delete title;
}
@@ -879,7 +879,8 @@ void Director::runTitle()
void Director::runGame()
{
const int playerID = section->options;
game = new Game(playerID, 0, screen, asset, lang, input, false, param, options, section, getMusic(musics, "playing.ogg"));
const int currentStage = 0;
game = new Game(playerID, currentStage, GAME_MODE_DEMO_OFF, screen, asset, input, lang, options, param, section, getMusic(musics, "playing.ogg"));
game->run();
delete game;
}
@@ -887,7 +888,7 @@ void Director::runGame()
// Ejecuta la sección donde se muestran las instrucciones
void Director::runInstructions()
{
instructions = new Instructions(screen, asset, input, lang, param, section, getMusic(musics, "title.ogg"));
instructions = new Instructions(screen, asset, input, lang, options, param, section, getMusic(musics, "title.ogg"));
instructions->run();
delete instructions;
}
@@ -895,7 +896,7 @@ void Director::runInstructions()
// Ejecuta la sección donde se muestra la tabla de puntuaciones
void Director::runHiScoreTable()
{
hiScoreTable = new HiScoreTable(screen, asset, input, lang, param, options, section, getMusic(musics, "title.ogg"));
hiScoreTable = new HiScoreTable(screen, asset, input, lang, options, param, section, getMusic(musics, "title.ogg"));
hiScoreTable->run();
delete hiScoreTable;
}
@@ -904,7 +905,8 @@ void Director::runHiScoreTable()
void Director::runDemoGame()
{
const int playerID = (rand() % 2) + 1;
demoGame = new Game(playerID, 0, screen, asset, lang, input, true, param, options, section, nullptr);
const int currentStage = 0;
demoGame = new Game(playerID, currentStage, GAME_MODE_DEMO_ON, screen, asset, input, lang, options, param, section, nullptr);
demoGame->run();
delete demoGame;
}

View File

@@ -41,7 +41,7 @@ private:
section_t *section; // Sección y subsección actual del programa;
// Variables
options_t *options; // Variable con todas las opciones del programa
options_t *options; // Opciones del programa
param_t *param; // Variable con todos los parametros del programa
std::string executablePath; // Path del ejecutable
std::string systemFolder; // Carpeta del sistema donde guardar datos

View File

@@ -4,7 +4,7 @@
#define GAME_OVER_COUNTER 350
// Constructor
Game::Game(int playerID, int currentStage, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, param_t *param, options_t *options, section_t *section, JA_Music_t *music)
Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, param_t *param, section_t *section, JA_Music_t *music)
{
// Copia los punteros
this->screen = screen;
@@ -2047,21 +2047,8 @@ void Game::checkInput()
}
// Comprueba el botón de SERVICE
switch (checkServiceButton(input, 0))
switch (checkServiceButton(input))
{
case SERVICE_EXIT:
{
section->name = SECTION_PROG_QUIT;
section->options = SECTION_OPTIONS_QUIT_SHUTDOWN;
break;
}
case SERVICE_SHADERS:
{
screen->switchShaders();
break;
}
case SERVICE_RESET:
{
section->name = SECTION_PROG_LOGO;

View File

@@ -24,6 +24,9 @@
#include "enemy_formations.h"
#include <iostream>
#define GAME_MODE_DEMO_OFF false
#define GAME_MODE_DEMO_ON true
// Cantidad de elementos a escribir en los ficheros de datos
#define TOTAL_SCORE_DATA 3
#define TOTAL_DEMO_DATA 2000
@@ -192,7 +195,7 @@ private:
int difficulty; // Dificultad del juego
float difficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad
color_t difficultyColor; // Color asociado a la dificultad
options_t *options; // Variable con todas las opciones del programa
options_t *options; // Opciones del programa
param_t *param; // Puntero con todos los parametros del programa
int lastStageReached; // Contiene el número de la última pantalla que se ha alcanzado
demo_t demo; // Variable con todas las variables relacionadas con el modo demo
@@ -445,7 +448,7 @@ private:
public:
// Constructor
Game(int playerID, int currentStage, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, param_t *param, options_t *options, section_t *section, JA_Music_t *music);
Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, param_t *param, section_t *section, JA_Music_t *music);
// Destructor
~Game();

View File

@@ -3,7 +3,7 @@
#include <iostream>
// Constructor
HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section, JA_Music_t *music)
HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, param_t *param, section_t *section, JA_Music_t *music)
{
// Copia punteros
this->screen = screen;
@@ -209,20 +209,32 @@ void HiScoreTable::checkInput()
}
// Comprueba el botón de SERVICE
switch (checkServiceButton(input, 0))
switch (checkServiceButton(input))
{
case SERVICE_EXIT:
section->name = SECTION_PROG_QUIT;
section->options = SECTION_OPTIONS_QUIT_SHUTDOWN;
case SERVICE_RESET:
{
section->name = SECTION_PROG_LOGO;
screen->showNotification("Reset");
break;
}
case SERVICE_SHADERS:
screen->switchShaders();
case SERVICE_MUTE:
{
const bool value = !options->audio.music.enabled;
options->audio.music.enabled = value;
options->audio.sound.enabled = value;
JA_EnableMusic(value);
JA_EnableSound(value);
const std::string text = value ? "on" : "off";
screen->showNotification("Audio " + text);
break;
}
default:
{
break;
}
}
// Comprueba el input para el resto de objetos
screen->checkInput();

View File

@@ -39,7 +39,7 @@ private:
Fade *fade; // Objeto para renderizar fades
Text *text; // Objeto para escribir texto
JA_Music_t *music; // Musica de fondo
options_t *options; // Opciones y parametros del programa
options_t *options; // Opciones del programa
section_t *section; // Estado del bucle principal para saber si continua o se sale
param_t *param; // Puntero con todos los parametros del programa
@@ -80,7 +80,7 @@ private:
public:
// Constructor
HiScoreTable(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section, JA_Music_t *music);
HiScoreTable(Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, param_t *param, section_t *section, JA_Music_t *music);
// Destructor
~HiScoreTable();

View File

@@ -3,7 +3,7 @@
#include <iostream>
// Constructor
Instructions::Instructions(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section, JA_Music_t *music)
Instructions::Instructions(Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, param_t *param, section_t *section, JA_Music_t *music)
{
// Copia los punteros
this->screen = screen;
@@ -13,6 +13,7 @@ Instructions::Instructions(Screen *screen, Asset *asset, Input *input, Lang *lan
this->param = param;
this->section = section;
this->music = music;
this->options = options;
renderer = screen->getRenderer();
// Crea objetos
@@ -338,20 +339,32 @@ void Instructions::checkInput()
}
// Comprueba el botón de SERVICE
switch (checkServiceButton(input, 0))
switch (checkServiceButton(input))
{
case SERVICE_EXIT:
section->name = SECTION_PROG_QUIT;
section->options = SECTION_OPTIONS_QUIT_SHUTDOWN;
case SERVICE_RESET:
{
section->name = SECTION_PROG_LOGO;
screen->showNotification("Reset");
break;
}
case SERVICE_SHADERS:
screen->switchShaders();
case SERVICE_MUTE:
{
const bool value = !options->audio.music.enabled;
options->audio.music.enabled = value;
options->audio.sound.enabled = value;
JA_EnableMusic(value);
JA_EnableSound(value);
const std::string text = value ? "on" : "off";
screen->showNotification("Audio " + text);
break;
}
default:
{
break;
}
}
// Comprueba el input para el resto de objetos
screen->checkInput();

View File

@@ -47,6 +47,7 @@ private:
JA_Music_t *music; // Musica de fondo
section_t *section; // Estado del bucle principal para saber si continua o se sale
param_t *param; // Puntero con todos los parametros del programa
options_t *options; // Opciones del programa
// Variables
int counter; // Contador
@@ -86,7 +87,7 @@ private:
public:
// Constructor
Instructions(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section, JA_Music_t *music);
Instructions(Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, param_t *param, section_t *section, JA_Music_t *music);
// Destructor
~Instructions();

View File

@@ -2,7 +2,7 @@
#include "service.h"
// Constructor
Intro::Intro(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section, JA_Music_t *music)
Intro::Intro(Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, param_t *param, section_t *section, JA_Music_t *music)
{
// Copia los punteros
this->screen = screen;
@@ -208,20 +208,32 @@ void Intro::checkInput()
}
// Comprueba el botón de SERVICE
switch (checkServiceButton(input, 0))
switch (checkServiceButton(input))
{
case SERVICE_EXIT:
section->name = SECTION_PROG_QUIT;
section->options = SECTION_OPTIONS_QUIT_SHUTDOWN;
case SERVICE_RESET:
{
section->name = SECTION_PROG_LOGO;
screen->showNotification("Reset");
break;
}
case SERVICE_SHADERS:
screen->switchShaders();
case SERVICE_MUTE:
{
const bool value = !options->audio.music.enabled;
options->audio.music.enabled = value;
options->audio.sound.enabled = value;
JA_EnableMusic(value);
JA_EnableSound(value);
const std::string text = value ? "on" : "off";
screen->showNotification("Audio " + text);
break;
}
default:
{
break;
}
}
// Comprueba el input para el resto de objetos
screen->checkInput();

View File

@@ -32,6 +32,7 @@ private:
std::vector<Writer *> texts; // Textos de la intro
Text *text; // Textos de la intro
section_t *section; // Estado del bucle principal para saber si continua o se sale
options_t *options; // Opciones del programa
param_t *param; // Puntero con todos los parametros del programa
// Variables
@@ -60,7 +61,7 @@ private:
public:
// Constructor
Intro(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section, JA_Music_t *music);
Intro(Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, param_t *param, section_t *section, JA_Music_t *music);
// Destructor
~Intro();

View File

@@ -3,12 +3,13 @@
#include <iostream>
// Constructor
Logo::Logo(Screen *screen, Asset *asset, Input *input, param_t *param, section_t *section)
Logo::Logo(Screen *screen, Asset *asset, Input *input, options_t *options, param_t *param, section_t *section)
{
// Copia la dirección de los objetos
this->screen = screen;
this->asset = asset;
this->input = input;
this->options = options;
this->param = param;
this->section = section;
SDL_Renderer *renderer = screen->getRenderer();
@@ -118,21 +119,40 @@ void Logo::checkInput()
}
// Comprueba el botón de SERVICE
switch (checkServiceButton(input, 0))
switch (checkServiceButton(input))
{
case SERVICE_EXIT:
{
section->name = SECTION_PROG_QUIT;
section->options = SECTION_OPTIONS_QUIT_SHUTDOWN;
return;
break;
}
case SERVICE_SHADERS:
screen->switchShaders();
case SERVICE_RESET:
{
section->name = SECTION_PROG_LOGO;
screen->showNotification("Reset");
break;
}
case SERVICE_MUTE:
{
const bool value = !options->audio.music.enabled;
options->audio.music.enabled = value;
options->audio.sound.enabled = value;
JA_EnableMusic(value);
JA_EnableSound(value);
const std::string text = value ? "on" : "off";
screen->showNotification("Audio " + text);
break;
}
default:
{
break;
}
}
// Comprueba el input para el resto de objetos
screen->checkInput();

View File

@@ -33,6 +33,7 @@ private:
Sprite *sinceSprite; // Sprite para manejar la sinceTexture
section_t *section; // Estado del bucle principal para saber si continua o se sale
param_t *param; // Puntero con todos los parametros del programa
options_t *options; // Opciones del programa
// Variables
std::vector<color_t> color; // Vector con los colores para el fade
@@ -69,7 +70,7 @@ private:
public:
// Constructor
Logo(Screen *screen, Asset *asset, Input *input, param_t *param, section_t *section);
Logo(Screen *screen, Asset *asset, Input *input, options_t *options, param_t *param, section_t *section);
// Destructor
~Logo();

View File

@@ -50,7 +50,7 @@ private:
std::vector<SDL_Texture *> panelTexture; // Texturas para dibujar cada panel;
// Variables
struct options_t *options; // Variable con todas las variables de las opciones del programa
options_t *options; // Opciones del programa
int stage; // Número de fase actual
std::string name[SCOREBOARD_MAX_PANELS]; // Nom de cada jugador
int score[SCOREBOARD_MAX_PANELS]; // Puntuación de los jugadores

View File

@@ -3,6 +3,51 @@
// Comprueba el botón de servicio del controlador "index"
int checkServiceButton(Input *input, int index)
{
if (index == -1)
{
for (int i = 0; i < input->getNumControllers(); ++i)
{
if (input->checkInput(input_service, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
return SERVICE_EXIT;
}
else if (input->checkInput(input_fire_left, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
return SERVICE_CONFIG;
}
else if (input->checkInput(input_fire_center, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
return SERVICE_SHADERS;
}
else if (input->checkInput(input_fire_right, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
return SERVICE_PAUSE;
}
else if (input->checkInput(input_up, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
return SERVICE_SWAP_CONTROLLERS;
}
else if (input->checkInput(input_down, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
return SERVICE_RESET;
}
else if (input->checkInput(input_left, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
return SERVICE_MUTE;
}
}
}
}
else
{
if (input->checkInput(input_service, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, index))
{
if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, index))
@@ -40,6 +85,7 @@ int checkServiceButton(Input *input, int index)
return SERVICE_MUTE;
}
}
}
return SERVICE_NULL;
}

View File

@@ -18,4 +18,4 @@ enum service_e
};
// Comprueba el botón de servicio del controlador "index"
int checkServiceButton(Input *input, int index);
int checkServiceButton(Input *input, int index = -1);

View File

@@ -2,7 +2,7 @@
#include "service.h"
// Constructor
Title::Title(Screen *screen, Asset *asset, Input *input, options_t *options, Lang *lang, param_t *param, section_t *section, JA_Music_t *music)
Title::Title(Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, param_t *param, section_t *section, JA_Music_t *music)
{
// Copia las direcciones de los punteros y objetos
this->screen = screen;
@@ -268,33 +268,47 @@ void Title::checkInput()
//////////////////////////////////////////////////
// Comprueba el botón de SERVICE
switch (checkServiceButton(input, 0))
switch (checkServiceButton(input))
{
case SERVICE_EXIT:
section->name = SECTION_PROG_QUIT;
section->options = SECTION_OPTIONS_QUIT_SHUTDOWN;
break;
case SERVICE_RESET:
{
section->name = SECTION_PROG_LOGO;
screen->showNotification("Reset");
break;
}
case SERVICE_SHADERS:
screen->switchShaders();
break;
case SERVICE_CONFIG:
defineButtons->enable(0);
case SERVICE_MUTE:
{
const bool value = !options->audio.music.enabled;
options->audio.music.enabled = value;
options->audio.sound.enabled = value;
JA_EnableMusic(value);
JA_EnableSound(value);
const std::string text = value ? "on" : "off";
screen->showNotification("Audio " + text);
break;
}
case SERVICE_SWAP_CONTROLLERS:
{
swapControllers();
break;
}
default:
{
break;
}
}
// Comprueba si algun mando quiere ser configurado
for (int i = 0; i < input->getNumControllers(); ++i)
{
if (checkServiceButton(input, i) == SERVICE_CONFIG)
{
defineButtons->enable(i);
}
}
// Comprueba el botón de START de los mandos
for (int i = 0; i < input->getNumControllers(); ++i)

View File

@@ -72,7 +72,7 @@ private:
section_t nextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
int postFade; // Opción a realizar cuando termina el fundido
options_t *options; // Variable con todas las variables de las opciones del programa
options_t *options; // Opciones del programa
param_t *param; // Puntero con todos los parametros del programa
int numControllers; // Número de mandos conectados
@@ -102,7 +102,7 @@ private:
public:
// Constructor
Title(Screen *screen, Asset *asset, Input *input, options_t *options, Lang *lang, param_t *param, section_t *section, JA_Music_t *music);
Title(Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, param_t *param, section_t *section, JA_Music_t *music);
// Destructor
~Title();