Ya funcionan los nuevos inputs de teclado y mando durante las instrucciones

This commit is contained in:
2023-02-12 19:19:39 +01:00
parent 856415c8c4
commit b8bb1b144f
3 changed files with 57 additions and 24 deletions

View File

@@ -4,12 +4,13 @@
const Uint8 SELF = 0; const Uint8 SELF = 0;
// Constructor // Constructor
Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang) Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang)
{ {
// Copia los punteros // Copia los punteros
this->renderer = renderer; this->renderer = renderer;
this->screen = screen; this->screen = screen;
this->asset = asset; this->asset = asset;
this->input = input;
this->lang = lang; this->lang = lang;
// Reserva memoria para los punteros // Reserva memoria para los punteros
@@ -40,7 +41,7 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset,
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
if (backbuffer == nullptr) if (backbuffer == nullptr)
{ {
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl; std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
} }
// Inicializa variables // Inicializa variables
@@ -75,6 +76,9 @@ void Instructions::update()
// Comprueba los eventos // Comprueba los eventos
checkEventHandler(); checkEventHandler();
// Comprueba las entradas
checkInput();
// Actualiza las variables // Actualiza las variables
if (SDL_GetTicks() - ticks > ticksSpeed) if (SDL_GetTicks() - ticks > ticksSpeed)
{ {
@@ -216,21 +220,45 @@ void Instructions::checkEventHandler()
section.name = PROG_SECTION_QUIT; section.name = PROG_SECTION_QUIT;
break; break;
} }
}
}
if ((eventHandler->type == SDL_KEYUP) || (eventHandler->type == SDL_JOYBUTTONUP)) // Comprueba las entradas
void Instructions::checkInput()
{
if (input->checkInput(input_exit, REPEAT_FALSE))
{
section.name = PROG_SECTION_QUIT;
}
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
{
screen->switchVideoMode();
}
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
{
screen->decWindowSize();
}
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
{
screen->incWindowSize();
}
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE))
{
if (mode == m_auto)
{ {
if (mode == m_auto) JA_StopMusic();
section.name = PROG_SECTION_TITLE;
section.subsection = TITLE_SECTION_1;
}
else
{
if (counter > 30)
{ {
JA_StopMusic(); manualQuit = true;
section.name = PROG_SECTION_TITLE;
section.subsection = TITLE_SECTION_1;
}
else
{
if (counter > 30)
{
manualQuit = true;
}
} }
} }
} }

View File

@@ -2,6 +2,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "common/asset.h" #include "common/asset.h"
#include "common/input.h"
#include "common/jail_audio.h" #include "common/jail_audio.h"
#include "common/screen.h" #include "common/screen.h"
#include "common/sprite.h" #include "common/sprite.h"
@@ -23,15 +24,16 @@ class Instructions
{ {
private: private:
// Objetos y punteros // Objetos y punteros
SDL_Renderer *renderer; // El renderizador de la ventana SDL_Renderer *renderer; // El renderizador de la ventana
Screen *screen; // Objeto encargado de dibujar en pantalla Screen *screen; // Objeto encargado de dibujar en pantalla
std::vector<Texture *> itemTextures; // Vector con las texturas de los items std::vector<Texture *> itemTextures; // Vector con las texturas de los items
SDL_Event *eventHandler; // Manejador de eventos SDL_Event *eventHandler; // Manejador de eventos
SDL_Texture *backbuffer; // Textura para usar como backbuffer SDL_Texture *backbuffer; // Textura para usar como backbuffer
Sprite *sprite; // Sprite con la textura de las instrucciones Sprite *sprite; // Sprite con la textura de las instrucciones
Asset *asset; // Objeto que gestiona todos los ficheros de recursos Asset *asset; // Objeto que gestiona todos los ficheros de recursos
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas Input *input; // Objeto pata gestionar la entrada
Text *text; // Objeto para escribir texto Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
Text *text; // Objeto para escribir texto
// Variables // Variables
Uint16 counter; // Contador Uint16 counter; // Contador
@@ -51,9 +53,12 @@ private:
// Comprueba los eventos // Comprueba los eventos
void checkEventHandler(); void checkEventHandler();
// Comprueba las entradas
void checkInput();
public: public:
// Constructor // Constructor
Instructions(SDL_Renderer *renderer, Screen *screen, Asset *mAsset, Lang *lang); Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang);
// Destructor // Destructor
~Instructions(); ~Instructions();

View File

@@ -957,7 +957,7 @@ section_t Title::run()
// Ejecuta la parte donde se muestran las instrucciones // Ejecuta la parte donde se muestran las instrucciones
section_t Title::runInstructions(mode_e mode) section_t Title::runInstructions(mode_e mode)
{ {
instructions = new Instructions(renderer, screen, asset, lang); instructions = new Instructions(renderer, screen, asset, input, lang);
section = instructions->run(mode); section = instructions->run(mode);
delete instructions; delete instructions;