From a435e3ed8cd110fa33d62b1bb3586f795533597a Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 11 Sep 2024 20:42:21 +0200 Subject: [PATCH] corregidos varios bugs --- source/common/screen.cpp | 6 +++--- source/define_buttons.cpp | 7 +++++-- source/define_buttons.h | 2 +- source/director.cpp | 2 +- source/game.cpp | 6 +++--- source/title.cpp | 28 ++++++++++++---------------- source/title.h | 5 ++++- 7 files changed, 29 insertions(+), 27 deletions(-) diff --git a/source/common/screen.cpp b/source/common/screen.cpp index 8ce2e2a..9ebe5f8 100644 --- a/source/common/screen.cpp +++ b/source/common/screen.cpp @@ -339,14 +339,14 @@ void Screen::checkInput() const std::string size = std::to_string(options->video.window.size); showNotification("Window size x" + size); } +#endif - else if (input->checkInput(input_video_shaders, DO_NOT_ALLOW_REPEAT)) + if (input->checkInput(input_video_shaders, DO_NOT_ALLOW_REPEAT)) { switchShaders(); } -#endif - if (input->checkInput(input_showinfo, DO_NOT_ALLOW_REPEAT)) + else if (input->checkInput(input_showinfo, DO_NOT_ALLOW_REPEAT)) { showInfo = !showInfo; } diff --git a/source/define_buttons.cpp b/source/define_buttons.cpp index 542f4a0..9d4da86 100644 --- a/source/define_buttons.cpp +++ b/source/define_buttons.cpp @@ -125,14 +125,17 @@ void DefineButtons::checkInput() } // Habilita el objeto -void DefineButtons::enable(int index) +bool DefineButtons::enable(int index) { - if (input->getNumControllers() > 0) + if (index < input->getNumControllers()) { enabled = true; indexController = index; indexButton = 0; + return true; } + + return false; } // Comprueba si está habilitado diff --git a/source/define_buttons.h b/source/define_buttons.h index 13d476e..2b79b37 100644 --- a/source/define_buttons.h +++ b/source/define_buttons.h @@ -61,7 +61,7 @@ public: void checkInput(); // Habilita el objeto - void enable(int index); + bool enable(int index); // Comprueba si está habilitado bool isEnabled(); diff --git a/source/director.cpp b/source/director.cpp index ce39bfd..be9adba 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -902,7 +902,7 @@ void Director::runHiScoreTable() // Ejecuta el juego en modo demo void Director::runDemoGame() { - const int playerID = rand() % 2; + const int playerID = (rand() % 2) + 1; demoGame = new Game(playerID, 0, screen, asset, lang, input, true, param, options, section, nullptr); demoGame->run(); delete demoGame; diff --git a/source/game.cpp b/source/game.cpp index bd66e22..8abe241 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -2098,7 +2098,7 @@ void Game::checkInput() if (player->canFire()) { player->setInput(input_fire_center); - createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_UP, player->isPowerUp(), i); + createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_UP, player->isPowerUp(), player->getId()); player->setFireCooldown(10); } } @@ -2108,7 +2108,7 @@ void Game::checkInput() if (player->canFire()) { player->setInput(input_fire_left); - createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_LEFT, player->isPowerUp(), i); + createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_LEFT, player->isPowerUp(), player->getId()); player->setFireCooldown(10); } } @@ -2118,7 +2118,7 @@ void Game::checkInput() if (player->canFire()) { player->setInput(input_fire_right); - createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_RIGHT, player->isPowerUp(), i); + createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_RIGHT, player->isPowerUp(), player->getId()); player->setFireCooldown(10); } } diff --git a/source/title.cpp b/source/title.cpp index fb46f98..b9803d5 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -94,7 +94,6 @@ void Title::update() if (postFade == -1) { section->name = SECTION_PROG_GAME_DEMO; - } else { @@ -215,33 +214,25 @@ void Title::checkEvents() switch (eventHandler->key.keysym.sym) { case SDLK_1: - defineButtons->enable(0); + if (defineButtons->enable(0)) + resetCounter(); break; case SDLK_2: - defineButtons->enable(1); + if (defineButtons->enable(1)) + resetCounter(); break; case SDLK_3: defineButtons->swapControllers(); screen->showNotification("Swap Controllers"); + resetCounter(); break; - + default: break; } } - - // 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; - // } - //} } } } @@ -273,7 +264,6 @@ void Title::checkInput() } } - ////////////////////////////////////////////////// // MANDO // ////////////////////////////////////////////////// @@ -334,4 +324,10 @@ void Title::reLoadTextures() { gameLogo->reLoad(); tiledbg->reLoad(); +} + +// Reinicia el contador interno +void Title::resetCounter() +{ + counter = 0; } \ No newline at end of file diff --git a/source/title.h b/source/title.h index 5156363..d49b18e 100644 --- a/source/title.h +++ b/source/title.h @@ -72,7 +72,7 @@ private: bool demo; // Indica si el modo demo estará activo 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 - Uint8 postFade; // Opción a realizar cuando termina el fundido + int postFade; // Opción a realizar cuando termina el fundido options_t *options; // Variable con todas las variables de las opciones del programa param_t *param; // Puntero con todos los parametros del programa int numControllers; // Número de mandos conectados @@ -95,6 +95,9 @@ private: // Recarga las texturas void reLoadTextures(); + // Reinicia el contador interno + void resetCounter(); + public: // Constructor Title(Screen *screen, Asset *asset, Input *input, options_t *options, Lang *lang, param_t *param, section_t *section, JA_Music_t *music);