From 2330820a1576106db06485e553b5347ce0982f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Mon, 5 Apr 2021 19:07:33 +0200 Subject: [PATCH] "How to play" added --- source/gamedirector.cpp | 94 ++++++++++++++++++++++++++++------------- source/gamedirector.h | 1 + source/text.cpp | 19 +++++++++ source/text.h | 17 +++++--- 4 files changed, 95 insertions(+), 36 deletions(-) diff --git a/source/gamedirector.cpp b/source/gamedirector.cpp index 8155d53..bfea4c4 100644 --- a/source/gamedirector.cpp +++ b/source/gamedirector.cpp @@ -183,7 +183,7 @@ void GameDirector::initProg() mMenu.title->addItem("OPTIONS"); mMenu.title->addItem("HOW TO PLAY", 0, 5); mMenu.title->addItem("QUIT"); - mMenu.title->setDefaultActionWhenCancel(2); + mMenu.title->setDefaultActionWhenCancel(3); mMenu.title->setBackgroundColor(0x30, 0x30, 0x40, 192); mMenu.title->setSelectorColor(0xe5, 0x1c, 0x23, 255); mMenu.title->setSelectorTextColor(0xFF, 0xF1, 0x76); @@ -684,6 +684,7 @@ void GameDirector::resetTitle(Uint8 subsection) mTitle.menuVisible = false; mTitle.nextProgSection = PROG_SECTION_GAME; mTitle.instructionsCounter = INSTRUCTIONS_COUNTER; + mTitle.instructionsMode = MODE_AUTO; // Inicializa el bitmap de Coffee mTitle.coffeeBitmap->init(mTexture[TEXTURE_TITLE].texture, mRenderer); @@ -4064,7 +4065,7 @@ void GameDirector::renderFade(Uint8 index) void GameDirector::renderMessages() { // GetReady - if (mGame.counter < STAGE_COUNTER) + if ((mGame.counter < STAGE_COUNTER) && (!mDemo.enabled)) { mGame.getReadyBitmap->setPosX((int)mGame.getReadyBitmapPath[mGame.counter]); mGame.getReadyBitmap->render(); @@ -4096,8 +4097,8 @@ void GameDirector::renderMessages() { if (mDemo.counter % 30 > 14) { - mText.black->writeCentered(PLAY_AREA_CENTER_X + 1, PLAY_AREA_FIRST_QUARTER_Y + 1, "D E M O"); - mText.white->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, "D E M O"); + mText.blackX2->writeCentered(PLAY_AREA_CENTER_X + 2, PLAY_AREA_FIRST_QUARTER_Y + 2, "D E M O"); + mText.whiteX2->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, "D E M O"); } } @@ -4752,8 +4753,7 @@ void GameDirector::runTitle(Uint8 subsection) mMenu.active->reset(); mMenu.keyPressed = false; mTitle.section = TITLE_SECTION_INSTRUCTIONS; - //runInstructions(MODE_MANUAL); - //setProgSection(PROG_SECTION_TITLE,TITLE_SECTION_INSTRUCTIONS); + mTitle.instructionsMode = MODE_MANUAL; break; case 3: // QUIT JA_PlaySound(mSound[SOUND_MENU_CANCEL].sound); @@ -4827,7 +4827,7 @@ void GameDirector::runTitle(Uint8 subsection) // Sección Instrucciones if (mTitle.section == TITLE_SECTION_INSTRUCTIONS) - runInstructions(MODE_AUTO); + runInstructions(mTitle.instructionsMode); } quitTitle(); @@ -5039,6 +5039,10 @@ void GameDirector::runInstructions(Uint8 mode) Sprite *sprite = new Sprite(); SDL_Rect srcRect = {0, 0, 16, 16}; + bool wannaExit = false; + if (mode == MODE_MANUAL) + mTitle.instructionsCounter = 0; + const SDL_Rect destRect1 = {60, 88 + (16 * 0), 16, 16}; // Disquito const SDL_Rect destRect2 = {60, 88 + (16 * 1), 16, 16}; // Gavineixon const SDL_Rect destRect3 = {60, 88 + (16 * 2), 16, 16}; // Pacmar @@ -5061,8 +5065,13 @@ void GameDirector::runInstructions(Uint8 mode) if ((mEventHandler->type == SDL_KEYDOWN) || (mEventHandler->type == SDL_JOYBUTTONDOWN)) { - JA_StopMusic(); - setProgSection(PROG_SECTION_TITLE); + if (mode == MODE_AUTO) + { + JA_StopMusic(); + setProgSection(PROG_SECTION_TITLE); + } + else + wannaExit = true; } } @@ -5070,17 +5079,19 @@ void GameDirector::runInstructions(Uint8 mode) SDL_SetRenderTarget(mRenderer, mInstructionsSurface); SDL_SetRenderDrawColor(mRenderer, 0x27, 0x27, 0x36, 255); SDL_RenderClear(mRenderer); - mText.white->writeCentered(SCREEN_CENTER_X, 8, "OBJECTIVE", 0); - mText.white->writeCentered(SCREEN_CENTER_X, 24, "YOU HAVE TO POP AS MANY", 0); - mText.white->writeCentered(SCREEN_CENTER_X, 34, "BALLOONS AS YOU CAN", 0); - mText.white->writeCentered(SCREEN_CENTER_X, 48, "DIFFICULTY WILL BE INCREASED", 0); - mText.white->writeCentered(SCREEN_CENTER_X, 58, "AS YOU SCORE POINTS", 0); - mText.white->writeCentered(SCREEN_CENTER_X, 75, "ITEMS", 0); + mText.white->writeCenteredAndColored(SCREEN_CENTER_X, 8, "OBJECTIVE", 0, 0xFF, 0x7A, 0x00); + mText.white->writeCentered(SCREEN_CENTER_X, 24, "YOU HAVE TO POP AS MANY"); + mText.white->writeCentered(SCREEN_CENTER_X, 34, "BALLOONS AS YOU CAN"); + mText.white->writeCentered(SCREEN_CENTER_X, 48, "DIFFICULTY WILL BE INCREASED"); + mText.white->writeCentered(SCREEN_CENTER_X, 58, "AS YOU SCORE POINTS"); + mText.white->writeCenteredAndColored(SCREEN_CENTER_X, 75, "ITEMS", 0, 0xFF, 0x7A, 0x00); mText.white->write(84, 92, "1.000 POINTS", 0); mText.white->write(84, 108, "2.500 POINTS", 0); mText.white->write(84, 124, "5.000 POINTS", 0); mText.white->write(84, 140, "TIME STOPPER", 0); mText.white->write(84, 156, "EXTRA HIT", 0); + if ((mode == MODE_MANUAL) && (mTitle.instructionsCounter % 50 > 14)) + mText.white->writeCenteredAndColored(SCREEN_CENTER_X, SCREEN_HEIGHT - 12, "PRESS ANY KEY TO RETURN", 0, 0xFF, 0x7A, 0x00); // Disquito sprite->init(destRect1, mTexture[TEXTURE_ITEMS].texture, mRenderer); @@ -5125,27 +5136,52 @@ void GameDirector::runInstructions(Uint8 mode) SDL_RenderClear(mRenderer); // Dibuja los objetos - window.y = std::max(0, SCREEN_HEIGHT - (INSTRUCTIONS_COUNTER - mTitle.instructionsCounter) + 100); + if (mode == MODE_AUTO) + window.y = std::max(0, SCREEN_HEIGHT - (INSTRUCTIONS_COUNTER - mTitle.instructionsCounter) + 100); + else + window.y = 0; SDL_RenderCopy(mRenderer, mInstructionsSurface, NULL, &window); // Muestra la pantalla SDL_RenderPresent(mRenderer); - mTitle.instructionsCounter--; - - if (mTitle.instructionsCounter == 0) + // Lógica + if (SDL_GetTicks() - mProg.ticks > mProg.ticksSpeed) { - resetTitle(TITLE_SECTION_1); - mTitle.section = TITLE_SECTION_3; - mTitle.nextProgSection = PROG_SECTION_LOGO; + // Actualiza el contador de ticks + mProg.ticks = SDL_GetTicks(); - // Prepara las variables para la sección 3 del titulo - mTitle.dustBitmapL->setEnabled(false); - mTitle.dustBitmapR->setEnabled(false); - mTitle.menuVisible = true; - mTitle.coffeeBitmap->setPosY(11); - mTitle.crisisBitmap->setPosY(57); - mMenu.title->setSelectorPos(2); + // Modo automático + if (mode == MODE_AUTO) + { + mTitle.instructionsCounter--; + + if (mTitle.instructionsCounter == 0) + { + resetTitle(TITLE_SECTION_1); + mTitle.nextProgSection = PROG_SECTION_LOGO; + } + } + // Modo manual + else + { + ++mTitle.instructionsCounter %= 60000; + + if (wannaExit) + { + resetTitle(TITLE_SECTION_1); + mTitle.section = TITLE_SECTION_3; + mTitle.nextProgSection = PROG_SECTION_LOGO; + + // Prepara las variables para la sección 3 del titulo + mTitle.dustBitmapL->setEnabled(false); + mTitle.dustBitmapR->setEnabled(false); + mTitle.menuVisible = true; + mTitle.coffeeBitmap->setPosY(11); + mTitle.crisisBitmap->setPosY(57); + mMenu.title->setSelectorPos(2); + } + } } } delete sprite; diff --git a/source/gamedirector.h b/source/gamedirector.h index 9570802..04e8086 100644 --- a/source/gamedirector.h +++ b/source/gamedirector.h @@ -169,6 +169,7 @@ private: Uint8 nextProgSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo Uint8 events[TITLE_TOTAL_EVENTS]; // Vector para coordinar los eventos de la pantalla de titulo Uint16 instructionsCounter; // Contador para las instrucciones + Uint8 instructionsMode; // Modo en el que se van a mostrar las instrucciones SmartSprite *coffeeBitmap; // Sprite con la palabra COFFEE para la pantalla de titulo SmartSprite *crisisBitmap; // Sprite con la palabra CRISIS para la pantalla de titulo AnimatedSprite *dustBitmapL; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo diff --git a/source/text.cpp b/source/text.cpp index b3545c7..93666cd 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -216,6 +216,25 @@ void Text::writeCentered(int x, int y, std::string text, int kerning) } } +// Escribe el texto centrado en un punto x y con kerning +void Text::writeCenteredAndColored(int x, int y, std::string text, int kerning, Uint8 R, Uint8 G, Uint8 B) +{ + mSprite->getTexture()->setColor(R, G, B); + + x = x - (Text::lenght(text, kerning) / 2); + Uint16 shift = 0; + for (Uint8 i = 0; i < text.length(); ++i) + { + mSprite->setSpriteClip(mOffset[int(text[i])].x, mOffset[int(text[i])].y, mSprite->getWidth(), mSprite->getHeight()); + mSprite->setPosX(x + shift); + mSprite->setPosY(y); + mSprite->render(); + shift += (mOffset[int(text[i])].w + kerning); + } + + mSprite->getTexture()->setColor(255, 255, 255); +} + // Obtiene la longitud en pixels de una cadena Uint16 Text::lenght(std::string text, int kerning) { diff --git a/source/text.h b/source/text.h index 1a5950b..22a2ad7 100644 --- a/source/text.h +++ b/source/text.h @@ -7,8 +7,8 @@ // Clase texto. Pinta texto en pantalla a partir de un bitmap class Text { - private: - Sprite *mSprite;// Objeto con los graficos para el texto +private: + Sprite *mSprite; // Objeto con los graficos para el texto struct Offset { @@ -16,10 +16,10 @@ class Text int y; Uint8 w; }; - Offset mOffset[255];// Vector con las posiciones y ancho de cada letra + Offset mOffset[255]; // Vector con las posiciones y ancho de cada letra - Uint8 mType;// Indica si el texto es de anchura fija o variable - Uint8 mSize;// Altura del texto + Uint8 mType; // Indica si el texto es de anchura fija o variable + Uint8 mSize; // Altura del texto public: // Constructor @@ -39,12 +39,15 @@ public: // Escribe el texto con colores void writeColored(int x, int y, std::string text, Uint8 R, Uint8 G, Uint8 B); - // Escribe el texto con sombra + // Escribe el texto con sombra void writeShadowed(int x, int y, std::string text, Uint8 R, Uint8 G, Uint8 B); // Escribe el texto centrado en un punto x y con kerning void writeCentered(int x, int y, std::string text, int kerning = 0); + // Escribe el texto centrado en un punto x y con kerning + void writeCenteredAndColored(int x, int y, std::string text, int kerning = 0, Uint8 R = 255, Uint8 G = 255, Uint8 B = 255); + // Obtiene la longitud en pixels de una cadena Uint16 lenght(std::string text, int kerning); @@ -53,7 +56,7 @@ public: // Establece el valor de la variable void setType(Uint8 type); - + // Obtiene el valor de la variable Uint8 getSize();