From 42c0f19c6805fee105d57a2d70e67785154160db Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 31 Aug 2021 21:05:04 +0200 Subject: [PATCH 1/4] Working on support for various controllers --- source/director.cpp | 12 +++---- source/input.cpp | 8 +++-- source/input.h | 3 ++ source/logo.cpp | 21 +++++------- source/title.cpp | 82 +++++++++++++++++++++++++++++++++++++++------ source/title.h | 7 +++- 6 files changed, 101 insertions(+), 32 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index e7624dd..acc2938 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -371,8 +371,8 @@ bool Director::loadConfigFile() SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1); SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1); SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1); - SDL_RWwrite(file, &mOptions->input[0], sizeof(mOptions->input[0]), 1); - SDL_RWwrite(file, &mOptions->input[1], sizeof(mOptions->input[1]), 1); + SDL_RWwrite(file, &mOptions->input[0].deviceType, sizeof(mOptions->input[0].deviceType), 1); + SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1); SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1); SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1); @@ -394,8 +394,8 @@ bool Director::loadConfigFile() SDL_RWread(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1); SDL_RWread(file, &mOptions->language, sizeof(mOptions->language), 1); SDL_RWread(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1); - SDL_RWread(file, &mOptions->input[0], sizeof(mOptions->input[0]), 1); - SDL_RWread(file, &mOptions->input[1], sizeof(mOptions->input[1]), 1); + SDL_RWread(file, &mOptions->input[0].deviceType, sizeof(mOptions->input[0].deviceType), 1); + SDL_RWread(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1); SDL_RWread(file, &mOptions->filter, sizeof(mOptions->filter), 1); SDL_RWread(file, &mOptions->vSync, sizeof(mOptions->vSync), 1); @@ -435,8 +435,8 @@ bool Director::saveConfigFile() SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1); SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1); SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1); - SDL_RWwrite(file, &mOptions->input[0], sizeof(mOptions->input[0]), 1); - SDL_RWwrite(file, &mOptions->input[1], sizeof(mOptions->input[1]), 1); + SDL_RWwrite(file, &mOptions->input[0].deviceType, sizeof(mOptions->input[0].deviceType), 1); + SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1); SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1); SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1); diff --git a/source/input.cpp b/source/input.cpp index 649991d..dc8b705 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -4,8 +4,6 @@ // Contestar cuantos joystics ha detectado // Preguntarlepor los joystics que ha encontrado para ir poniendolos en la variable de opciones - - // Constructor Input::Input(std::string file) { @@ -202,4 +200,10 @@ std::string Input::getControllerName(int index) return mControllerNames[index]; else return ""; +} + +// Obten el numero de mandos conectados +int Input::getNumControllers() +{ + return mNumGamepads; } \ No newline at end of file diff --git a/source/input.h b/source/input.h index 1531512..bea512b 100644 --- a/source/input.h +++ b/source/input.h @@ -77,6 +77,9 @@ public: // Comprueba si hay algun mando conectado bool gameControllerFound(); + // Obten el numero de mandos conectados + int getNumControllers(); + // Obten el nombre de un mando de juego std::string getControllerName(int index); }; diff --git a/source/logo.cpp b/source/logo.cpp index 7c2e5e0..3ae6cbd 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -4,6 +4,9 @@ #include #endif +# define INIT_FADE 100 +# define END_LOGO 200 + // Constructor Logo::Logo(SDL_Renderer *renderer, std::string *fileList) { @@ -71,6 +74,7 @@ section_t Logo::run() { init(); const SDL_Rect rect = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT}; + const int fadeLenght = END_LOGO - INIT_FADE; while (mSection.name == PROG_SECTION_LOGO) { @@ -92,9 +96,6 @@ section_t Logo::run() } } - // Cambia el destino donde se pinta todo - //SDL_SetRenderTarget(mRenderer, mBackbuffer); - // Limpia el destino SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255); SDL_RenderClear(mRenderer); @@ -103,22 +104,16 @@ section_t Logo::run() mSprite->render(); // Dibuja el fade - if (mCounter >= 200) + if (mCounter >= INIT_FADE) { - Uint16 alpha = mCounter - 200; + Uint16 alpha = (255 * (mCounter - INIT_FADE)) / fadeLenght; if (alpha < 256) SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, alpha); else - SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255); // alpha - 0 trans, 255 opaco + SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255); SDL_RenderFillRect(mRenderer, &rect); } - // Vuelve a usar el renderizador como destino - //SDL_SetRenderTarget(mRenderer, NULL); - - // Copia el backbufer al renderizador - //SDL_RenderCopy(mRenderer, mBackbuffer, NULL, NULL); - // Actualiza la pantalla SDL_RenderPresent(mRenderer); @@ -134,7 +129,7 @@ section_t Logo::run() JA_StopMusic(); } - if (mCounter == 500) // minimo 200 + 255 + if (mCounter == END_LOGO + 20) { mCounter = 0; mSection.name = PROG_SECTION_INTRO; diff --git a/source/title.cpp b/source/title.cpp index 27d3e85..637f0fe 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -141,6 +141,11 @@ void Title::init(bool demo, Uint8 subsection) mOptions->input[0].deviceType = INPUT_USE_KEYBOARD; mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER; } + + checkInputDevices(); + + mDeviceIndex[0] = 0; + mDeviceIndex[1] = 0; // Inicializa el bitmap de Coffee mCoffeeBitmap->init(mTitleTexture, mRenderer); @@ -363,7 +368,8 @@ void Title::updateMenuLabels() else { mMenu.options->setGreyed(i, false); - mMenu.options->setItemCaption(i, mInput->getControllerName(0)); + //mMenu.options->setItemCaption(i, mInput->getControllerName(0)); + mMenu.options->setItemCaption(i, mOptions->input[0].name); } break; @@ -392,7 +398,8 @@ void Title::updateMenuLabels() else { mMenu.options->setGreyed(i, false); - mMenu.options->setItemCaption(i, mInput->getControllerName(0)); + //mMenu.options->setItemCaption(i, mInput->getControllerName(0)); + mMenu.options->setItemCaption(i, mOptions->input[1].name); } break; @@ -755,11 +762,11 @@ section_t Title::run(Uint8 subsection) updateMenuLabels(); break; case 1: // PLAYER 1 CONTROLS - switchInputs(1); + updatePlayerInputs(1); updateMenuLabels(); break; case 3: // PLAYER 2 CONTROLS - switchInputs(2); + updatePlayerInputs(2); updateMenuLabels(); break; case 5: // Language @@ -908,17 +915,45 @@ void Title::runDemoGame() } // Modifica las opciones para los controles de los jugadores -void Title::switchInputs(int value) +bool Title::updatePlayerInputs(int numPlayer) { - Uint8 temp; - temp = mOptions->input[0].deviceType; - mOptions->input[0].deviceType = mOptions->input[1].deviceType; - mOptions->input[1].deviceType = temp; + const int numDevices = mInput->getNumControllers(); - if (!mInput->gameControllerFound()) + // Si no hay mandos se deja todo de manera prefijada + if (numDevices == 0) { + mDeviceIndex[0] = 0; + mDeviceIndex[1] = 0; + mOptions->input[0].id = -1; + mOptions->input[0].name = "KEYBOARD"; mOptions->input[0].deviceType = INPUT_USE_KEYBOARD; + mOptions->input[1].id = 0; + mOptions->input[0].name = "GAME CONTROLLER"; mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER; + + return true; + } + else // Si hay mas de un dispositivo, se recorre el vector + { + // Incrementa el indice + if (mDeviceIndex[numPlayer] < numDevices - 1) + mDeviceIndex[numPlayer]++; + else + mDeviceIndex[numPlayer] = 0; + + // Si coincide con el del otro jugador, se lo intercambian + if (mDeviceIndex[0] == mDeviceIndex[1]) + { + const int temp = mDeviceIndex[0]; + mDeviceIndex[0] = mDeviceIndex[1]; + mDeviceIndex[1] = temp; + } + + // Copia el dispositivo marcado por el indice a la variable de opciones de cada jugador + mOptions->input[0] = mAvailableInputDevices[mDeviceIndex[0]]; + mOptions->input[1] = mAvailableInputDevices[mDeviceIndex[1]]; + + return true; } } @@ -940,4 +975,31 @@ void Title::createTiledBackground() } SDL_SetRenderTarget(mRenderer, nullptr); +} + +// Comprueba cuantos mandos hay conectados para gestionar el menu de opciones +void Title::checkInputDevices() +{ + printf("Filling devices for options menu...\n"); + int numControllers = mInput->getNumControllers(); + mAvailableInputDevices.clear(); + input_t temp; + + // Añade todos los mandos + if (numControllers > 0) + for (int i = 0; i < numControllers; i++) + { + temp.id = i; + temp.name = mInput->getControllerName(i); + temp.deviceType = INPUT_USE_GAMECONTROLLER; + mAvailableInputDevices.push_back(temp); + printf("Device %i:\t%s\n", mAvailableInputDevices.size(), temp.name.c_str()); + } + + // Añade el teclado al final + temp.id = -1; + temp.name = "KEYBOARD"; + temp.deviceType = INPUT_USE_KEYBOARD; + mAvailableInputDevices.push_back(temp); + printf("Device %i:\t%s\n\n", mAvailableInputDevices.size(), temp.name.c_str()); } \ No newline at end of file diff --git a/source/title.h b/source/title.h index 3429f4e..7fa6d2f 100644 --- a/source/title.h +++ b/source/title.h @@ -72,6 +72,8 @@ private: struct options_t *mOptions; // Variable con todas las variables de las opciones del programa options_t mOptionsPrevious; // Variable de respaldo para las opciones + std::vector mAvailableInputDevices; // Vector con todos los metodos de control disponibles + int mDeviceIndex[2]; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles // Carga los recursos necesarios para la sección 'Title' bool loadMedia(); @@ -92,11 +94,14 @@ private: void runDemoGame(); // Modifica las opciones para los controles de los jugadores - void switchInputs(int value); + bool updatePlayerInputs(int numPlayer); // Crea el mosaico de fondo del titulo void createTiledBackground(); + // Comprueba cuantos mandos hay conectados para gestionar el menu de opciones + void checkInputDevices(); + public: // Constructor Title(SDL_Window *window, SDL_Renderer *renderer, Input *input, std::string *fileList, options_t *options, Lang *lang); From cf072424c69116e52133b832cf688cf0d4124f0f Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 31 Aug 2021 21:30:55 +0200 Subject: [PATCH 2/4] Working on support for various controllers --- source/title.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/source/title.cpp b/source/title.cpp index 637f0fe..c3228b5 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -138,15 +138,21 @@ void Title::init(bool demo, Uint8 subsection) if (!mInput->gameControllerFound()) { + mOptions->input[0].id = 0; + mOptions->input[0].name = "KEYBOARD"; mOptions->input[0].deviceType = INPUT_USE_KEYBOARD; + + mOptions->input[1].id = 0; + mOptions->input[1].name = "GAME CONTROLLER"; mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER; } - - checkInputDevices(); - mDeviceIndex[0] = 0; + checkInputDevices(); + + mDeviceIndex[0] = mAvailableInputDevices.size(); mDeviceIndex[1] = 0; + // Inicializa el bitmap de Coffee mCoffeeBitmap->init(mTitleTexture, mRenderer); mCoffeeBitmap->setId(0); @@ -917,24 +923,26 @@ void Title::runDemoGame() // Modifica las opciones para los controles de los jugadores bool Title::updatePlayerInputs(int numPlayer) { - const int numDevices = mInput->getNumControllers(); + const int numDevices = mAvailableInputDevices.size(); // Si no hay mandos se deja todo de manera prefijada - if (numDevices == 0) + if (!mInput->gameControllerFound()) { mDeviceIndex[0] = 0; mDeviceIndex[1] = 0; + mOptions->input[0].id = -1; mOptions->input[0].name = "KEYBOARD"; mOptions->input[0].deviceType = INPUT_USE_KEYBOARD; + mOptions->input[1].id = 0; - mOptions->input[0].name = "GAME CONTROLLER"; + mOptions->input[1].name = "GAME CONTROLLER"; mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER; return true; } else // Si hay mas de un dispositivo, se recorre el vector - { + { // Incrementa el indice if (mDeviceIndex[numPlayer] < numDevices - 1) mDeviceIndex[numPlayer]++; @@ -948,7 +956,7 @@ bool Title::updatePlayerInputs(int numPlayer) mDeviceIndex[0] = mDeviceIndex[1]; mDeviceIndex[1] = temp; } - + // Copia el dispositivo marcado por el indice a la variable de opciones de cada jugador mOptions->input[0] = mAvailableInputDevices[mDeviceIndex[0]]; mOptions->input[1] = mAvailableInputDevices[mDeviceIndex[1]]; From 0b996ea321f07c158d64bed38ce4a0a7f8613e4d Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 31 Aug 2021 21:36:09 +0200 Subject: [PATCH 3/4] Working on support for various controllers --- source/title.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/source/title.cpp b/source/title.cpp index c3228b5..ccb1f63 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -148,10 +148,9 @@ void Title::init(bool demo, Uint8 subsection) } checkInputDevices(); - - mDeviceIndex[0] = mAvailableInputDevices.size(); - mDeviceIndex[1] = 0; + mDeviceIndex[0] = mAvailableInputDevices.size() - 1; + mDeviceIndex[1] = 0; // Inicializa el bitmap de Coffee mCoffeeBitmap->init(mTitleTexture, mRenderer); @@ -768,11 +767,11 @@ section_t Title::run(Uint8 subsection) updateMenuLabels(); break; case 1: // PLAYER 1 CONTROLS - updatePlayerInputs(1); + updatePlayerInputs(0); updateMenuLabels(); break; case 3: // PLAYER 2 CONTROLS - updatePlayerInputs(2); + updatePlayerInputs(1); updateMenuLabels(); break; case 5: // Language From 658bb71441f5e2a68822b2cdee60f8df2291bd28 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 1 Sep 2021 14:04:34 +0200 Subject: [PATCH 4/4] bug fixes --- media/lang/ba_BA.txt | 6 ++++- media/lang/en_UK.txt | 8 ++++-- media/lang/es_ES.txt | 6 ++++- source/director.cpp | 2 ++ source/game.cpp | 63 +++++++++++++++++++++++++++++++++----------- source/game.h | 6 ++++- source/title.cpp | 26 +++++++++++++++--- 7 files changed, 92 insertions(+), 25 deletions(-) diff --git a/media/lang/ba_BA.txt b/media/lang/ba_BA.txt index d17c888..c02e6ac 100644 --- a/media/lang/ba_BA.txt +++ b/media/lang/ba_BA.txt @@ -151,4 +151,8 @@ DESACTIVADA ## 75 - MENU DE OPCIONES ENDAVANT! ## 76 - JUEGO -1.000.000 DE PUNTS! \ No newline at end of file +1.000.000 DE PUNTS! +## 77 - PANTALLA DE GAME OVER +PUNTS J1: +## 78 - PANTALLA DE GAME OVER +PUNTS J2: \ No newline at end of file diff --git a/media/lang/en_UK.txt b/media/lang/en_UK.txt index a706281..cf3eee0 100644 --- a/media/lang/en_UK.txt +++ b/media/lang/en_UK.txt @@ -149,6 +149,10 @@ ON ## 74 - MENU DE OPCIONES OFF ## 75 - JUEGO -GET READY! +Get Ready! ## 76 - JUEGO -1.000.000 POINTS! \ No newline at end of file +1.000.000 POINTS! +## 77 - PANTALLA DE GAME OVER +PLAYER1 SCORE: +## 78 - PANTALLA DE GAME OVER +PLAYER2 SCORE: \ No newline at end of file diff --git a/media/lang/es_ES.txt b/media/lang/es_ES.txt index 40713dc..20dbb63 100644 --- a/media/lang/es_ES.txt +++ b/media/lang/es_ES.txt @@ -151,4 +151,8 @@ DESACTIVADA ## 75 - MENU DE OPCIONES ADELANTE! ## 76 - JUEGO -1.000.000 DE PUNTOS! \ No newline at end of file +1.000.000 DE PUNTOS! +## 77 - PANTALLA DE GAME OVER +PUNTUACION J1: +## 78 - PANTALLA DE GAME OVER +PUNTUACION J2: \ No newline at end of file diff --git a/source/director.cpp b/source/director.cpp index acc2938..7cc0ba9 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -257,7 +257,9 @@ void Director::setFileList() mFileList[27] = mExecutablePath + "/" + "../media/font/8bithud.png"; mFileList[46] = mExecutablePath + "/" + "../media/font/8bithud.txt"; mFileList[28] = mExecutablePath + "/" + "../media/font/nokia.png"; + mFileList[54] = mExecutablePath + "/" + "../media/font/nokia_big.png"; mFileList[52] = mExecutablePath + "/" + "../media/font/nokia.txt"; + mFileList[55] = mExecutablePath + "/" + "../media/font/nokia_big.txt"; mFileList[29] = mExecutablePath + "/" + "../media/font/smb2_big.png"; mFileList[47] = mExecutablePath + "/" + "../media/font/smb2_big.txt"; mFileList[30] = mExecutablePath + "/" + "../media/font/smb2.png"; diff --git a/source/game.cpp b/source/game.cpp index e945da0..5088dcf 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -50,10 +50,14 @@ Game::Game(int numPlayers, SDL_Renderer *renderer, std::string *filelist, Lang * mTextureText = new LTexture(); mTextureTextScoreBoard = new LTexture(); mTextureTextBig = new LTexture(); + mTextureTextNokia = new LTexture(); + mTextureTextNokiaBig = new LTexture(); mText = new Text(mFileList[48], mTextureText, mRenderer); mTextScoreBoard = new Text(mFileList[46], mTextureTextScoreBoard, mRenderer); mTextBig = new Text(mFileList[47], mTextureTextBig, mRenderer); + mTextNokia = new Text(mFileList[52], mTextureTextNokia, mRenderer); + mTextNokiaBig = new Text(mFileList[55], mTextureTextNokiaBig, mRenderer); mMenuGameOver = new Menu(mRenderer, mText, mInput, mFileList); mMenuPause = new Menu(mRenderer, mText, mInput, mFileList); @@ -190,14 +194,28 @@ Game::~Game() delete mTextureTextBig; mTextureTextBig = nullptr; + mTextureTextNokia->unload(); + delete mTextureTextNokia; + mTextureTextNokia = nullptr; + + mTextureTextNokiaBig->unload(); + delete mTextureTextNokiaBig; + mTextureTextNokiaBig = nullptr; + delete mText; mText = nullptr; + delete mTextBig; + mTextBig = nullptr; + delete mTextScoreBoard; mTextScoreBoard = nullptr; - delete mTextureTextBig; - mTextureTextBig = nullptr; + delete mTextNokia; + mTextNokia = nullptr; + + delete mTextNokiaBig; + mTextNokiaBig = nullptr; delete mMenuGameOver; mMenuGameOver = nullptr; @@ -523,6 +541,8 @@ bool Game::loadMedia() success &= loadTextureFromFile(mTextureText, mFileList[30], mRenderer); success &= loadTextureFromFile(mTextureTextScoreBoard, mFileList[27], mRenderer); success &= loadTextureFromFile(mTextureTextBig, mFileList[29], mRenderer); + success &= loadTextureFromFile(mTextureTextNokia, mFileList[28], mRenderer); + success &= loadTextureFromFile(mTextureTextNokiaBig, mFileList[54], mRenderer); success &= loadTextureFromFile(mTexturePlayer1Legs, mFileList[39], mRenderer); success &= loadTextureFromFile(mTexturePlayer1Head, mFileList[41], mRenderer); @@ -2065,8 +2085,8 @@ void Game::destroyBalloon(Uint8 index) } // Otorga los puntos correspondientes al globo - mPlayer[0]->addScore(Uint32(score * mPlayer[0]->getScoreMultiplier() * mDifficultyScoreMultiplier)); - //setScore(mPlayer[0]->getScore()); + for (int i = 0; i < mNumPlayers; i++) + mPlayer[i]->addScore(Uint32(score * mPlayer[i]->getScoreMultiplier() * mDifficultyScoreMultiplier)); updateHiScore(); // Aumenta el poder de la fase @@ -2259,7 +2279,7 @@ void Game::moveBullets() for (int i = 0; i < MAX_BULLETS; i++) if (mBullet[i]->isActive()) if (mBullet[i]->move() == MSG_BULLET_OUT) - mPlayer[0]->decScoreMultiplier(); + mPlayer[mBullet[i]->getOwner()]->decScoreMultiplier(); } // Pinta las balas activas @@ -2861,7 +2881,7 @@ void Game::checkGameInput() if (mPlayer[i]->isAlive()) { // Input a la izquierda - if (mInput->checkInput(INPUT_LEFT, REPEAT_TRUE, mOptions->input[i].deviceType)) + if (mInput->checkInput(INPUT_LEFT, REPEAT_TRUE, mOptions->input[i].deviceType, mOptions->input[i].id)) { mPlayer[i]->setInput(INPUT_LEFT); mDemo.keys.left = 1; @@ -2869,7 +2889,7 @@ void Game::checkGameInput() else { // Input a la derecha - if (mInput->checkInput(INPUT_RIGHT, REPEAT_TRUE, mOptions->input[i].deviceType)) + if (mInput->checkInput(INPUT_RIGHT, REPEAT_TRUE, mOptions->input[i].deviceType, mOptions->input[i].id)) { mPlayer[i]->setInput(INPUT_RIGHT); mDemo.keys.right = 1; @@ -2882,7 +2902,7 @@ void Game::checkGameInput() } } // Comprueba el input de disparar al centro - if (mInput->checkInput(INPUT_BUTTON_2, REPEAT_TRUE, mOptions->input[i].deviceType)) + if (mInput->checkInput(INPUT_BUTTON_2, REPEAT_TRUE, mOptions->input[i].deviceType, mOptions->input[i].id)) { if (mPlayer[i]->canFire()) { @@ -2898,7 +2918,7 @@ void Game::checkGameInput() } // Comprueba el input de disparar a la izquierda - if (mInput->checkInput(INPUT_BUTTON_1, REPEAT_TRUE, mOptions->input[i].deviceType)) + if (mInput->checkInput(INPUT_BUTTON_1, REPEAT_TRUE, mOptions->input[i].deviceType, mOptions->input[i].id)) { if (mPlayer[i]->canFire()) { @@ -2914,7 +2934,7 @@ void Game::checkGameInput() } // Comprueba el input de disparar a la derecha - if (mInput->checkInput(INPUT_BUTTON_3, REPEAT_TRUE, mOptions->input[i].deviceType)) + if (mInput->checkInput(INPUT_BUTTON_3, REPEAT_TRUE, mOptions->input[i].deviceType, mOptions->input[i].id)) { if (mPlayer[i]->canFire()) { @@ -2930,7 +2950,7 @@ void Game::checkGameInput() } // Comprueba el input de pausa - if (mInput->checkInput(INPUT_CANCEL, REPEAT_FALSE, mOptions->input[i].deviceType)) + if (mInput->checkInput(INPUT_CANCEL, REPEAT_FALSE, mOptions->input[i].deviceType, mOptions->input[i].id)) { mSection.subsection = GAME_SECTION_PAUSE; @@ -2961,7 +2981,8 @@ void Game::renderMessages() //mSpriteGetReady->render(); const color_t color = {0x17, 0x17, 0x26}; //mTextBig->writeShadowed((int)mGetReadyBitmapPath[mCounter], PLAY_AREA_CENTER_Y - 8, mLang->getText(75), color, 2); - mTextBig->writeDX(TXT_STROKE, (int)mGetReadyBitmapPath[mCounter], PLAY_AREA_CENTER_Y - 8, mLang->getText(75), 1, noColor, 1, shdwTxtColor); + //mTextBig->writeDX(TXT_STROKE, (int)mGetReadyBitmapPath[mCounter], PLAY_AREA_CENTER_Y - 8, mLang->getText(75), 1, noColor, 1, shdwTxtColor); + mTextNokiaBig->write((int)mGetReadyBitmapPath[mCounter], PLAY_AREA_CENTER_Y - 8, mLang->getText(75), -4); } // Time Stopped @@ -3273,7 +3294,7 @@ void Game::runGameOverScreen() { // Guarda los puntos saveScoreFile(); - + // Reinicia el menu mMenuGameOver->reset(); @@ -3330,8 +3351,17 @@ void Game::runGameOverScreen() SDL_RenderClear(mRenderer); // Dibuja los objetos - mTextBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 4), mLang->getText(43)); - mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 1), mLang->getText(44) + std::to_string(mPlayer[0]->getScore())); + if (mNumPlayers == 1) + { + mTextBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 4), mLang->getText(43)); + mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 1), mLang->getText(44) + std::to_string(mPlayer[0]->getScore())); + } + else + { + mTextBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - 36, mLang->getText(43)); + mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - 12, mLang->getText(77) + std::to_string(mPlayer[0]->getScore())); + mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y, mLang->getText(78) + std::to_string(mPlayer[1]->getScore())); + } mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y + BLOCK * 2, mLang->getText(45)); mMenuGameOver->render(); mFade->render(); @@ -3427,7 +3457,7 @@ void Game::initPaths() } // Letrero de GetReady - const int size = mTextBig->lenght(mLang->getText(75)); + const int size = mTextBig->lenght(mLang->getText(75), -4); const float start1 = PLAY_AREA_LEFT - size; const float finish1 = PLAY_AREA_CENTER_X - (size / 2); @@ -3470,6 +3500,7 @@ void Game::updateGameCompleted() // Actualiza las variables de ayuda void Game::updateHelper() { + // El ayudante solo funciona para un jugador // Solo ofrece ayuda cuando la amenaza o la velocidad es elevada if (mMenaceCurrent > 15) { diff --git a/source/game.h b/source/game.h index da4939e..6c86040 100644 --- a/source/game.h +++ b/source/game.h @@ -108,10 +108,14 @@ private: LTexture *mTextureText; // Textura para el texto del juego LTexture *mTextureTextScoreBoard; // Textura para el texto del marcador LTexture *mTextureTextBig; // Textura para el texto grande + LTexture *mTextureTextNokia; // Textura para la fuente de texto Nokia + LTexture *mTextureTextNokiaBig; // Textura para la fuente de texto Nokia grande Text *mText; // Fuente para los textos del juego - Text *mTextScoreBoard; // Fuente para el marcador del juego Text *mTextBig; // Fuente de texto grande + Text *mTextScoreBoard; // Fuente para el marcador del juego + Text *mTextNokia; // Otra fuente de texto para mesajes + Text *mTextNokiaBig; // Y la versión en grande Menu *mMenuGameOver; // Menú de la pantalla de game over Menu *mMenuPause; // Menú de la pantalla de pausa diff --git a/source/title.cpp b/source/title.cpp index ccb1f63..37bae5e 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -136,7 +136,7 @@ void Title::init(bool demo, Uint8 subsection) mFade->init(0x17, 0x17, 0x26); mDemo = demo; - if (!mInput->gameControllerFound()) + //if (!mInput->gameControllerFound()) { mOptions->input[0].id = 0; mOptions->input[0].name = "KEYBOARD"; @@ -152,6 +152,13 @@ void Title::init(bool demo, Uint8 subsection) mDeviceIndex[0] = mAvailableInputDevices.size() - 1; mDeviceIndex[1] = 0; + if (mInput->gameControllerFound()) + { + mOptions->input[1].id = mAvailableInputDevices[mDeviceIndex[1]].id; + mOptions->input[1].name = mAvailableInputDevices[mDeviceIndex[1]].name; + mOptions->input[1].deviceType = mAvailableInputDevices[mDeviceIndex[1]].deviceType; + } + // Inicializa el bitmap de Coffee mCoffeeBitmap->init(mTitleTexture, mRenderer); mCoffeeBitmap->setId(0); @@ -942,18 +949,29 @@ bool Title::updatePlayerInputs(int numPlayer) } else // Si hay mas de un dispositivo, se recorre el vector { + printf("numplayer:%i\n",numPlayer); + printf("deviceindex:%i\n",mDeviceIndex[numPlayer]); + // Incrementa el indice if (mDeviceIndex[numPlayer] < numDevices - 1) mDeviceIndex[numPlayer]++; else mDeviceIndex[numPlayer] = 0; + printf("deviceindex:%i\n",mDeviceIndex[numPlayer]); // Si coincide con el del otro jugador, se lo intercambian if (mDeviceIndex[0] == mDeviceIndex[1]) { - const int temp = mDeviceIndex[0]; - mDeviceIndex[0] = mDeviceIndex[1]; - mDeviceIndex[1] = temp; + printf("%i:%i\n",mDeviceIndex[0],mDeviceIndex[1]); + + //const int temp = mDeviceIndex[0]; + //mDeviceIndex[0] = mDeviceIndex[1]; + //mDeviceIndex[1] = temp; + const int theOtherPlayer = (numPlayer + 1) % 2; + mDeviceIndex[theOtherPlayer]--; + if (mDeviceIndex[theOtherPlayer] < 0) + mDeviceIndex[theOtherPlayer]=numDevices-1; + printf("%i:%i\n",mDeviceIndex[0],mDeviceIndex[1]); } // Copia el dispositivo marcado por el indice a la variable de opciones de cada jugador