diff --git a/source/const.h b/source/const.h index 4768f47..33799a5 100644 --- a/source/const.h +++ b/source/const.h @@ -269,6 +269,7 @@ const int MULTIPLIER_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2; // PowerBall #define POWERBALL_SCREENPOWER_MINIMUM 10 +#define POWERBALL_COUNTER 8 // Tipos de bala #define BULLET_UP 1 diff --git a/source/director.cpp b/source/director.cpp index 934e3fe..b36d086 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -76,7 +76,7 @@ Director::~Director() delete mInput1; mInput1 = nullptr; - + delete mInput2; mInput2 = nullptr; @@ -490,7 +490,7 @@ bool Director::loadConfigFile() // Aplica las opciones SDL_SetWindowFullscreen(mWindow, mOptions->fullScreenMode); SDL_SetWindowSize(mWindow, SCREEN_WIDTH * mOptions->windowSize, SCREEN_HEIGHT * mOptions->windowSize); - mLang->setLang(mOptions->language); + mLang->setLang(mOptions->language); // Cierra el fichero SDL_RWclose(file); diff --git a/source/game.cpp b/source/game.cpp index f151500..16ee0a2 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -89,6 +89,7 @@ Game::~Game() mRenderer = nullptr; mFileList = nullptr; + mLang = nullptr; mInput[0] = nullptr; mInput[1] = nullptr; @@ -289,7 +290,6 @@ void Game::init() mSection.subsection = GAME_SECTION_PLAY_1P; mMenaceCurrent = 0; mMenaceThreshold = 0; - //mHiScore = 0; mHiScoreAchieved = false; mCurrentStage = 0; mStageBitmapCounter = STAGE_COUNTER; @@ -318,6 +318,7 @@ void Game::init() mHelper.itemCoffeeOdds = ITEM_COFFEE_ODDS; mHelper.itemCoffeeMachineOdds = ITEM_COFFEE_MACHINE_ODDS; mPowerBallEnabled = false; + mPowerBallCounter = 0; mCoffeeMachineEnabled = false; mPostFade = 0; @@ -354,11 +355,6 @@ void Game::init() // Iniciualiza el objeto para el fundido mFade->init(0x27, 0x27, 0x36); - // Inicializa los objetos de texto - //mText->init(); - //mTextScoreBoard->init(); - //mTextBig->init(); - // Inicializa el objeto con el menu de pausa mMenuPause->init("PAUSE", 0, 12 * BLOCK, MENU_BACKGROUND_SOLID); mMenuPause->addItem(mLang->getText(46)); @@ -1444,16 +1440,16 @@ void Game::deployEnemyFormation() } else { + // Decrementa el contador de despliegues enemigos de la PowerBall + mPowerBallCounter > 0 ? mPowerBallCounter-- : mPowerBallCounter = 0; // Elige una formación enemiga la azar Uint8 set = (rand() % 10); // Evita repetir la ultima formación enemiga desplegada if (set == mLastEnemyDeploy) - { - set++; - set %= 10; - } + ++set %= 10; + mLastEnemyDeploy = set; if (mDebug.enabled) @@ -1850,6 +1846,7 @@ void Game::createPowerBall() mBalloon[getBalloonFreeIndex()]->init(posX, posY, POWER_BALL, BALLOON_VELX_POSITIVE * (((rand() % 2) * 2) - 1), mEnemySpeed, 100, mTextureBalloon, mRenderer); mPowerBallEnabled = true; + mPowerBallCounter = POWERBALL_COUNTER; } // Establece a cero todos los valores del vector de objetos globo @@ -2245,11 +2242,14 @@ void Game::createBullet(int x, int y, Uint8 kind, bool poweredUp, int owner) void Game::updateItems() { for (int i = 0; i < MAX_ITEMS; i++) - if (mItem[i]->update() == 1) + { + mItem[i]->update(); + if (mItem[i]->floorCollision()) { JA_PlaySound(mSoundCollision); mEffect.shake = true; } + } } // Pinta los items activos @@ -3317,7 +3317,7 @@ void Game::renderDebugInfo() // Indica si se puede crear una powerball bool Game::canPowerBallBeCreated() { - if ((!mPowerBallEnabled) && (calculateScreenPower() > POWERBALL_SCREENPOWER_MINIMUM)) + if ((!mPowerBallEnabled) && (calculateScreenPower() > POWERBALL_SCREENPOWER_MINIMUM) && (mPowerBallCounter == 0)) return true; else return false; diff --git a/source/game.h b/source/game.h index 301d17d..beb5272 100644 --- a/source/game.h +++ b/source/game.h @@ -79,9 +79,9 @@ private: int itemCoffeeMachineOdds; // Probabilidad de aparición del objeto }; - SDL_Renderer *mRenderer; // El renderizador de la ventana - std::string *mFileList; // Lista de ficheros con los recursos - Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas + SDL_Renderer *mRenderer; // El renderizador de la ventana + std::string *mFileList; // Lista de ficheros con los recursos + Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas int mNumPlayers; // Numero de jugadores Player *mPlayer[2]; // Vector con los jugadores jugador @@ -92,22 +92,22 @@ private: Item *mItem[MAX_ITEMS]; // Vector con los objetos item SmartSprite *mSmartSprite[MAX_SMART_SPRITES]; // Vector para almacenar y gestionar SmartSprites - LTexture *mTextureBalloon; // Textura para los enemigos - LTexture *mTextureBullet; // Textura para las balas - LTexture *mTextureGameBG; // Textura para el fondo del juego - LTexture *mTextureGameText; // Textura para los sprites con textos - LTexture *mTextureItems; // Textura para los items - LTexture *mTexturePlayer1Head; // Textura para la cabeza del jugador1 - LTexture *mTexturePlayer1Body; // Textura para el cuerpo del jugador1 - LTexture *mTexturePlayer1Death; // Textura para la animación de muerte del jugador1 - LTexture *mTexturePlayer1Legs; // Textura para las piernas del jugador - LTexture *mTexturePlayer2Head; // Textura para la cabeza del jugador2 - LTexture *mTexturePlayer2Body; // Textura para el cuerpo del jugador2 - LTexture *mTexturePlayer2Death; // Textura para la animación de muerte del jugador2 - LTexture *mTexturePlayer2Legs; // Textura para las piernas del jugador - LTexture *mTextureText; // Textura para el texto del juego - LTexture *mTextureTextScoreBoard; // Textura para el texto del marcador - LTexture *mTextureTextBig; // Textura para el texto grande + LTexture *mTextureBalloon; // Textura para los enemigos + LTexture *mTextureBullet; // Textura para las balas + LTexture *mTextureGameBG; // Textura para el fondo del juego + LTexture *mTextureGameText; // Textura para los sprites con textos + LTexture *mTextureItems; // Textura para los items + LTexture *mTexturePlayer1Head; // Textura para la cabeza del jugador1 + LTexture *mTexturePlayer1Body; // Textura para el cuerpo del jugador1 + LTexture *mTexturePlayer1Death; // Textura para la animación de muerte del jugador1 + LTexture *mTexturePlayer1Legs; // Textura para las piernas del jugador + LTexture *mTexturePlayer2Head; // Textura para la cabeza del jugador2 + LTexture *mTexturePlayer2Body; // Textura para el cuerpo del jugador2 + LTexture *mTexturePlayer2Death; // Textura para la animación de muerte del jugador2 + LTexture *mTexturePlayer2Legs; // Textura para las piernas del jugador + LTexture *mTextureText; // Textura para el texto del juego + LTexture *mTextureTextScoreBoard; // Textura para el texto del marcador + LTexture *mTextureTextBig; // Textura para el texto grande Text *mText; // Fuente para los textos del juego Text *mTextScoreBoard; // Fuente para el marcador del juego @@ -182,6 +182,7 @@ private: effect_t mEffect; // Variable para gestionar los efectos visuales helper_t mHelper; // Variable para gestionar las ayudas bool mPowerBallEnabled; // Indica si hay una powerball ya activa + Uint8 mPowerBallCounter; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra bool mCoffeeMachineEnabled; // Indica si hay una máquina de café en el terreno de juego Uint8 mPostFade; // Qué hacer al acabar el fade float mSin[360]; // Vector con los valores del seno para 360 grados diff --git a/source/instructions.cpp b/source/instructions.cpp index be49e54..380306b 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -73,7 +73,6 @@ void Instructions::init() mSprite->init(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, mItemTexture, mRenderer); mTicks = 0; mTicksSpeed = 15; - //mText->init(); mManualQuit = false; mCounter = 0; } diff --git a/source/item.cpp b/source/item.cpp index f7b7b00..ef639f0 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -30,7 +30,7 @@ void Item::init(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer * mVelY = -4.0f; mAccelX = 0.0f; mAccelY = 0.2f; - mStatus = 0; + mFloorCollision = false; mCollider.r = mWidth / 2; shiftColliders(); @@ -149,7 +149,7 @@ void Item::render() // Actualiza la posición y estados del objeto void Item::move() { - mStatus = 0; + mFloorCollision = false; // Calcula la nueva posición mPosX += mVelX; @@ -169,15 +169,15 @@ void Item::move() mVelX = -mVelX; } - // Si se sale por arriba - //if (mPosY < PLAY_AREA_TOP) - //{ - // // Corrige - // mPosY = PLAY_AREA_TOP; - // - // // Invierte el sentido - // mVelY = -mVelY; - //} + // Si se sale por arriba rebota (excepto la maquina de café) + if ((mPosY < PLAY_AREA_TOP) && !(mClass == ITEM_COFFEE_MACHINE)) + { + // Corrige + mPosY = PLAY_AREA_TOP; + + // Invierte el sentido + mVelY = -mVelY; + } // Si el objeto se sale por la parte inferior if (mPosY + mHeight > PLAY_AREA_BOTTOM) @@ -192,7 +192,7 @@ void Item::move() mAccelY = 0; mPosY = PLAY_AREA_BOTTOM - mHeight; if (mClass == ITEM_COFFEE_MACHINE) - mStatus = 1; + mFloorCollision = true; } // Actualiza la posición del sprite @@ -207,7 +207,7 @@ void Item::erase() } // Actualiza el objeto a su posicion, animación y controla los contadores -int Item::update() +void Item::update() { if (mEnabled) { @@ -217,8 +217,6 @@ int Item::update() updateTimeToLive(); checkTimeToLive(); } - - return mStatus; } // Actualiza el contador @@ -290,4 +288,10 @@ void Item::shiftColliders() { mCollider.x = int(mPosX + mCollider.r); mCollider.y = int(mPosY + mCollider.r); +} + +// Informa si el objeto ha colisionado con el suelo +bool Item::floorCollision() +{ + return mFloorCollision; } \ No newline at end of file diff --git a/source/item.h b/source/item.h index 0da7b0c..0084c87 100644 --- a/source/item.h +++ b/source/item.h @@ -18,7 +18,7 @@ private: float mVelY; // Velocidad en el eje Y float mAccelX; // Aceleración en el eje X float mAccelY; // Aceleración en el eje Y - int mStatus; // Contiene mensajes de estado + bool mFloorCollision; // Indica si el objeto colisiona con el suelo AnimatedSprite *mSprite; // Sprite con los graficos del objeto @@ -52,7 +52,7 @@ public: void erase(); // Actualiza al objeto a su posicion, animación y controla los contadores - int update(); + void update(); // Actualiza el contador void updateTimeToLive(); @@ -86,6 +86,9 @@ public: // Temporizador con el tiempo que el objeto está presente Uint16 mTimeToLive; + + // Informa si el objeto ha colisionado con el suelo + bool floorCollision(); }; #endif diff --git a/source/title.cpp b/source/title.cpp index 4c540f3..bf6c090 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -41,6 +41,13 @@ Title::Title(SDL_Window *window, SDL_Renderer *renderer, Input *input, std::stri // Destructor Title::~Title() { + mWindow = nullptr; + mRenderer = nullptr; + mInput = nullptr; + mFileList = nullptr; + mOptions = nullptr; + mLang = nullptr; + delete mEventHandler; mEventHandler = nullptr; @@ -50,9 +57,6 @@ Title::~Title() delete mText2; mText2 = nullptr; - delete mLang; - mLang = nullptr; - delete mFade; mFade = nullptr; @@ -129,8 +133,6 @@ void Title::init(bool demo, Uint8 subsection) mPostFade = 0; mTicks = 0; mTicksSpeed = 15; - //mText->init(); - //mText2->init(); mFade->init(0x00, 0x00, 0x00); mDemo = demo; diff --git a/source/writer.cpp b/source/writer.cpp index 113504c..ef9cfa7 100644 --- a/source/writer.cpp +++ b/source/writer.cpp @@ -5,11 +5,13 @@ Writer::Writer(Text *text) { mText = text; + init(); } // Destructor Writer::~Writer() { + mText = nullptr; } // Inicializador