Balas funcionales
This commit is contained in:
@@ -12,7 +12,7 @@ Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, LTexture *text
|
|||||||
|
|
||||||
// Alto y ancho del objeto
|
// Alto y ancho del objeto
|
||||||
mWidth = 10;
|
mWidth = 10;
|
||||||
mHeight = mWidth;
|
mHeight = 10;
|
||||||
|
|
||||||
// Velocidad inicial en el eje Y
|
// Velocidad inicial en el eje Y
|
||||||
mVelY = -3;
|
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
|
// Rectangulo con los gráficos del objeto
|
||||||
if (!poweredUp)
|
if (!poweredUp)
|
||||||
|
{
|
||||||
mSprite->setSpriteClip(0 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
mSprite->setSpriteClip(0 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
mSprite->setSpriteClip((0 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
mSprite->setSpriteClip((0 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BULLET_LEFT:
|
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
|
// Rectangulo con los gráficos del objeto
|
||||||
if (!poweredUp)
|
if (!poweredUp)
|
||||||
|
{
|
||||||
mSprite->setSpriteClip(1 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
mSprite->setSpriteClip(1 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
mSprite->setSpriteClip((1 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
mSprite->setSpriteClip((1 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BULLET_RIGHT:
|
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
|
// Rectangulo con los gráficos del objeto
|
||||||
if (!poweredUp)
|
if (!poweredUp)
|
||||||
|
{
|
||||||
mSprite->setSpriteClip(2 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
mSprite->setSpriteClip(2 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
mSprite->setSpriteClip((2 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
mSprite->setSpriteClip((2 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -74,7 +86,6 @@ Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, LTexture *text
|
|||||||
Bullet::~Bullet()
|
Bullet::~Bullet()
|
||||||
{
|
{
|
||||||
delete mSprite;
|
delete mSprite;
|
||||||
mSprite = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el objeto en pantalla
|
// Pinta el objeto en pantalla
|
||||||
@@ -129,10 +140,20 @@ Uint8 Bullet::move()
|
|||||||
bool Bullet::isActive()
|
bool Bullet::isActive()
|
||||||
{
|
{
|
||||||
if (mKind == NO_KIND)
|
if (mKind == NO_KIND)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Desactiva el objeto
|
||||||
|
void Bullet::deactivate()
|
||||||
|
{
|
||||||
|
mKind = NO_KIND;
|
||||||
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int Bullet::getPosX()
|
int Bullet::getPosX()
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ public:
|
|||||||
// Comprueba si el objeto está activo
|
// Comprueba si el objeto está activo
|
||||||
bool isActive();
|
bool isActive();
|
||||||
|
|
||||||
|
// Desactiva el objeto
|
||||||
|
void deactivate();
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int getPosX();
|
int getPosX();
|
||||||
|
|
||||||
|
|||||||
@@ -2153,8 +2153,8 @@ void Game::checkBulletBalloonCollision()
|
|||||||
{
|
{
|
||||||
// Otorga los puntos correspondientes al globo al jugador que disparó la bala
|
// Otorga los puntos correspondientes al globo al jugador que disparó la bala
|
||||||
int index = bullet->getOwner();
|
int index = bullet->getOwner();
|
||||||
players[index]->incScoreMultiplier();
|
players.at(index)->incScoreMultiplier();
|
||||||
players[index]->addScore(Uint32(balloon->getScore() * players[index]->getScoreMultiplier() * mDifficultyScoreMultiplier));
|
players.at(index)->addScore(Uint32(balloon->getScore() * players.at(index)->getScoreMultiplier() * mDifficultyScoreMultiplier));
|
||||||
updateHiScore();
|
updateHiScore();
|
||||||
|
|
||||||
// Explota el globo
|
// Explota el globo
|
||||||
@@ -2166,8 +2166,8 @@ void Game::checkBulletBalloonCollision()
|
|||||||
JA_PlaySound(mSoundBalloon);
|
JA_PlaySound(mSoundBalloon);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destruye la bala
|
// Desactiva la bala
|
||||||
delete bullet;
|
bullet->deactivate();
|
||||||
|
|
||||||
// Suelta el item en caso de que salga uno
|
// Suelta el item en caso de que salga uno
|
||||||
const Uint8 droppeditem = dropItem();
|
const Uint8 droppeditem = dropItem();
|
||||||
@@ -2200,7 +2200,7 @@ void Game::moveBullets()
|
|||||||
{
|
{
|
||||||
if (bullet->move() == BULLET_MOVE_OUT)
|
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);
|
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
|
// Actualiza los items
|
||||||
void Game::updateItems()
|
void Game::updateItems()
|
||||||
{
|
{
|
||||||
@@ -2591,6 +2607,9 @@ void Game::updatePlayField()
|
|||||||
|
|
||||||
// Actualiza el tramo final de juego, una vez completado
|
// Actualiza el tramo final de juego, una vez completado
|
||||||
updateGameCompleted();
|
updateGameCompleted();
|
||||||
|
|
||||||
|
// Vacia los vectores
|
||||||
|
freeBullets();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el fondo
|
// Actualiza el fondo
|
||||||
@@ -2676,7 +2695,7 @@ void Game::renderPlayField()
|
|||||||
player->render();
|
player->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mDeathCounter <= 150) && !players[0]->isAlive())
|
if ((mDeathCounter <= 150) && !players.at(0)->isAlive())
|
||||||
{
|
{
|
||||||
renderDeathFade(150 - mDeathCounter);
|
renderDeathFade(150 - mDeathCounter);
|
||||||
}
|
}
|
||||||
@@ -3056,7 +3075,7 @@ section_t Game::run()
|
|||||||
// Reproduce la música
|
// Reproduce la música
|
||||||
if (!mGameCompleted)
|
if (!mGameCompleted)
|
||||||
{
|
{
|
||||||
if (players[0]->isAlive())
|
if (players.at(0)->isAlive())
|
||||||
{
|
{
|
||||||
JA_PlayMusic(mMusicPlaying);
|
JA_PlayMusic(mMusicPlaying);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -359,6 +359,9 @@ private:
|
|||||||
// Crea un objeto bala
|
// Crea un objeto bala
|
||||||
void createBullet(int x, int y, Uint8 kind, bool poweredUp, int owner);
|
void createBullet(int x, int y, Uint8 kind, bool poweredUp, int owner);
|
||||||
|
|
||||||
|
// Vacia el vector de balas
|
||||||
|
void freeBullets();
|
||||||
|
|
||||||
// Actualiza los items
|
// Actualiza los items
|
||||||
void updateItems();
|
void updateItems();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user