Balas funcionales

This commit is contained in:
2022-10-03 03:02:46 +02:00
parent 4ac7496eff
commit 80ca04fd64
4 changed files with 96 additions and 50 deletions

View File

@@ -12,7 +12,7 @@ Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, LTexture *text
// Alto y ancho del objeto
mWidth = 10;
mHeight = mWidth;
mHeight = 10;
// Velocidad inicial en el eje Y
mVelY = -3;
@@ -32,9 +32,13 @@ Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, LTexture *text
// Rectangulo con los gráficos del objeto
if (!poweredUp)
{
mSprite->setSpriteClip(0 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
}
else
{
mSprite->setSpriteClip((0 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
}
break;
case BULLET_LEFT:
@@ -43,9 +47,13 @@ Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, LTexture *text
// Rectangulo con los gráficos del objeto
if (!poweredUp)
{
mSprite->setSpriteClip(1 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
}
else
{
mSprite->setSpriteClip((1 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
}
break;
case BULLET_RIGHT:
@@ -54,9 +62,13 @@ Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, LTexture *text
// Rectangulo con los gráficos del objeto
if (!poweredUp)
{
mSprite->setSpriteClip(2 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
}
else
{
mSprite->setSpriteClip((2 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
}
break;
default:
@@ -74,7 +86,6 @@ Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, LTexture *text
Bullet::~Bullet()
{
delete mSprite;
mSprite = nullptr;
}
// Pinta el objeto en pantalla
@@ -129,10 +140,20 @@ Uint8 Bullet::move()
bool Bullet::isActive()
{
if (mKind == NO_KIND)
{
return false;
}
else
{
return true;
}
}
// Desactiva el objeto
void Bullet::deactivate()
{
mKind = NO_KIND;
}
// Obtiene el valor de la variable
int Bullet::getPosX()

View File

@@ -50,6 +50,9 @@ public:
// Comprueba si el objeto está activo
bool isActive();
// Desactiva el objeto
void deactivate();
// Obtiene el valor de la variable
int getPosX();

View File

@@ -2153,8 +2153,8 @@ void Game::checkBulletBalloonCollision()
{
// Otorga los puntos correspondientes al globo al jugador que disparó la bala
int index = bullet->getOwner();
players[index]->incScoreMultiplier();
players[index]->addScore(Uint32(balloon->getScore() * players[index]->getScoreMultiplier() * mDifficultyScoreMultiplier));
players.at(index)->incScoreMultiplier();
players.at(index)->addScore(Uint32(balloon->getScore() * players.at(index)->getScoreMultiplier() * mDifficultyScoreMultiplier));
updateHiScore();
// Explota el globo
@@ -2166,8 +2166,8 @@ void Game::checkBulletBalloonCollision()
JA_PlaySound(mSoundBalloon);
}
// Destruye la bala
delete bullet;
// Desactiva la bala
bullet->deactivate();
// Suelta el item en caso de que salga uno
const Uint8 droppeditem = dropItem();
@@ -2200,7 +2200,7 @@ void Game::moveBullets()
{
if (bullet->move() == BULLET_MOVE_OUT)
{
players[bullet->getOwner()]->decScoreMultiplier();
players.at(bullet->getOwner())->decScoreMultiplier();
}
}
}
@@ -2225,6 +2225,22 @@ void Game::createBullet(int x, int y, Uint8 kind, bool poweredUp, int owner)
bullets.push_back(b);
}
// Vacia el vector de balas
void Game::freeBullets()
{
if (bullets.empty() == false)
{
for (int i = bullets.size() - 1; i >= 0; --i)
{
if (bullets.at(i)->isActive() == false)
{
delete bullets.at(i);
bullets.erase(bullets.begin() + i);
}
}
}
}
// Actualiza los items
void Game::updateItems()
{
@@ -2591,6 +2607,9 @@ void Game::updatePlayField()
// Actualiza el tramo final de juego, una vez completado
updateGameCompleted();
// Vacia los vectores
freeBullets();
}
// Actualiza el fondo
@@ -2676,7 +2695,7 @@ void Game::renderPlayField()
player->render();
}
if ((mDeathCounter <= 150) && !players[0]->isAlive())
if ((mDeathCounter <= 150) && !players.at(0)->isAlive())
{
renderDeathFade(150 - mDeathCounter);
}
@@ -3056,7 +3075,7 @@ section_t Game::run()
// Reproduce la música
if (!mGameCompleted)
{
if (players[0]->isAlive())
if (players.at(0)->isAlive())
{
JA_PlayMusic(mMusicPlaying);
}

View File

@@ -359,6 +359,9 @@ private:
// Crea un objeto bala
void createBullet(int x, int y, Uint8 kind, bool poweredUp, int owner);
// Vacia el vector de balas
void freeBullets();
// Actualiza los items
void updateItems();