Trabajando en los globos
This commit is contained in:
135
source/game.cpp
135
source/game.cpp
@@ -39,7 +39,10 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
|
||||
players.push_back(player2);
|
||||
}
|
||||
|
||||
mTextureBalloon = new LTexture(mRenderer, mAsset->get("balloon.png"));
|
||||
balloon1Texture = new LTexture(mRenderer, mAsset->get("balloon1.png"));
|
||||
balloon2Texture = new LTexture(mRenderer, mAsset->get("balloon2.png"));
|
||||
balloon3Texture = new LTexture(mRenderer, mAsset->get("balloon3.png"));
|
||||
balloon4Texture = new LTexture(mRenderer, mAsset->get("balloon4.png"));
|
||||
mTextureBullet = new LTexture(mRenderer, mAsset->get("bullet.png"));
|
||||
mTextureGameBG = new LTexture(mRenderer, mAsset->get("game_bg.png"));
|
||||
mTextureGameText = new LTexture(mRenderer, mAsset->get("game_text.png"));
|
||||
@@ -112,9 +115,17 @@ Game::~Game()
|
||||
delete smartSprite;
|
||||
};
|
||||
|
||||
mTextureBalloon->unload();
|
||||
delete mTextureBalloon;
|
||||
mTextureBalloon = nullptr;
|
||||
balloon1Texture->unload();
|
||||
delete balloon1Texture;
|
||||
|
||||
balloon2Texture->unload();
|
||||
delete balloon2Texture;
|
||||
|
||||
balloon3Texture->unload();
|
||||
delete balloon3Texture;
|
||||
|
||||
balloon4Texture->unload();
|
||||
delete balloon4Texture;
|
||||
|
||||
mTextureBullet->unload();
|
||||
delete mTextureBullet;
|
||||
@@ -1386,15 +1397,16 @@ void Game::deployEnemyFormation()
|
||||
if (mDebug.enabled)
|
||||
set = mDebug.enemySet;
|
||||
|
||||
Uint8 numEnemies = mStage[mCurrentStage].enemyPool->set[set]->numberOfEnemies;
|
||||
for (int i = 0; i < numEnemies; i++)
|
||||
const Uint8 numEnemies = mStage[mCurrentStage].enemyPool->set[set]->numberOfEnemies;
|
||||
for (int i = 0; i < numEnemies; ++i)
|
||||
{
|
||||
createNewBalloon(mStage[mCurrentStage].enemyPool->set[set]->init[i].x,
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].y,
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].kind,
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].velX,
|
||||
mEnemySpeed,
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].creationCounter,
|
||||
mTextureBalloon);
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].creationCounter);
|
||||
}
|
||||
|
||||
mEnemyDeployCounter = 300;
|
||||
}
|
||||
@@ -1754,11 +1766,12 @@ void Game::renderBalloons()
|
||||
}
|
||||
|
||||
// Crea un globo nuevo en el vector de globos
|
||||
Uint8 Game::createNewBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture)
|
||||
Uint8 Game::createNewBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 creationtimer)
|
||||
{
|
||||
// Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, texture, mRenderer);
|
||||
// balloons.push_back(b);
|
||||
// return (Uint8)(balloons.size() - 1);
|
||||
const std::string file = balloonAnimation(kind);
|
||||
Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, balloonTexture(kind), file, mRenderer);
|
||||
balloons.push_back(b);
|
||||
return (Uint8)(balloons.size() - 1);
|
||||
}
|
||||
|
||||
// Crea una PowerBall
|
||||
@@ -1773,7 +1786,7 @@ void Game::createPowerBall()
|
||||
const int x[3] = {left, center, right};
|
||||
const int posX = x[rand() % 3];
|
||||
|
||||
Balloon *b = new Balloon(posX, posY, POWER_BALL, BALLOON_VELX_POSITIVE * (((rand() % 2) * 2) - 1), mEnemySpeed, 100, mTextureBalloon, mRenderer);
|
||||
Balloon *b = new Balloon(posX, posY, POWER_BALL, BALLOON_VELX_POSITIVE * (((rand() % 2) * 2) - 1), mEnemySpeed, 100, balloon4Texture, mAsset->get("balloon4.ani"), mRenderer);
|
||||
balloons.push_back(b);
|
||||
|
||||
mPowerBallEnabled = true;
|
||||
@@ -1897,28 +1910,27 @@ void Game::popBalloon(Balloon *balloon)
|
||||
|
||||
// En cualquier otro caso, crea dos globos de un tipo inferior
|
||||
default:
|
||||
Balloon *b1 = new Balloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_NEGATIVE, mEnemySpeed, 0, mTextureBalloon, mRenderer);
|
||||
balloons.push_back(b1);
|
||||
b1->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
||||
if (b1->getClass() == BALLOON_CLASS)
|
||||
// Balloon *b1 = new Balloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_NEGATIVE, mEnemySpeed, 0, mRenderer);
|
||||
const int index = createNewBalloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_NEGATIVE, mEnemySpeed, 0);
|
||||
balloons.at(index)->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
||||
if (balloons.at(index)->getClass() == BALLOON_CLASS)
|
||||
{
|
||||
b1->setVelY(-2.50f);
|
||||
balloons.at(index)->setVelY(-2.50f);
|
||||
}
|
||||
else if (b1->getClass() == HEXAGON_CLASS)
|
||||
else if (balloons.at(index)->getClass() == HEXAGON_CLASS)
|
||||
{
|
||||
b1->setVelY(BALLOON_VELX_NEGATIVE);
|
||||
balloons.at(index)->setVelY(BALLOON_VELX_NEGATIVE);
|
||||
}
|
||||
|
||||
Balloon *b2 = new Balloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_POSITIVE, mEnemySpeed, 0, mTextureBalloon, mRenderer);
|
||||
balloons.push_back(b2);
|
||||
b2->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
||||
if (b2->getClass() == BALLOON_CLASS)
|
||||
const int index2 = createNewBalloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_POSITIVE, mEnemySpeed, 0);
|
||||
balloons.at(index2)->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
||||
if (balloons.at(index2)->getClass() == BALLOON_CLASS)
|
||||
{
|
||||
b2->setVelY(-2.50f);
|
||||
balloons.at(index2)->setVelY(-2.50f);
|
||||
}
|
||||
else if (b2->getClass() == HEXAGON_CLASS)
|
||||
else if (balloons.at(index2)->getClass() == HEXAGON_CLASS)
|
||||
{
|
||||
b2->setVelY(BALLOON_VELX_NEGATIVE);
|
||||
balloons.at(index2)->setVelY(BALLOON_VELX_NEGATIVE);
|
||||
}
|
||||
|
||||
// Elimina el globo
|
||||
@@ -2059,6 +2071,74 @@ Uint8 Game::countBalloons()
|
||||
return num;
|
||||
}
|
||||
|
||||
// Obtiene la textura correspondiente en funcion del tipo
|
||||
LTexture *Game::balloonTexture(int kind)
|
||||
{
|
||||
if (kind == 1 || kind == 5)
|
||||
{
|
||||
return balloon1Texture;
|
||||
}
|
||||
|
||||
else if (kind == 2 || kind == 6)
|
||||
{
|
||||
return balloon2Texture;
|
||||
}
|
||||
|
||||
else if (kind == 3 || kind == 7)
|
||||
{
|
||||
return balloon4Texture;
|
||||
}
|
||||
|
||||
else if (kind == 4 || kind == 8 || kind == 9)
|
||||
{
|
||||
return balloon4Texture;
|
||||
}
|
||||
|
||||
return balloon1Texture;
|
||||
}
|
||||
|
||||
// Obtiene la animacion correspondiente en funcion del tipo
|
||||
std::string Game::balloonAnimation(int kind)
|
||||
{
|
||||
if (kind == 1 || kind == 5)
|
||||
{
|
||||
return mAsset->get("balloon1.ani");
|
||||
}
|
||||
|
||||
else if (kind == 2 || kind == 6)
|
||||
{
|
||||
return mAsset->get("balloon2.ani");
|
||||
}
|
||||
|
||||
else if (kind == 3 || kind == 7)
|
||||
{
|
||||
return mAsset->get("balloon3.ani");
|
||||
}
|
||||
|
||||
else if (kind == 4 || kind == 8 || kind == 9)
|
||||
{
|
||||
return mAsset->get("balloon4.ani");
|
||||
}
|
||||
|
||||
return mAsset->get("balloon1.ani");
|
||||
}
|
||||
|
||||
// Vacia el vector de globos
|
||||
void Game::freeBalloons()
|
||||
{
|
||||
if (balloons.empty() == false)
|
||||
{
|
||||
for (int i = balloons.size() - 1; i >= 0; --i)
|
||||
{
|
||||
if (balloons.at(i)->isEnabled() == false)
|
||||
{
|
||||
delete balloons.at(i);
|
||||
balloons.erase(balloons.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba la colisión entre el jugador y los globos activos
|
||||
bool Game::checkPlayerBalloonCollision(Player *player)
|
||||
{
|
||||
@@ -2610,6 +2690,7 @@ void Game::updatePlayField()
|
||||
|
||||
// Vacia los vectores
|
||||
freeBullets();
|
||||
freeBalloons();
|
||||
}
|
||||
|
||||
// Actualiza el fondo
|
||||
|
||||
Reference in New Issue
Block a user