Ya funcionan los nuevos inputs de teclado y mando en el logo

Ya funcionan los nuevos inputs de teclado y mando en la intro
This commit is contained in:
2023-02-12 18:58:29 +01:00
parent cbb5d54250
commit 50a2038ef9
3 changed files with 40 additions and 41 deletions

View File

@@ -98,6 +98,9 @@ void Director::initInput()
input->bindKey(input_cancel, SDL_SCANCODE_ESCAPE); input->bindKey(input_cancel, SDL_SCANCODE_ESCAPE);
input->bindKey(input_pause, SDL_SCANCODE_ESCAPE); input->bindKey(input_pause, SDL_SCANCODE_ESCAPE);
input->bindKey(input_exit, SDL_SCANCODE_ESCAPE); input->bindKey(input_exit, SDL_SCANCODE_ESCAPE);
input->bindKey(input_window_dec_size, SDL_SCANCODE_F1);
input->bindKey(input_window_inc_size, SDL_SCANCODE_F2);
input->bindKey(input_window_fullscreen, SDL_SCANCODE_F3);
// Mando - Movimiento del jugador // Mando - Movimiento del jugador
input->bindGameControllerButton(input_up, SDL_CONTROLLER_BUTTON_DPAD_UP); input->bindGameControllerButton(input_up, SDL_CONTROLLER_BUTTON_DPAD_UP);
@@ -613,7 +616,7 @@ void Director::runLogo()
void Director::runIntro() void Director::runIntro()
{ {
intro = new Intro(renderer, screen, asset, lang); intro = new Intro(renderer, screen, asset, input, lang);
setSection(intro->run()); setSection(intro->run());
delete intro; delete intro;
} }

View File

@@ -1,13 +1,14 @@
#include "intro.h" #include "intro.h"
// Constructor // Constructor
Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang) Intro::Intro(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->lang = lang; this->lang = lang;
this->asset = asset; this->asset = asset;
this->input = input;
// Reserva memoria para los objetos // Reserva memoria para los objetos
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
@@ -183,48 +184,37 @@ void Intro::checkEventHandler()
section.name = PROG_SECTION_QUIT; section.name = PROG_SECTION_QUIT;
break; break;
} }
}
}
// Cualquier tecla pulsada // Comprueba las entradas
if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN)) void Intro::checkInput()
{ {
switch (eventHandler->key.keysym.scancode) if (input->checkInput(input_exit, REPEAT_FALSE))
{ {
case SDL_SCANCODE_F: section.name = PROG_SECTION_QUIT;
screen->switchVideoMode(); }
texture->reLoad();
break;
case SDL_SCANCODE_F1: else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
screen->setWindowSize(1); {
texture->reLoad(); screen->switchVideoMode();
break; }
case SDL_SCANCODE_F2: else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
screen->setWindowSize(2); {
texture->reLoad(); screen->decWindowSize();
break; }
case SDL_SCANCODE_F3: else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
screen->setWindowSize(3); {
texture->reLoad(); screen->incWindowSize();
break; }
case SDL_SCANCODE_F4: 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))
screen->setWindowSize(4); {
texture->reLoad(); JA_StopMusic();
break; section.name = PROG_SECTION_TITLE;
section.subsection = TITLE_SECTION_1;
case SDL_SCANCODE_F5:
screen->showNotification("HOLA MAMA!");
break;
default:
JA_StopMusic();
section.name = PROG_SECTION_TITLE;
section.subsection = TITLE_SECTION_1;
break;
}
}
} }
} }
@@ -388,6 +378,7 @@ void Intro::updateScenes()
void Intro::update() void Intro::update()
{ {
checkEventHandler(); checkEventHandler();
checkInput();
if (SDL_GetTicks() - ticks > ticksSpeed) if (SDL_GetTicks() - ticks > ticksSpeed)
{ {

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/smartsprite.h" #include "common/smartsprite.h"
@@ -24,6 +25,7 @@ private:
SDL_Event *eventHandler; // Manejador de eventos SDL_Event *eventHandler; // Manejador de eventos
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 Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
Input *input; // Objeto pata gestionar la entrada
std::vector<SmartSprite *> bitmaps; // Vector con los sprites inteligentes para los dibujos de la intro std::vector<SmartSprite *> bitmaps; // Vector con los sprites inteligentes para los dibujos de la intro
std::vector<Writer *> texts; // Textos de la intro std::vector<Writer *> texts; // Textos de la intro
Text *text; // Textos de la intro Text *text; // Textos de la intro
@@ -32,7 +34,7 @@ private:
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
section_t section; // Estado del bucle principal para saber si continua o se sale section_t section; // Estado del bucle principal para saber si continua o se sale
JA_Music_t* music; // Musica para la intro JA_Music_t *music; // Musica para la intro
int scene; // Indica que escena está activa int scene; // Indica que escena está activa
// Actualiza las variables del objeto // Actualiza las variables del objeto
@@ -47,12 +49,15 @@ private:
// Comprueba los eventos // Comprueba los eventos
void checkEventHandler(); void checkEventHandler();
// Comprueba las entradas
void checkInput();
// Actualiza las escenas de la intro // Actualiza las escenas de la intro
void updateScenes(); void updateScenes();
public: public:
// Constructor // Constructor
Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang); Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang);
// Destructor // Destructor
~Intro(); ~Intro();