From 02b528ea8cbcf2436265d4de6a50bd5bf717c0de Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 29 Aug 2021 19:54:18 +0200 Subject: [PATCH] Start to work on dual input for P1 --- media/lang/ba_BA.txt | 6 +++++- media/lang/en_UK.txt | 10 ++++++--- media/lang/es_ES.txt | 10 ++++++--- source/director.cpp | 7 ++++--- source/director.h | 5 ++--- source/game.cpp | 37 +++++++++++++++++++++++++--------- source/input.cpp | 10 +++++++-- source/input.h | 7 +++++-- source/text.cpp | 14 +++++++++++++ source/text.h | 1 + source/title.cpp | 48 ++++++++++++++++++++++++-------------------- source/title.h | 3 +++ 12 files changed, 110 insertions(+), 48 deletions(-) diff --git a/media/lang/ba_BA.txt b/media/lang/ba_BA.txt index 59a3a01..d17c888 100644 --- a/media/lang/ba_BA.txt +++ b/media/lang/ba_BA.txt @@ -147,4 +147,8 @@ NEAREST ## 73 - MENU DE OPCIONES ACTIVADA ## 74 - MENU DE OPCIONES -DESACTIVADA \ No newline at end of file +DESACTIVADA +## 75 - MENU DE OPCIONES +ENDAVANT! +## 76 - JUEGO +1.000.000 DE PUNTS! \ No newline at end of file diff --git a/media/lang/en_UK.txt b/media/lang/en_UK.txt index 3e82bc8..a706281 100644 --- a/media/lang/en_UK.txt +++ b/media/lang/en_UK.txt @@ -109,9 +109,9 @@ player 1 ## 54 - MARCADOR player 2 ## 55 - MARCADOR -mult - +mult ## 56 - MARCADOR -high score - +high score ## 57 - MARCADOR stage ## 58 - MENU DE OPCIONES @@ -147,4 +147,8 @@ NEAREST ## 73 - MENU DE OPCIONES ON ## 74 - MENU DE OPCIONES -OFF \ No newline at end of file +OFF +## 75 - JUEGO +GET READY! +## 76 - JUEGO +1.000.000 POINTS! \ No newline at end of file diff --git a/media/lang/es_ES.txt b/media/lang/es_ES.txt index 6b8a565..40713dc 100644 --- a/media/lang/es_ES.txt +++ b/media/lang/es_ES.txt @@ -109,9 +109,9 @@ jugador 1 ## 54 - MARCADOR jugador 2 ## 55 - MARCADOR -mult - +mult ## 56 - MARCADOR -max. puntuacion - +max. puntuacion ## 57 - MARCADOR fase ## 58 - MENU DE OPCIONES @@ -147,4 +147,8 @@ NEAREST ## 73 - MENU DE OPCIONES ACTIVADA ## 74 - MENU DE OPCIONES -DESACTIVADA \ No newline at end of file +DESACTIVADA +## 75 - MENU DE OPCIONES +ADELANTE! +## 76 - JUEGO +1.000.000 DE PUNTOS! \ No newline at end of file diff --git a/source/director.cpp b/source/director.cpp index 35eb4e1..d7b1b42 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -42,6 +42,8 @@ Director::Director(std::string path) // Crea los objetos mInput1 = new Input(mOptions->player1Input); mInput2 = new Input(mOptions->player2Input); + //mInput[0] = new Input(INPUT_USE_KEYBOARD); + //mInput[1] = new Input(INPUT_USE_GAMECONTROLLER); // Inicializa SDL initSDL(); @@ -140,12 +142,11 @@ void Director::initJailAudio() // Arranca SDL y crea la ventana bool Director::initSDL() { - // Indicador de inicialización + // Indicador de éxito bool success = true; // Inicializa SDL - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO | SDL_INIT_HAPTIC) < 0) - //if (SDL_Init(SDL_INIT_EVERYTHING) < 0) + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO) < 0) { printf("SDL could not initialize!\nSDL Error: %s\n", SDL_GetError()); success = false; diff --git a/source/director.h b/source/director.h index e9cd069..6a40ea0 100644 --- a/source/director.h +++ b/source/director.h @@ -34,13 +34,12 @@ private: SDL_Window *mWindow; // La ventana donde dibujamos SDL_Renderer *mRenderer; // El renderizador de la ventana - Input *mInput1; // Objeto Input para gestionar las entradas - Input *mInput2; // Objeto Input para gestionar las entradas - Logo *mLogo; // Objeto para la sección del logo Intro *mIntro; // Objeto para la sección de la intro Title *mTitle; // Objeto para la sección del titulo y el menu de opciones Game *mGame; // Objeto para la sección del juego + Input *mInput1; // Objeto Input para gestionar las entradas + Input *mInput2; // Objeto Input para gestionar las entradas Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas std::string mFileList[MAX_FILE_LIST]; // Vector con las rutas a los ficheros de recursos diff --git a/source/game.cpp b/source/game.cpp index 0e176b9..ec3d57d 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -315,6 +315,10 @@ void Game::init() mMenaceThreshold = 0; mHiScoreAchieved = false; mCurrentStage = 0; + + // BORRAR + mCurrentStage = 9; + mStageBitmapCounter = STAGE_COUNTER; mDeathCounter = DEATH_COUNTER; mExplosionTime = false; @@ -366,6 +370,9 @@ void Game::init() initEnemyPools(); initGameStages(); + // BORRAR + mStage[mCurrentStage].currentPower = mStage[mCurrentStage].powerToComplete - 10; + // Modo debug mDebug.enabled = false; mDebug.enemySet = 0; @@ -1704,7 +1711,10 @@ void Game::updateStage() mStage[mCurrentStage].currentPower = 0; // Deja el poder a cero para que no vuelva a entrar en esta condición destroyAllBalloons(); // Destruye a todos los enemigos mStage[mCurrentStage].currentPower = 0; // Vuelve a dejar el poder a cero, por lo que hubiera podido subir al destruir todos lo globos - mMenaceCurrent = 255; + mMenaceCurrent = 255; // Sube el nivel de amenaza para que no cree mas globos + for (int i = 0; i < mNumPlayers; i++) // Añade un millon de puntos a los jugadores que queden vivos + if (mPlayer[i]->isAlive()) + mPlayer[i]->addScore(1000000); JA_StopMusic(); } JA_PlaySound(mSoundStageChange); @@ -1735,7 +1745,7 @@ void Game::updateDeath() allPlayersAreDead &= (!mPlayer[i]->isAlive()); if (!mPlayer[i]->isAlive()) - { + { // Animación if ((mPlayer[i]->getDeathCounter() / 5) % 4 == 0) mSmartSprite[mPlayer[i]->mDeathIndex]->setSpriteClip(24 * 0, 24, 24, 24); @@ -2946,15 +2956,16 @@ void Game::renderMessages() if ((mCounter < STAGE_COUNTER) && (!mDemo.enabled)) { mSpriteGetReady->setPosX((int)mGetReadyBitmapPath[mCounter]); - mSpriteGetReady->render(); + //mSpriteGetReady->render(); + const color_t color = {0x17, 0x17, 0x26}; + mTextBig->writeShadowed((int)mGetReadyBitmapPath[mCounter], PLAY_AREA_CENTER_Y - 8, mLang->getText(75), color, 2); } // Time Stopped if (mTimeStopped) { if ((mTimeStoppedCounter > 100) || (mTimeStoppedCounter % 10 > 4)) - //mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, "Time Stopped: " + std::to_string(mTimeStoppedCounter / 10)); - mText->writeDX(TXT_CENTER | TXT_SHADOW, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, mLang->getText(36) + std::to_string(mTimeStoppedCounter / 10), 1, noColor, 1, shdwTxtColor); + mText->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, mLang->getText(36) + std::to_string(mTimeStoppedCounter / 10), 1, noColor, 1, shdwTxtColor); if (mTimeStoppedCounter > 100) { @@ -2975,11 +2986,19 @@ void Game::renderMessages() // STAGE NUMBER std::string text = mLang->getText(38) + std::to_string(mStage[mCurrentStage].number); - if (mGameCompleted) // Texto de juego completado - text = mLang->getText(50); - if (mStageBitmapCounter < STAGE_COUNTER) - mTextBig->writeDX(TXT_CENTER | TXT_SHADOW, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter], text, 1, noColor, 2, shdwTxtColor); + { + if (!mGameCompleted) + { + mTextBig->writeDX(TXT_CENTER | TXT_SHADOW, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter], text, 1, noColor, 2, shdwTxtColor); + } + else + { // Texto de juego completado + text = mLang->getText(50); + mTextBig->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter], text, 1, noColor, 1, shdwTxtColor); + mText->writeDX(TXT_CENTER | TXT_STROKE, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter] + 17, mLang->getText(76), 1, noColor, 1, shdwTxtColor); + } + } } // Habilita el efecto del item de detener el tiempo diff --git a/source/input.cpp b/source/input.cpp index 40cb5a3..d5b5789 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -141,7 +141,7 @@ bool Input::discoverGameController() int nJoysticks = SDL_NumJoysticks(); mNumGamepads = 0; - // Count how many controllers there are + // Cuenta el numero de mandos for (int i = 0; i < nJoysticks; i++) if (SDL_IsGameController(i)) mNumGamepads++; @@ -154,7 +154,7 @@ bool Input::discoverGameController() for (int i = 0; i < mNumGamepads; i++) { - // Open the controller and add it to our list + // Abre el mando y lo añade a la lista SDL_GameController *pad = SDL_GameControllerOpen(i); if (SDL_GameControllerGetAttached(pad) == 1) mConnectedControllers.push_back(pad); @@ -167,4 +167,10 @@ bool Input::discoverGameController() } return found; +} + +// Establece el método de entrada +void Input::setSource(Uint8 value) +{ + mSource = value; } \ No newline at end of file diff --git a/source/input.h b/source/input.h index 666ed3d..2a93082 100644 --- a/source/input.h +++ b/source/input.h @@ -54,6 +54,9 @@ private: int mSource; // Indica si el objeto usará un mando o un teclado + // Comprueba si hay un mando conectado + bool discoverGameController(); + public: // Constructor Input(int source); @@ -70,8 +73,8 @@ public: // Comprueba si un input esta activo bool checkInput(Uint8 input, bool repeat); - // Comprueba si hay un mando conectado - bool discoverGameController(); + // Establece el método de entrada + void setSource(Uint8 value); }; #endif diff --git a/source/text.cpp b/source/text.cpp index dcb5e2c..936d2cf 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -98,6 +98,7 @@ void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, col const bool centered = ((flags & TXT_CENTER) == TXT_CENTER); const bool shadowed = ((flags & TXT_SHADOW) == TXT_SHADOW); const bool colored = ((flags & TXT_COLOR) == TXT_COLOR); + const bool stroked = ((flags & TXT_STROKE) == TXT_STROKE); if (centered) x -= (Text::lenght(text, kerning) / 2); @@ -105,6 +106,19 @@ void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, col if (shadowed) writeColored(x + shadowDistance, y + shadowDistance, text, shadowColor, kerning, lenght); + if (stroked) + { + writeColored(x + shadowDistance, y + shadowDistance, text, shadowColor, kerning, lenght); + writeColored(x - shadowDistance, y + shadowDistance, text, shadowColor, kerning, lenght); + writeColored(x + shadowDistance, y - shadowDistance, text, shadowColor, kerning, lenght); + writeColored(x - shadowDistance, y - shadowDistance, text, shadowColor, kerning, lenght); + + writeColored(x, y + shadowDistance, text, shadowColor, kerning, lenght); + writeColored(x, y - shadowDistance, text, shadowColor, kerning, lenght); + writeColored(x + shadowDistance, y, text, shadowColor, kerning, lenght); + writeColored(x - shadowDistance, y, text, shadowColor, kerning, lenght); + } + if (colored) writeColored(x, y, text, textColor, kerning, lenght); else diff --git a/source/text.h b/source/text.h index ad7ca9c..e74b9db 100644 --- a/source/text.h +++ b/source/text.h @@ -8,6 +8,7 @@ #define TXT_COLOR 1 #define TXT_SHADOW 2 #define TXT_CENTER 4 +#define TXT_STROKE 8 // Clase texto. Pinta texto en pantalla a partir de un bitmap class Text diff --git a/source/title.cpp b/source/title.cpp index 41ee0b6..adbffe5 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -219,21 +219,7 @@ void Title::init(bool demo, Uint8 subsection) mEvents[i] = EVENT_WAITING; // Crea el mosaico de fondo del titulo - SDL_SetRenderTarget(mRenderer, mBackground); - SDL_SetRenderDrawColor(mRenderer, 0x43, 0x43, 0x4F, 0xFF); - SDL_RenderClear(mRenderer); - - mTile->init(0, 0, 64, 64, mTitleTexture, mRenderer); - mTile->setSpriteClip(192, 0, 64, 64); - for (int i = 0; i < 8; i++) - for (int j = 0; j < 6; j++) - { - mTile->setPosX(i * 64); - mTile->setPosY(j * 64); - mTile->render(); - } - - SDL_SetRenderTarget(mRenderer, nullptr); + createTiledBackground(); mBackgroundWindow.x = 0; mBackgroundWindow.y = 0; @@ -251,13 +237,10 @@ void Title::init(bool demo, Uint8 subsection) mMenu.title->addItem(mLang->getText(51)); // 1 PLAYER mMenu.title->addItem(mLang->getText(52), 0, 5); // 2 PLAYERS mMenu.title->addItem(mLang->getText(1), 0, 5); // OPTIONS - //mMenu.title->addItem(mLang->getText(2), 0, 5); // HOW TO PLAY - mMenu.title->addItem(mLang->getText(3)); // QUIT + mMenu.title->addItem(mLang->getText(3)); // QUIT mMenu.title->setDefaultActionWhenCancel(3); mMenu.title->setBackgroundColor(0x30, 0x30, 0x40, 192); - //mMenu.title->setSelectorColor(0xe5, 0x1c, 0x23, 255); mMenu.title->setSelectorColor(0xe5, 0x1c, 0x23, 0); - //mMenu.title->setSelectorTextColor(0xFF, 0xF1, 0x76); mMenu.title->setSelectorTextColor(0xFF, 0xB4, 0x00); mMenu.title->centerMenuOnX(SCREEN_CENTER_X); mMenu.title->centerMenuElementsOnX(); @@ -493,6 +476,7 @@ void Title::applyOptions() mLang->setLang(mOptions->language); updateMenuLabels(); + createTiledBackground(); } // Bucle para el titulo del juego @@ -838,14 +822,14 @@ section_t Title::run(Uint8 subsection) // Bitmaps con el logo/titulo del juego mCoffeeBitmap->render(); mCrisisBitmap->render(); - + // Texto con el copyright y versión mText2->writeDX(TXT_CENTER | TXT_SHADOW, SCREEN_CENTER_X, SCREEN_HEIGHT - (BLOCK * 2), TEXT_COPYRIGHT, 1, noColor, 1, shdwTxtColor); } - + if (mMenuVisible == true) mMenu.active->render(); - + mDustBitmapR->animate(0); mDustBitmapL->animate(0); mDustBitmapR->render(); @@ -908,4 +892,24 @@ void Title::SwitchInputs(int value) temp = mOptions->player1Input; mOptions->player1Input = mOptions->player2Input; mOptions->player2Input = temp; +} + +// Crea el mosaico de fondo del titulo +void Title::createTiledBackground() +{ + SDL_SetRenderTarget(mRenderer, mBackground); + SDL_SetRenderDrawColor(mRenderer, 0x43, 0x43, 0x4F, 0xFF); + SDL_RenderClear(mRenderer); + + mTile->init(0, 0, 64, 64, mTitleTexture, mRenderer); + mTile->setSpriteClip(192, 0, 64, 64); + for (int i = 0; i < 8; i++) + for (int j = 0; j < 6; j++) + { + mTile->setPosX(i * 64); + mTile->setPosY(j * 64); + mTile->render(); + } + + SDL_SetRenderTarget(mRenderer, nullptr); } \ No newline at end of file diff --git a/source/title.h b/source/title.h index ec9d838..44e8a9d 100644 --- a/source/title.h +++ b/source/title.h @@ -94,6 +94,9 @@ private: // Modifica las opciones para los controles de los jugadores void SwitchInputs(int value); + // Crea el mosaico de fondo del titulo + void createTiledBackground(); + public: // Constructor Title(SDL_Window *window, SDL_Renderer *renderer, Input *input, std::string *fileList, options_t *options, Lang *lang);