From 5bb5022ebf18237703f0c13c68f955d420d77815 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 25 Aug 2021 17:59:40 +0200 Subject: [PATCH] fix bullet owner bug --- source/bullet.cpp | 2 +- source/director.cpp | 8 ++++---- source/game.cpp | 6 +++--- source/input.cpp | 2 +- source/input.h | 6 ++++-- source/player.cpp | 10 +++++----- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/source/bullet.cpp b/source/bullet.cpp index 7e1ee36..f063556 100644 --- a/source/bullet.cpp +++ b/source/bullet.cpp @@ -34,7 +34,7 @@ void Bullet::init(int x, int y, int kind, bool poweredUp, int owner, LTexture *t mKind = kind; // Identificador del dueño del objeto - mOwner = -1; + mOwner = owner; // Textura con los gráficos del objeto mSprite->setTexture(texture); diff --git a/source/director.cpp b/source/director.cpp index fa8c229..4da74f2 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -96,8 +96,8 @@ void Director::init() mInput1->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_W); mInput1->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_E); #endif - mInput1->bindKey(INPUT_BUTTON_4, SDL_SCANCODE_ESCAPE); // PAUSE - mInput1->bindKey(INPUT_BUTTON_5, SDL_SCANCODE_ESCAPE); // ESCAPE + mInput1->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); // PAUSE + mInput1->bindKey(INPUT_BUTTON_ESCAPE, SDL_SCANCODE_ESCAPE); // ESCAPE mInput2->bindGameController(INPUT_UP, SDL_CONTROLLER_BUTTON_DPAD_UP); mInput2->bindGameController(INPUT_DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN); @@ -108,8 +108,8 @@ void Director::init() mInput2->bindGameController(INPUT_BUTTON_1, SDL_CONTROLLER_BUTTON_X); mInput2->bindGameController(INPUT_BUTTON_2, SDL_CONTROLLER_BUTTON_Y); mInput2->bindGameController(INPUT_BUTTON_3, SDL_CONTROLLER_BUTTON_B); - mInput2->bindGameController(INPUT_BUTTON_4, SDL_CONTROLLER_BUTTON_GUIDE); // PAUSE - mInput2->bindGameController(INPUT_BUTTON_5, SDL_CONTROLLER_BUTTON_GUIDE); // ESCAPE + mInput2->bindGameController(INPUT_BUTTON_PAUSE, SDL_CONTROLLER_BUTTON_GUIDE); // PAUSE + mInput2->bindGameController(INPUT_BUTTON_ESCAPE, SDL_CONTROLLER_BUTTON_GUIDE); // ESCAPE } // Inicializa JailAudio diff --git a/source/game.cpp b/source/game.cpp index 470bf54..1c03e63 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -2107,7 +2107,7 @@ void Game::checkBulletBalloonCollision() if (checkCollision(mBalloon[i]->getCollider(), mBullet[j]->getCollider())) { // Otorga los puntos correspondientes al globo al jugador que disparó la bala - const int index = mBullet[j]->getOwner(); + int index = mBullet[j]->getOwner(); mPlayer[index]->incScoreMultiplier(); mPlayer[index]->addScore(Uint32(mBalloon[i]->getScore() * mPlayer[index]->getScoreMultiplier())); //setScore(mPlayer[index]->getScore()); @@ -2727,7 +2727,7 @@ void Game::checkGameInput() } // Comprueba el input de pausa - if (mInput[0]->checkInput(INPUT_PAUSE, REPEAT_FALSE)) + if (mInput[0]->checkInput(INPUT_BUTTON_PAUSE, REPEAT_FALSE)) mSection.name = PROG_SECTION_TITLE; // Incrementa el contador de la demo @@ -2811,7 +2811,7 @@ void Game::checkGameInput() } // Comprueba el input de pausa - if (mInput[i]->checkInput(INPUT_CANCEL, REPEAT_FALSE)) + if (mInput[i]->checkInput(INPUT_BUTTON_PAUSE, REPEAT_FALSE)) { mSection.subsection = GAME_SECTION_PAUSE; diff --git a/source/input.cpp b/source/input.cpp index fd3a070..1550d51 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -6,7 +6,7 @@ Input::Input(int source) { // Inicializa las variables - for (int i = 0; i < 15; i++) + for (int i = 0; i < 17; i++) { mKeyBindings[i].scancode = 0; mKeyBindings[i].active = false; diff --git a/source/input.h b/source/input.h index 822680e..8609313 100644 --- a/source/input.h +++ b/source/input.h @@ -19,6 +19,8 @@ #define INPUT_BUTTON_6 12 #define INPUT_BUTTON_7 13 #define INPUT_BUTTON_8 14 +#define INPUT_BUTTON_PAUSE 15 +#define INPUT_BUTTON_ESCAPE 16 #define REPEAT_TRUE true #define REPEAT_FALSE false @@ -35,14 +37,14 @@ private: Uint8 scancode; // Scancode asociado bool active; // Indica si está activo }; - keyBindings_t mKeyBindings[15]; // Vector con las teclas asociadas a los inputs predefinidos + keyBindings_t mKeyBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos struct GameControllerBindings_t { SDL_GameControllerButton button; // GameControllerButton asociado bool active; // Indica si está activo }; - GameControllerBindings_t mGameControllerBindings[15]; // Vector con las teclas asociadas a los inputs predefinidos + GameControllerBindings_t mGameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos SDL_GameController *mGameController; // Manejador para el mando //SDL_Haptic *mControllerHaptic; // Manejador para el mando con vibración diff --git a/source/player.cpp b/source/player.cpp index e8f5642..d66784e 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -65,7 +65,7 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody, mScore = 0; // Establece el multiplicador de puntos inicial - mScoreMultiplier = 1.0f; + mScoreMultiplier = 2.0f; // Inicia el contador para la cadencia de disparo mCooldown = 10; @@ -593,18 +593,18 @@ void Player::setScoreMultiplier(float value) void Player::incScoreMultiplier() { if (mScoreMultiplier < 5.0f) - { mScoreMultiplier += 0.1f; - } + else + mScoreMultiplier = 5.0f; } // Decrementa el valor de la variable hasta un mínimo void Player::decScoreMultiplier() { if (mScoreMultiplier > 1.0f) - { mScoreMultiplier -= 0.1f; - } + else + mScoreMultiplier = 1.0f; } // Obtiene el valor de la variable