diff --git a/data/gfx/balloon1.ani b/data/gfx/balloon1.ani index 3fbe8c1..154a029 100644 --- a/data/gfx/balloon1.ani +++ b/data/gfx/balloon1.ani @@ -33,5 +33,5 @@ frames=36,37,38,39,40,41,42,43,44,45 name=pop speed=5 loop=-1 -frames=48,49,50,51,52,53,54,55,56,57,58,59 +frames=60,61,62,63,64,65,66,67,68,69,70,71 [/animation] \ No newline at end of file diff --git a/data/gfx/balloon2.ani b/data/gfx/balloon2.ani index bbc4d86..93862ad 100644 --- a/data/gfx/balloon2.ani +++ b/data/gfx/balloon2.ani @@ -33,5 +33,5 @@ frames=36,37,38,39,40,41,42,43,44,45 name=pop speed=5 loop=-1 -frames=48,49,50,51,52,53,54,55,56,57,58,59 +frames=60,61,62,63,64,65,66,67,68,69,70,71 [/animation] \ No newline at end of file diff --git a/data/gfx/balloon3.ani b/data/gfx/balloon3.ani index e1fd440..a791602 100644 --- a/data/gfx/balloon3.ani +++ b/data/gfx/balloon3.ani @@ -33,5 +33,5 @@ frames=36,37,38,39,40,41,42,43,44,45 name=pop speed=5 loop=-1 -frames=48,49,50,51,52,53,54,55,56,57,58,59 +frames=60,61,62,63,64,65,66,67,68,69,70,71 [/animation] \ No newline at end of file diff --git a/data/gfx/balloon4.ani b/data/gfx/balloon4.ani index 0e3f214..1db5a21 100644 --- a/data/gfx/balloon4.ani +++ b/data/gfx/balloon4.ani @@ -29,9 +29,16 @@ loop=0 frames=36,37,38,39,40,41,42,43,44,45 [/animation] +[animation] +name=powerball +speed=20 +loop=0 +frames=48 +[/animation] + [animation] name=pop speed=5 loop=-1 -frames=48,49,50,51,52,53,54,55,56,57,58,59 +frames=60,61,62,63,64,65,66,67,68,69,70,71 [/animation] \ No newline at end of file diff --git a/data/gfx/item_clock.ani b/data/gfx/item_clock.ani new file mode 100644 index 0000000..5967f69 --- /dev/null +++ b/data/gfx/item_clock.ani @@ -0,0 +1,9 @@ +frameWidth=16 +frameHeight=16 + +[animation] +name=default +speed=10 +loop=0 +frames=0,1 +[/animation] \ No newline at end of file diff --git a/data/gfx/item_clock.png b/data/gfx/item_clock.png new file mode 100644 index 0000000..415ef88 Binary files /dev/null and b/data/gfx/item_clock.png differ diff --git a/data/gfx/item_coffee.ani b/data/gfx/item_coffee.ani new file mode 100644 index 0000000..5967f69 --- /dev/null +++ b/data/gfx/item_coffee.ani @@ -0,0 +1,9 @@ +frameWidth=16 +frameHeight=16 + +[animation] +name=default +speed=10 +loop=0 +frames=0,1 +[/animation] \ No newline at end of file diff --git a/data/gfx/item_coffee.png b/data/gfx/item_coffee.png new file mode 100644 index 0000000..4888ee6 Binary files /dev/null and b/data/gfx/item_coffee.png differ diff --git a/data/gfx/item_coffee_machine.ani b/data/gfx/item_coffee_machine.ani new file mode 100644 index 0000000..465d9e8 --- /dev/null +++ b/data/gfx/item_coffee_machine.ani @@ -0,0 +1,9 @@ +frameWidth=23 +frameHeight=29 + +[animation] +name=default +speed=10 +loop=0 +frames=0,1,2,3 +[/animation] \ No newline at end of file diff --git a/data/gfx/item_coffee_machine.png b/data/gfx/item_coffee_machine.png new file mode 100644 index 0000000..4c68ecf Binary files /dev/null and b/data/gfx/item_coffee_machine.png differ diff --git a/data/gfx/item_points1_disk.ani b/data/gfx/item_points1_disk.ani new file mode 100644 index 0000000..5967f69 --- /dev/null +++ b/data/gfx/item_points1_disk.ani @@ -0,0 +1,9 @@ +frameWidth=16 +frameHeight=16 + +[animation] +name=default +speed=10 +loop=0 +frames=0,1 +[/animation] \ No newline at end of file diff --git a/data/gfx/item_points1_disk.png b/data/gfx/item_points1_disk.png new file mode 100644 index 0000000..ac974d2 Binary files /dev/null and b/data/gfx/item_points1_disk.png differ diff --git a/data/gfx/item_points2_gavina.ani b/data/gfx/item_points2_gavina.ani new file mode 100644 index 0000000..5967f69 --- /dev/null +++ b/data/gfx/item_points2_gavina.ani @@ -0,0 +1,9 @@ +frameWidth=16 +frameHeight=16 + +[animation] +name=default +speed=10 +loop=0 +frames=0,1 +[/animation] \ No newline at end of file diff --git a/data/gfx/item_points2_gavina.png b/data/gfx/item_points2_gavina.png new file mode 100644 index 0000000..cbf4529 Binary files /dev/null and b/data/gfx/item_points2_gavina.png differ diff --git a/data/gfx/item_points3_pacmar.ani b/data/gfx/item_points3_pacmar.ani new file mode 100644 index 0000000..5967f69 --- /dev/null +++ b/data/gfx/item_points3_pacmar.ani @@ -0,0 +1,9 @@ +frameWidth=16 +frameHeight=16 + +[animation] +name=default +speed=10 +loop=0 +frames=0,1 +[/animation] \ No newline at end of file diff --git a/data/gfx/item_points3_pacmar.png b/data/gfx/item_points3_pacmar.png new file mode 100644 index 0000000..f8e5515 Binary files /dev/null and b/data/gfx/item_points3_pacmar.png differ diff --git a/source/director.cpp b/source/director.cpp index 0fda954..01c5429 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -201,8 +201,20 @@ bool Director::setFileList() asset->add("data/gfx/game_bg.png", t_bitmap); asset->add("data/gfx/game_text.png", t_bitmap); asset->add("data/gfx/intro.png", t_bitmap); - asset->add("data/gfx/items.png", t_bitmap); asset->add("data/gfx/logo.png", t_bitmap); + asset->add("data/gfx/items.png", t_bitmap); + asset->add("data/gfx/item_points1_disk.png", t_bitmap); + asset->add("data/gfx/item_points1_disk.ani", t_data); + asset->add("data/gfx/item_points2_gavina.png", t_bitmap); + asset->add("data/gfx/item_points2_gavina.ani", t_data); + asset->add("data/gfx/item_points3_pacmar.png", t_bitmap); + asset->add("data/gfx/item_points3_pacmar.ani", t_data); + asset->add("data/gfx/item_clock.png", t_bitmap); + asset->add("data/gfx/item_clock.ani", t_data); + asset->add("data/gfx/item_coffee.png", t_bitmap); + asset->add("data/gfx/item_coffee.ani", t_data); + asset->add("data/gfx/item_coffee_machine.png", t_bitmap); + asset->add("data/gfx/item_coffee_machine.ani", t_data); asset->add("data/gfx/title_bg_tile.png", t_bitmap); asset->add("data/gfx/title_coffee.png", t_bitmap); diff --git a/source/game.cpp b/source/game.cpp index 8a4bf10..28093d2 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -2086,7 +2086,7 @@ LTexture *Game::balloonTexture(int kind) else if (kind == 3 || kind == 7) { - return balloon4Texture; + return balloon3Texture; } else if (kind == 4 || kind == 8 || kind == 9) @@ -2214,7 +2214,7 @@ void Game::checkPlayerItemCollision(Player *player) default: break; } - item->erase(); + item->disable(); } } } @@ -2255,12 +2255,12 @@ void Game::checkBulletBalloonCollision() { if (droppeditem != ITEM_COFFEE_MACHINE) { - createItem(mTextureItems, mRenderer, balloon->getPosX(), balloon->getPosY(), droppeditem); + createItem(balloon->getPosX(), balloon->getPosY(), droppeditem); JA_PlaySound(mSoundItemDrop); } else { - createItem(mTextureItems, mRenderer, players[index]->getPosX(), 0, droppeditem); + createItem(players.at(index)->getPosX(), 0, droppeditem); mCoffeeMachineEnabled = true; } } @@ -2327,7 +2327,7 @@ void Game::updateItems() for (auto item : items) { item->update(); - if (item->floorCollision()) + if (item->isOnFloor()) { JA_PlaySound(mSoundCollision); mEffect.shake = true; @@ -2413,12 +2413,28 @@ Uint8 Game::dropItem() } // Crea un objeto item -void Game::createItem(LTexture *texture, SDL_Renderer *renderer, Uint8 type, float x, float y) +void Game::createItem(Uint8 type, float x, float y) { - Item *i = new Item(texture, renderer, type, x, y); + Item *i = new Item(mRenderer, mAsset, type, x, y); items.push_back(i); } +// Vacia el vector de items +void Game::freeItems() +{ + if (items.empty() == false) + { + for (int i = items.size() - 1; i >= 0; --i) + { + if (items.at(i)->isEnabled() == false) + { + delete items.at(i); + items.erase(items.begin() + i); + } + } + } +} + // Crea un objeto SmartSprite para mostrar la puntuación al coger un objeto void Game::createItemScoreSprite(int x, int y, SmartSprite *sprite) { @@ -2691,6 +2707,7 @@ void Game::updatePlayField() // Vacia los vectores freeBullets(); freeBalloons(); + freeItems(); } // Actualiza el fondo @@ -2787,6 +2804,8 @@ void Game::renderPlayField() } renderFlashEffect(); + + mText->write(0, 0, std::to_string(balloons.size())); } // Gestiona el nivel de amenaza @@ -2825,45 +2844,45 @@ void Game::checkGameInput() const int index = 0; if (mDemo.dataFile[mDemo.counter].left == 1) { - players[index]->setInput(INPUT_LEFT); + players.at(index)->setInput(INPUT_LEFT); } if (mDemo.dataFile[mDemo.counter].right == 1) { - players[index]->setInput(INPUT_RIGHT); + players.at(index)->setInput(INPUT_RIGHT); } if (mDemo.dataFile[mDemo.counter].noInput == 1) { - players[index]->setInput(INPUT_NULL); + players.at(index)->setInput(INPUT_NULL); } if (mDemo.dataFile[mDemo.counter].fire == 1) { - if (players[index]->canFire()) + if (players.at(index)->canFire()) { - players[index]->setInput(INPUT_BUTTON_2); - createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_UP, players[index]->isPowerUp(), index); - players[index]->setFireCooldown(10); + players.at(index)->setInput(INPUT_BUTTON_2); + createBullet(players.at(index)->getPosX() + (players.at(index)->getWidth() / 2) - 4, players.at(index)->getPosY() + (players.at(index)->getHeight() / 2), BULLET_UP, players.at(index)->isPowerUp(), index); + players.at(index)->setFireCooldown(10); } } if (mDemo.dataFile[mDemo.counter].fireLeft == 1) { - if (players[index]->canFire()) + if (players.at(index)->canFire()) { - players[index]->setInput(INPUT_BUTTON_1); - createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_UP, players[index]->isPowerUp(), index); - players[index]->setFireCooldown(10); + players.at(index)->setInput(INPUT_BUTTON_1); + createBullet(players.at(index)->getPosX() + (players.at(index)->getWidth() / 2) - 4, players.at(index)->getPosY() + (players.at(index)->getHeight() / 2), BULLET_UP, players.at(index)->isPowerUp(), index); + players.at(index)->setFireCooldown(10); } } if (mDemo.dataFile[mDemo.counter].fireRight == 1) { - if (players[index]->canFire()) + if (players.at(index)->canFire()) { - players[index]->setInput(INPUT_BUTTON_3); - createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_UP, players[index]->isPowerUp(), index); - players[index]->setFireCooldown(10); + players.at(index)->setInput(INPUT_BUTTON_3); + createBullet(players.at(index)->getPosX() + (players.at(index)->getWidth() / 2) - 4, players.at(index)->getPosY() + (players.at(index)->getHeight() / 2), BULLET_UP, players.at(index)->isPowerUp(), index); + players.at(index)->setFireCooldown(10); } } diff --git a/source/game.h b/source/game.h index 17e853e..f243fbf 100644 --- a/source/game.h +++ b/source/game.h @@ -384,7 +384,10 @@ private: Uint8 dropItem(); // Crea un objeto item - void createItem(LTexture *texture, SDL_Renderer *renderer, Uint8 type, float x, float y); + void createItem(Uint8 type, float x, float y); + + // Vacia el vector de items + void freeItems(); // Crea un objeto SmartSprite void createItemScoreSprite(int x, int y, SmartSprite *sprite); diff --git a/source/instructions.cpp b/source/instructions.cpp index d7b848d..32b8d9d 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -13,7 +13,7 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *mAsset // Reserva memoria para los punteros mEventHandler = new SDL_Event(); - mItemTexture = new LTexture(mRenderer,mAsset->get("items.png")); + mItemTexture = new LTexture(mRenderer, mAsset->get("items.png")); mSprite = new Sprite(0, 0, GAME_WIDTH, GAME_HEIGHT, mItemTexture, mRenderer); mText = new Text(mAsset->get("smb2.png"), mAsset->get("smb2.txt"), mRenderer); @@ -28,26 +28,14 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *mAsset // Destructor Instructions::~Instructions() { - mRenderer = nullptr; - mScreen = nullptr; - mAsset = nullptr; - mLang = nullptr; - mItemTexture->unload(); delete mItemTexture; - mItemTexture = nullptr; delete mSprite; - mSprite = nullptr; - delete mEventHandler; - mEventHandler = nullptr; - delete mText; - mText = nullptr; SDL_DestroyTexture(mBackbuffer); - mBackbuffer = nullptr; } // Inicializa las variables necesarias para la sección 'Instructions' @@ -87,7 +75,9 @@ void Instructions::run(Uint8 mode) mSection.subsection = TITLE_SECTION_1; } else + { mManualQuit = true; + } } } @@ -97,9 +87,8 @@ void Instructions::run(Uint8 mode) // Actualiza el contador de ticks mTicks = SDL_GetTicks(); - // Modo automático if (mode == INSTRUCTIONS_MODE_AUTO) - { + { // Modo automático mCounter++; if (mCounter == INSTRUCTIONS_COUNTER) @@ -108,9 +97,8 @@ void Instructions::run(Uint8 mode) mSection.subsection = TITLE_SECTION_1; } } - // Modo manual else - { + { // Modo manual ++mCounter %= 60000; if (mManualQuit) @@ -153,7 +141,9 @@ void Instructions::run(Uint8 mode) mText->writeShadowed(84, 156, mLang->getText(21), shdwTxtColor); if ((mode == INSTRUCTIONS_MODE_MANUAL) && (mCounter % 50 > 14)) + { mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, GAME_HEIGHT - 12, mLang->getText(22), 1, orangeColor, 1, shdwTxtColor); + } // Disquito mSprite->setPos(destRect1); @@ -201,9 +191,13 @@ void Instructions::run(Uint8 mode) // Establece la ventana del backbuffer if (mode == INSTRUCTIONS_MODE_AUTO) + { window.y = std::max(8, GAME_HEIGHT - mCounter + 100); + } else + { window.y = 0; + } // Copia el backbuffer al renderizador SDL_RenderCopy(mRenderer, mBackbuffer, nullptr, &window); diff --git a/source/item.cpp b/source/item.cpp index 52f08b9..992a46d 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -2,120 +2,107 @@ #include "item.h" // Constructor -Item::Item(LTexture *texture, SDL_Renderer *renderer, Uint8 type, float x, float y) +Item::Item(SDL_Renderer *renderer, Asset *asset, Uint8 type, float x, float y) { - mSprite = new AnimatedSprite(texture, renderer); - - mClass = type; - mEnabled = true; - mTimeToLive = 600; - mPosX = x; - mPosY = y; - mWidth = 16; - mHeight = 16; - mVelX = -1.0f + ((rand() % 5) * 0.5f); - mVelY = -4.0f; - mAccelX = 0.0f; - mAccelY = 0.2f; - mFloorCollision = false; - mCollider.r = mWidth / 2; - shiftColliders(); - - mSprite->setAnimationFrames(0, 0, 0, 48, mWidth, mHeight); - mSprite->setAnimationFrames(0, 1, 0, 64, mWidth, mHeight); - mSprite->setCurrentFrame(0); - mSprite->setAnimationCounter(0); - mSprite->setAnimationSpeed(0, 10); - mSprite->setAnimationLoop(0, true); - mSprite->setSpriteClip(mSprite->getAnimationClip(0, 0)); - mSprite->setPosX(mPosX); - mSprite->setPosY(mPosY); - + std::string filePNG; + std::string fileANI; switch (type) { - case NO_KIND: - mEnabled = false; - mTimeToLive = 0; - mPosX = 0; - mPosY = 0; - mWidth = 0; - mHeight = 0; - mVelX = 0; - mVelY = 0; - break; - case ITEM_POINTS_1_DISK: - mSprite->setAnimationFrames(0, 0, 16 * 0, 16 * 0, mWidth, mHeight); - mSprite->setAnimationFrames(0, 1, 16 * 0, 16 * 1, mWidth, mHeight); + filePNG = asset->get("item_points1_disk.png"); + fileANI = asset->get("item_points1_disk.ani"); break; case ITEM_POINTS_2_GAVINA: - mSprite->setAnimationFrames(0, 0, 16 * 1, 16 * 0, mWidth, mHeight); - mSprite->setAnimationFrames(0, 1, 16 * 1, 16 * 1, mWidth, mHeight); + filePNG = asset->get("item_points2_gavina.png"); + fileANI = asset->get("item_points2_gavina.ani"); break; case ITEM_POINTS_3_PACMAR: - mSprite->setAnimationFrames(0, 0, 16 * 2, 16 * 0, mWidth, mHeight); - mSprite->setAnimationFrames(0, 1, 16 * 2, 16 * 1, mWidth, mHeight); + filePNG = asset->get("item_points3_pacmar.png"); + fileANI = asset->get("item_points3_pacmar.ani"); break; case ITEM_CLOCK: - mSprite->setAnimationFrames(0, 0, 16 * 3, 16 * 0, mWidth, mHeight); - mSprite->setAnimationFrames(0, 1, 16 * 3, 16 * 1, mWidth, mHeight); + filePNG = asset->get("item_clock.png"); + fileANI = asset->get("item_clock.ani"); break; case ITEM_COFFEE: - mSprite->setAnimationFrames(0, 0, 16 * 5, 16 * 0, mWidth, mHeight); - mSprite->setAnimationFrames(0, 1, 16 * 5, 16 * 1, mWidth, mHeight); + filePNG = asset->get("item_coffee.png"); + fileANI = asset->get("item_coffee.ani"); break; case ITEM_COFFEE_MACHINE: - mWidth = 32; - mHeight = 32; - mPosX = (((int)x + (PLAY_AREA_WIDTH / 2)) % (PLAY_AREA_WIDTH - mWidth - 5)) + 2; - mPosY = PLAY_AREA_TOP - mHeight; - mVelX = 0.0f; - mVelY = -0.1f; - mAccelY = 0.1f; - 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->setPosX(mPosX); - mSprite->setPosY(mPosY); - mCollider.r = 10; - shiftColliders(); + filePNG = asset->get("item_coffee_machine.png"); + fileANI = asset->get("item_coffee_machine.ani"); break; default: break; } + + texture = new LTexture(renderer, filePNG); + sprite = new AnimatedSprite(texture, renderer, fileANI); + + this->type = type; + enabled = true; + timeToLive = 600; + accelX = 0.0f; + floorCollision = false; + + if (type == ITEM_COFFEE_MACHINE) + { + width = 32; + height = 32; + posX = (((int)x + (PLAY_AREA_WIDTH / 2)) % (PLAY_AREA_WIDTH - width - 5)) + 2; + posY = PLAY_AREA_TOP - height; + velX = 0.0f; + velY = -0.1f; + accelY = 0.1f; + collider.r = 10; + } + else + { + width = 16; + height = 16; + posX = x; + posY = y; + velX = -1.0f + ((rand() % 5) * 0.5f); + velY = -4.0f; + accelY = 0.2f; + collider.r = width / 2; + } + + sprite->setPosX(posX); + sprite->setPosY(posY); + shiftColliders(); } // Destructor Item::~Item() { - delete mSprite; - mSprite = nullptr; + delete texture; + delete sprite; } // Centra el objeto en la posición X void Item::allignTo(int x) { - mPosX = float(x - (mWidth / 2)); + posX = float(x - (width / 2)); - if (mPosX < PLAY_AREA_LEFT) + if (posX < PLAY_AREA_LEFT) { - mPosX = PLAY_AREA_LEFT + 1; + posX = PLAY_AREA_LEFT + 1; } - else if ((mPosX + mWidth) > PLAY_AREA_RIGHT) + else if ((posX + width) > PLAY_AREA_RIGHT) { - mPosX = float(PLAY_AREA_RIGHT - mWidth - 1); + posX = float(PLAY_AREA_RIGHT - width - 1); } // Posición X,Y del sprite - mSprite->setPosX(int(mPosX)); - mSprite->setPosY(int(mPosY)); + sprite->setPosX(int(posX)); + sprite->setPosY(int(posY)); // Alinea el circulo de colisión con el objeto shiftColliders(); @@ -124,15 +111,15 @@ void Item::allignTo(int x) // Pinta el objeto en la pantalla void Item::render() { - if (mEnabled) + if (enabled) { - if (mTimeToLive > 200) + if (timeToLive > 200) { - mSprite->render(); + sprite->render(); } - else if (mTimeToLive % 20 > 10) + else if (timeToLive % 20 > 10) { - mSprite->render(); + sprite->render(); } } } @@ -140,71 +127,73 @@ void Item::render() // Actualiza la posición y estados del objeto void Item::move() { - mFloorCollision = false; + floorCollision = false; // Calcula la nueva posición - mPosX += mVelX; - mPosY += mVelY; + posX += velX; + posY += velY; // Aplica las aceleraciones a la velocidad - mVelX += mAccelX; - mVelY += mAccelY; + velX += accelX; + velY += accelY; // Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido - if ((mPosX < PLAY_AREA_LEFT) || (mPosX + mWidth > PLAY_AREA_RIGHT)) + if ((posX < PLAY_AREA_LEFT) || (posX + width > PLAY_AREA_RIGHT)) { // Corregir posición - mPosX -= mVelX; + posX -= velX; // Invertir sentido - mVelX = -mVelX; + velX = -velX; } // Si se sale por arriba rebota (excepto la maquina de café) - if ((mPosY < PLAY_AREA_TOP) && !(mClass == ITEM_COFFEE_MACHINE)) + if ((posY < PLAY_AREA_TOP) && !(type == ITEM_COFFEE_MACHINE)) { // Corrige - mPosY = PLAY_AREA_TOP; + posY = PLAY_AREA_TOP; // Invierte el sentido - mVelY = -mVelY; + velY = -velY; } // Si el objeto se sale por la parte inferior - if (mPosY + mHeight > PLAY_AREA_BOTTOM) + if (posY + height > PLAY_AREA_BOTTOM) { // Corrige - mPosY -= mVelY; + posY -= velY; // Detiene el objeto - mVelY = 0; - mVelX = 0; - mAccelX = 0; - mAccelY = 0; - mPosY = PLAY_AREA_BOTTOM - mHeight; - if (mClass == ITEM_COFFEE_MACHINE) - mFloorCollision = true; + velY = 0; + velX = 0; + accelX = 0; + accelY = 0; + posY = PLAY_AREA_BOTTOM - height; + if (type == ITEM_COFFEE_MACHINE) + { + floorCollision = true; + } } // Actualiza la posición del sprite - mSprite->setPosX(int(mPosX)); - mSprite->setPosY(int(mPosY)); + sprite->setPosX(int(posX)); + sprite->setPosY(int(posY)); + shiftColliders(); } // Pone a cero todos los valores del objeto -void Item::erase() +void Item::disable() { - // init(NO_KIND, 0, 0, nullptr, nullptr); + enabled = false; } // Actualiza el objeto a su posicion, animación y controla los contadores void Item::update() { - if (mEnabled) + if (enabled) { move(); - shiftColliders(); - mSprite->animate(); + sprite->animate(); updateTimeToLive(); checkTimeToLive(); } @@ -213,76 +202,70 @@ void Item::update() // Actualiza el contador void Item::updateTimeToLive() { - if (mTimeToLive > 0) + if (timeToLive > 0) { - mTimeToLive--; + timeToLive--; } } // Comprueba si el objeto sigue vivo void Item::checkTimeToLive() { - if (mTimeToLive == 0) - erase(); + if (timeToLive == 0) + disable(); } // Obtiene del valor de la variable float Item::getPosX() { - return mPosX; + return posX; } // Obtiene del valor de la variable float Item::getPosY() { - return mPosY; + return posY; } // Obtiene del valor de la variable int Item::getWidth() { - return mWidth; + return width; } // Obtiene del valor de la variable int Item::getHeight() { - return mHeight; + return height; } // Obtiene del valor de la variable int Item::getClass() { - return mClass; + return type; } // Obtiene el valor de la variable bool Item::isEnabled() { - return mEnabled; -} - -// Establece el valor de la variable -void Item::setEnabled(bool value) -{ - mEnabled = value; + return enabled; } // Obtiene el circulo de colisión circle_t &Item::getCollider() { - return mCollider; + return collider; } // Alinea el circulo de colisión con la posición del objeto void Item::shiftColliders() { - mCollider.x = int(mPosX + (mWidth / 2)); - mCollider.y = int(mPosY + (mHeight / 2)); + collider.x = int(posX + (width / 2)); + collider.y = int(posY + (height / 2)); } // Informa si el objeto ha colisionado con el suelo -bool Item::floorCollision() +bool Item::isOnFloor() { - return mFloorCollision; + return floorCollision; } \ No newline at end of file diff --git a/source/item.h b/source/item.h index fda6bbb..87e9273 100644 --- a/source/item.h +++ b/source/item.h @@ -20,30 +20,35 @@ class Item { private: - float mPosX; // Posición X del objeto - float mPosY; // Posición Y del objeto - Uint8 mWidth; // Ancho del objeto - Uint8 mHeight; // Alto del objeto - float mVelX; // Velocidad en el eje X - float mVelY; // Velocidad en el eje Y - float mAccelX; // Aceleración en el eje X - float mAccelY; // Aceleración en el eje Y - bool mFloorCollision; // Indica si el objeto colisiona con el suelo + // Objetos + Asset *asset; // Objeto que gestiona todos los ficheros de recursos + AnimatedSprite *sprite; // Sprite con los graficos del objeto + LTexture *texture; // Objeto con los graficos del item - AnimatedSprite *mSprite; // Sprite con los graficos del objeto - - Uint8 mClass; // Especifica el tipo de objeto que es - bool mEnabled; // Especifica si el objeto está habilitado - circle_t mCollider; // Circulo de colisión del objeto + // Variables + float posX; // Posición X del objeto + float posY; // Posición Y del objeto + Uint8 width; // Ancho del objeto + Uint8 height; // Alto del objeto + float velX; // Velocidad en el eje X + float velY; // Velocidad en el eje Y + float accelX; // Aceleración en el eje X + float accelY; // Aceleración en el eje Y + bool floorCollision; // Indica si el objeto colisiona con el suelo + Uint8 type; // Especifica el tipo de objeto que es + bool enabled; // Especifica si el objeto está habilitado + circle_t collider; // Circulo de colisión del objeto // Alinea el circulo de colisión con la posición del objeto void shiftColliders(); + // Actualiza la posición y estados del objeto + void move(); public: - Uint16 mTimeToLive; // Temporizador con el tiempo que el objeto está presente + Uint16 timeToLive; // Temporizador con el tiempo que el objeto está presente // Constructor - Item(LTexture *texture, SDL_Renderer *renderer, Uint8 type, float x, float y); + Item(SDL_Renderer *renderer, Asset *asset, Uint8 type, float x, float y); // Destructor ~Item(); @@ -54,11 +59,9 @@ public: // Pinta el objeto en la pantalla void render(); - // Actualiza la posición y estados del objeto - void move(); // Pone a cero todos los valores del objeto - void erase(); + void disable(); // Actualiza al objeto a su posicion, animación y controla los contadores void update(); @@ -87,14 +90,11 @@ public: // Obtiene el valor de la variable bool isEnabled(); - // Establece el valor de la variable - void setEnabled(bool value); - // Obtiene el circulo de colisión circle_t &getCollider(); // Informa si el objeto ha colisionado con el suelo - bool floorCollision(); + bool isOnFloor(); }; #endif