From 50a2038ef97450194e1d8eaac39056c25a77ca29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Sun, 12 Feb 2023 18:58:29 +0100 Subject: [PATCH] Ya funcionan los nuevos inputs de teclado y mando en el logo Ya funcionan los nuevos inputs de teclado y mando en la intro --- source/director.cpp | 5 +++- source/intro.cpp | 67 ++++++++++++++++++++------------------------- source/intro.h | 9 ++++-- 3 files changed, 40 insertions(+), 41 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index affdc2f..a993ea4 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -98,6 +98,9 @@ void Director::initInput() input->bindKey(input_cancel, SDL_SCANCODE_ESCAPE); input->bindKey(input_pause, 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 input->bindGameControllerButton(input_up, SDL_CONTROLLER_BUTTON_DPAD_UP); @@ -613,7 +616,7 @@ void Director::runLogo() void Director::runIntro() { - intro = new Intro(renderer, screen, asset, lang); + intro = new Intro(renderer, screen, asset, input, lang); setSection(intro->run()); delete intro; } diff --git a/source/intro.cpp b/source/intro.cpp index e6b49a1..c19c587 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -1,13 +1,14 @@ #include "intro.h" // 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 this->renderer = renderer; this->screen = screen; this->lang = lang; this->asset = asset; + this->input = input; // Reserva memoria para los objetos eventHandler = new SDL_Event(); @@ -183,48 +184,37 @@ void Intro::checkEventHandler() section.name = PROG_SECTION_QUIT; break; } + } +} - // Cualquier tecla pulsada - if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN)) - { - switch (eventHandler->key.keysym.scancode) - { - case SDL_SCANCODE_F: - screen->switchVideoMode(); - texture->reLoad(); - break; +// Comprueba las entradas +void Intro::checkInput() +{ + if (input->checkInput(input_exit, REPEAT_FALSE)) + { + section.name = PROG_SECTION_QUIT; + } - case SDL_SCANCODE_F1: - screen->setWindowSize(1); - texture->reLoad(); - break; + else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE)) + { + screen->switchVideoMode(); + } - case SDL_SCANCODE_F2: - screen->setWindowSize(2); - texture->reLoad(); - break; + else if (input->checkInput(input_window_dec_size, REPEAT_FALSE)) + { + screen->decWindowSize(); + } - case SDL_SCANCODE_F3: - screen->setWindowSize(3); - texture->reLoad(); - break; + else if (input->checkInput(input_window_inc_size, REPEAT_FALSE)) + { + screen->incWindowSize(); + } - case SDL_SCANCODE_F4: - screen->setWindowSize(4); - texture->reLoad(); - break; - - case SDL_SCANCODE_F5: - screen->showNotification("HOLA MAMA!"); - break; - - default: - JA_StopMusic(); - section.name = PROG_SECTION_TITLE; - section.subsection = TITLE_SECTION_1; - break; - } - } + 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)) + { + JA_StopMusic(); + section.name = PROG_SECTION_TITLE; + section.subsection = TITLE_SECTION_1; } } @@ -388,6 +378,7 @@ void Intro::updateScenes() void Intro::update() { checkEventHandler(); + checkInput(); if (SDL_GetTicks() - ticks > ticksSpeed) { diff --git a/source/intro.h b/source/intro.h index 4d08bd6..eff3443 100644 --- a/source/intro.h +++ b/source/intro.h @@ -2,6 +2,7 @@ #include #include "common/asset.h" +#include "common/input.h" #include "common/jail_audio.h" #include "common/screen.h" #include "common/smartsprite.h" @@ -24,6 +25,7 @@ private: SDL_Event *eventHandler; // Manejador de eventos 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 std::vector bitmaps; // Vector con los sprites inteligentes para los dibujos de la intro std::vector texts; // 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 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 - JA_Music_t* music; // Musica para la intro + JA_Music_t *music; // Musica para la intro int scene; // Indica que escena está activa // Actualiza las variables del objeto @@ -47,12 +49,15 @@ private: // Comprueba los eventos void checkEventHandler(); + // Comprueba las entradas + void checkInput(); + // Actualiza las escenas de la intro void updateScenes(); public: // Constructor - Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang); + Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang); // Destructor ~Intro();