From 70324570c865781f53fe003723f4d50d85e243db Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 27 Aug 2021 12:32:34 +0200 Subject: [PATCH] bug hunting coffee machine on windows --- source/game.cpp | 20 ++++++++++++------ source/item.cpp | 52 ++++++++++++++++++++++++++--------------------- source/player.cpp | 4 ++-- source/utils.h | 6 +++--- 4 files changed, 48 insertions(+), 34 deletions(-) diff --git a/source/game.cpp b/source/game.cpp index d56a841..95bab9e 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -1623,7 +1623,7 @@ void Game::renderScoreBoard() } // STAGE - mTextScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset1-1, mTextStrings[57] + std::to_string(mStage[mCurrentStage].number)); + mTextScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset1 - 1, mTextStrings[57] + std::to_string(mStage[mCurrentStage].number)); // POWER mSpritePowerMeter->setSpriteClip(256, 184, 40, 8); @@ -1633,7 +1633,7 @@ void Game::renderScoreBoard() mSpritePowerMeter->render(); // HI-SCORE - mTextScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset3+1, mTextStrings[56] + updateScoreText(mHiScore)); + mTextScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset3 + 1, mTextStrings[56] + updateScoreText(mHiScore)); } // Actualiza las variables del jugador @@ -2110,21 +2110,18 @@ void Game::checkPlayerItemCollision(int index) { case ITEM_POINTS_1_DISK: mPlayer[index]->addScore(1000); - //setScore(mPlayer[index]->getScore()); updateHiScore(); createItemScoreSprite(mItem[i]->getPosX() + (mItem[i]->getWidth() / 2) - (m1000Bitmap->getWidth() / 2), mPlayer[index]->getPosY(), m1000Bitmap); JA_PlaySound(mSoundItemPickup); break; case ITEM_POINTS_2_GAVINA: mPlayer[index]->addScore(2500); - //setScore(mPlayer[index]->getScore()); updateHiScore(); createItemScoreSprite(mItem[i]->getPosX() + (mItem[i]->getWidth() / 2) - (m2500Bitmap->getWidth() / 2), mPlayer[index]->getPosY(), m2500Bitmap); JA_PlaySound(mSoundItemPickup); break; case ITEM_POINTS_3_PACMAR: mPlayer[index]->addScore(5000); - //setScore(mPlayer[index]->getScore()); updateHiScore(); createItemScoreSprite(mItem[i]->getPosX() + (mItem[i]->getWidth() / 2) - (m5000Bitmap->getWidth() / 2), mPlayer[index]->getPosY(), m5000Bitmap); JA_PlaySound(mSoundItemPickup); @@ -2141,6 +2138,12 @@ void Game::checkPlayerItemCollision(int index) mPlayer[index]->setPowerUp(true); JA_PlaySound(mSoundItemPickup); mCoffeeMachineEnabled = false; + { + printf("-collision-\n"); + printf("x\t%f\n", mItem[i]->getPosX()); + printf("y\t%f\n", mItem[i]->getPosY()); + printf("---\n"); + } break; default: @@ -2181,11 +2184,16 @@ void Game::checkBulletBalloonCollision() const Uint8 droppeditem = dropItem(); if ((droppeditem != NO_KIND) && !(mDemo.enabled) && !(mDemo.recording)) { - createItem(mBalloon[i]->getPosX(), mBalloon[i]->getPosY(), droppeditem); if (droppeditem != ITEM_COFFEE_MACHINE) + { + createItem(mBalloon[i]->getPosX(), mBalloon[i]->getPosY(), droppeditem); JA_PlaySound(mSoundItemDrop); + } else + { + createItem(mPlayer[index]->getPosX(), 0, droppeditem); mCoffeeMachineEnabled = true; + } } break; } diff --git a/source/item.cpp b/source/item.cpp index 3e9b2e3..473ae72 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -43,6 +43,8 @@ void Item::init(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer * mSprite->setAnimationSpeed(0, 10); mSprite->setAnimationLoop(0, true); mSprite->setSpriteClip(mSprite->getAnimationClip(0, 0)); + mSprite->setPosX(mPosX); + mSprite->setPosY(mPosY); switch (value) { @@ -86,15 +88,19 @@ void Item::init(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer * mWidth = 32; mHeight = 32; //mPosX = (rand() % (PLAY_AREA_WIDTH - mWidth - 3)) + 3; - mPosX = (((int)x + (PLAY_AREA_WIDTH / 2)) % (PLAY_AREA_WIDTH - mWidth)); + mPosX = (((int)x + (PLAY_AREA_WIDTH / 2)) % (PLAY_AREA_WIDTH - mWidth - 5)) + 2; mPosY = PLAY_AREA_TOP - mHeight; mVelX = 0.0f; - mVelY = -2.0f; + mVelY = -0.1f; + mAccelY = 0.15f; mSprite->setAnimationNumFrames(0, 4); mSprite->setAnimationFrames(0, 0, 32 * 0, 16 * 2, mWidth, mHeight); mSprite->setAnimationFrames(0, 1, 32 * 1, 16 * 2, mWidth, mHeight); mSprite->setAnimationFrames(0, 2, 32 * 2, 16 * 2, mWidth, mHeight); mSprite->setAnimationFrames(0, 3, 32 * 3, 16 * 2, mWidth, mHeight); + //mSprite->setSpriteClip(mSprite->getAnimationClip(0, 0)); + mSprite->setPosX(mPosX); + mSprite->setPosY(mPosY); mCollider.r = mWidth / 2; shiftColliders(); break; @@ -105,12 +111,12 @@ void Item::init(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer * if (mClass == ITEM_COFFEE_MACHINE) { - printf("---\n"); + printf("-creation-\n"); printf("x\t%f\n", mPosX); printf("y\t%f\n", mPosY); printf("ax\t%f\n", mAccelX); printf("ay\t%f\n", mAccelY); - printf("r\t%f\n", mCollider.r); + printf("r\t%i\n", mCollider.r); printf("---\n"); } } @@ -156,15 +162,15 @@ void Item::render() // Actualiza la posición y estados del objeto void Item::move() { - if (mClass == ITEM_COFFEE_MACHINE) - { - printf("---\n"); - printf("x\t%f\n", mPosX); - printf("y\t%f\n", mPosY); - printf("ax\t%f\n", mAccelX); - printf("ay\t%f\n", mAccelY); - printf("---\n"); - } + //if (mClass == ITEM_COFFEE_MACHINE) + //{ + // printf("-move-\n"); + // printf("x\t%f\n", mPosX); + // printf("y\t%f\n", mPosY); + // printf("ax\t%f\n", mAccelX); + // printf("ay\t%f\n", mAccelY); + // printf("---\n"); + //} mStatus = 0; @@ -187,14 +193,14 @@ void Item::move() } // Si se sale por arriba - if (mPosY < PLAY_AREA_TOP) - { - // Corrige - mPosY = PLAY_AREA_TOP; - - // Invierte el sentido - mVelY = -mVelY; - } + //if (mPosY < PLAY_AREA_TOP) + //{ + // // 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) @@ -305,6 +311,6 @@ circle_t &Item::getCollider() // Alinea el circulo de colisión con la posición del objeto void Item::shiftColliders() { - mCollider.x = Uint16(mPosX + mCollider.r); - mCollider.y = Uint16(mPosY + mCollider.r); + mCollider.x = int(mPosX + mCollider.r); + mCollider.y = int(mPosY + mCollider.r); } \ No newline at end of file diff --git a/source/player.cpp b/source/player.cpp index d66784e..1db63aa 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -736,8 +736,8 @@ circle_t &Player::getCollider() // Actualiza el circulo de colisión a la posición del jugador void Player::shiftColliders() { - mCollider.x = Uint16(mPosX + (mWidth / 2)); - mCollider.y = mPosY + (mHeight / 2); + mCollider.x = int(mPosX + (mWidth / 2)); + mCollider.y = int(mPosY + (mHeight / 2)); } // Obtiene el puntero a la textura con los gráficos de la animación de morir diff --git a/source/utils.h b/source/utils.h index 2d9d7e2..f23a4a9 100644 --- a/source/utils.h +++ b/source/utils.h @@ -8,9 +8,9 @@ // Estructura para definir un circulo struct circle_t { - Uint16 x; - Uint16 y; - Uint8 r; + int x; + int y; + int r; }; // Estructura para definir un color