Balas funcionales
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
// Constructor
|
// Constructor
|
||||||
Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, LTexture *texture, SDL_Renderer *renderer)
|
Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, LTexture *texture, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
mSprite = new Sprite({x,y,10,10},texture, renderer);
|
mSprite = new Sprite({x, y, 10, 10}, texture, renderer);
|
||||||
|
|
||||||
// Posición inicial del objeto
|
// Posición inicial del objeto
|
||||||
mPosX = x;
|
mPosX = x;
|
||||||
@@ -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,9 +140,19 @@ 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
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|
||||||
|
|||||||
111
source/game.cpp
111
source/game.cpp
@@ -337,33 +337,33 @@ void Game::init()
|
|||||||
mFade->init(0x27, 0x27, 0x36);
|
mFade->init(0x27, 0x27, 0x36);
|
||||||
|
|
||||||
// Inicializa el objeto con el menu de pausa
|
// Inicializa el objeto con el menu de pausa
|
||||||
//mMenuPause->setName("PAUSE");
|
// mMenuPause->setName("PAUSE");
|
||||||
//mMenuPause->setPos(0, 12 * BLOCK);
|
// mMenuPause->setPos(0, 12 * BLOCK);
|
||||||
//mMenuPause->setBackgroundType(MENU_BACKGROUND_SOLID);
|
// mMenuPause->setBackgroundType(MENU_BACKGROUND_SOLID);
|
||||||
//mMenuPause->addItem(mLang->getText(46), 2);
|
// mMenuPause->addItem(mLang->getText(46), 2);
|
||||||
//mMenuPause->addItem(mLang->getText(47), 0);
|
// mMenuPause->addItem(mLang->getText(47), 0);
|
||||||
//mMenuPause->setDefaultActionWhenCancel(0);
|
// mMenuPause->setDefaultActionWhenCancel(0);
|
||||||
//mMenuPause->setBackgroundColor({0x29, 0x39, 0x41}, 240);
|
// mMenuPause->setBackgroundColor({0x29, 0x39, 0x41}, 240);
|
||||||
//mMenuPause->setSelectorColor({0xFF, 0x7A, 0x00}, 255);
|
// mMenuPause->setSelectorColor({0xFF, 0x7A, 0x00}, 255);
|
||||||
//mMenuPause->setSelectorTextColor({0xFF, 0xFF, 0xFF});
|
// mMenuPause->setSelectorTextColor({0xFF, 0xFF, 0xFF});
|
||||||
//mMenuPause->centerMenuOnX(SCREEN_CENTER_X);
|
// mMenuPause->centerMenuOnX(SCREEN_CENTER_X);
|
||||||
//mMenuPause->centerMenuElementsOnX();
|
// mMenuPause->centerMenuElementsOnX();
|
||||||
|
|
||||||
// Inicializa el objeto con el menu de la pantalla de game over
|
// Inicializa el objeto con el menu de la pantalla de game over
|
||||||
//mMenuGameOver->setName("GAME OVER");
|
// mMenuGameOver->setName("GAME OVER");
|
||||||
//mMenuGameOver->setPos(0, PLAY_AREA_CENTER_Y + BLOCK * 4);
|
// mMenuGameOver->setPos(0, PLAY_AREA_CENTER_Y + BLOCK * 4);
|
||||||
//mMenuGameOver->setBackgroundType(MENU_BACKGROUND_TRANSPARENT);
|
// mMenuGameOver->setBackgroundType(MENU_BACKGROUND_TRANSPARENT);
|
||||||
//mMenuGameOver->addItem(mLang->getText(48), 2);
|
// mMenuGameOver->addItem(mLang->getText(48), 2);
|
||||||
//mMenuGameOver->addItem(mLang->getText(49));
|
// mMenuGameOver->addItem(mLang->getText(49));
|
||||||
//mMenuGameOver->setDefaultActionWhenCancel(1);
|
// mMenuGameOver->setDefaultActionWhenCancel(1);
|
||||||
//mMenuGameOver->setBackgroundColor({0, 0, 0}, 255);
|
// mMenuGameOver->setBackgroundColor({0, 0, 0}, 255);
|
||||||
//mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 255);
|
// mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 255);
|
||||||
//mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 0);
|
// mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 0);
|
||||||
//mMenuGameOver->setSelectorTextColor({0xFF, 0xFF, 0xFF});
|
// mMenuGameOver->setSelectorTextColor({0xFF, 0xFF, 0xFF});
|
||||||
//mMenuGameOver->setSelectorTextColor({0xFF, 0xF1, 0x76});
|
// mMenuGameOver->setSelectorTextColor({0xFF, 0xF1, 0x76});
|
||||||
//mMenuGameOver->setSelectorTextColor({0xFF, 0x7A, 0x00});
|
// mMenuGameOver->setSelectorTextColor({0xFF, 0x7A, 0x00});
|
||||||
//mMenuGameOver->centerMenuOnX(SCREEN_CENTER_X);
|
// mMenuGameOver->centerMenuOnX(SCREEN_CENTER_X);
|
||||||
//mMenuGameOver->centerMenuElementsOnX();
|
// mMenuGameOver->centerMenuElementsOnX();
|
||||||
|
|
||||||
// Sprites
|
// Sprites
|
||||||
mClouds1a->setSpriteClip(256, 0, 256, 52);
|
mClouds1a->setSpriteClip(256, 0, 256, 52);
|
||||||
@@ -1756,9 +1756,9 @@ void Game::renderBalloons()
|
|||||||
// Crea un globo nuevo en el vector de globos
|
// 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, LTexture *texture)
|
||||||
{
|
{
|
||||||
//Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, texture, mRenderer);
|
// Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, texture, mRenderer);
|
||||||
//balloons.push_back(b);
|
// balloons.push_back(b);
|
||||||
//return (Uint8)(balloons.size() - 1);
|
// return (Uint8)(balloons.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea una PowerBall
|
// Crea una PowerBall
|
||||||
@@ -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()
|
||||||
{
|
{
|
||||||
@@ -2330,7 +2346,7 @@ void Game::createItemScoreSprite(int x, int y, SmartSprite *sprite)
|
|||||||
smartSprites.push_back(ss);
|
smartSprites.push_back(ss);
|
||||||
|
|
||||||
// Crea una copia del objeto
|
// Crea una copia del objeto
|
||||||
*ss = *sprite;
|
*ss = *sprite;
|
||||||
ss->setPosX(x);
|
ss->setPosX(x);
|
||||||
ss->setPosY(y);
|
ss->setPosY(y);
|
||||||
ss->setDestX(x);
|
ss->setDestX(x);
|
||||||
@@ -2398,7 +2414,7 @@ void Game::throwPlayer(int x, int y, Player *player)
|
|||||||
{
|
{
|
||||||
const int sentit = ((rand() % 2) ? 1 : -1);
|
const int sentit = ((rand() % 2) ? 1 : -1);
|
||||||
|
|
||||||
//player->deathIndex = getSmartSpriteFreeIndex();
|
// player->deathIndex = getSmartSpriteFreeIndex();
|
||||||
|
|
||||||
SmartSprite *ss = new SmartSprite(nullptr, mRenderer);
|
SmartSprite *ss = new SmartSprite(nullptr, mRenderer);
|
||||||
smartSprites.push_back(ss);
|
smartSprites.push_back(ss);
|
||||||
@@ -2422,7 +2438,7 @@ void Game::throwPlayer(int x, int y, Player *player)
|
|||||||
// Actualiza los SmartSprites
|
// Actualiza los SmartSprites
|
||||||
void Game::updateSmartSprites()
|
void Game::updateSmartSprites()
|
||||||
{
|
{
|
||||||
for (auto ss:smartSprites)
|
for (auto ss : smartSprites)
|
||||||
{
|
{
|
||||||
ss->update();
|
ss->update();
|
||||||
}
|
}
|
||||||
@@ -2431,7 +2447,7 @@ void Game::updateSmartSprites()
|
|||||||
// Pinta los SmartSprites activos
|
// Pinta los SmartSprites activos
|
||||||
void Game::renderSmartSprites()
|
void Game::renderSmartSprites()
|
||||||
{
|
{
|
||||||
for (auto ss:smartSprites)
|
for (auto ss : smartSprites)
|
||||||
{
|
{
|
||||||
ss->render();
|
ss->render();
|
||||||
}
|
}
|
||||||
@@ -2474,7 +2490,7 @@ void Game::killPlayer(Player *player)
|
|||||||
void Game::evaluateAndSetMenace()
|
void Game::evaluateAndSetMenace()
|
||||||
{
|
{
|
||||||
mMenaceCurrent = 0;
|
mMenaceCurrent = 0;
|
||||||
for (auto balloon:balloons)
|
for (auto balloon : balloons)
|
||||||
{
|
{
|
||||||
if (balloon->isEnabled())
|
if (balloon->isEnabled())
|
||||||
{
|
{
|
||||||
@@ -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
|
||||||
@@ -2671,12 +2690,12 @@ void Game::renderPlayField()
|
|||||||
renderSmartSprites();
|
renderSmartSprites();
|
||||||
renderScoreBoard();
|
renderScoreBoard();
|
||||||
|
|
||||||
for (auto player:players)
|
for (auto player : players)
|
||||||
{
|
{
|
||||||
player->render();
|
player->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mDeathCounter <= 150) && !players[0]->isAlive())
|
if ((mDeathCounter <= 150) && !players.at(0)->isAlive())
|
||||||
{
|
{
|
||||||
renderDeathFade(150 - mDeathCounter);
|
renderDeathFade(150 - mDeathCounter);
|
||||||
}
|
}
|
||||||
@@ -2787,7 +2806,7 @@ void Game::checkGameInput()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto player:players)
|
for (auto player : players)
|
||||||
{
|
{
|
||||||
if (player->isAlive())
|
if (player->isAlive())
|
||||||
{
|
{
|
||||||
@@ -3016,7 +3035,7 @@ void Game::shakeScreen()
|
|||||||
renderBalloons();
|
renderBalloons();
|
||||||
renderBullets();
|
renderBullets();
|
||||||
renderItems();
|
renderItems();
|
||||||
for (auto player:players)
|
for (auto player : players)
|
||||||
{
|
{
|
||||||
player->render();
|
player->render();
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
@@ -3340,7 +3359,7 @@ int Game::calculateScreenPower()
|
|||||||
{
|
{
|
||||||
int power = 0;
|
int power = 0;
|
||||||
|
|
||||||
for (auto balloon:balloons)
|
for (auto balloon : balloons)
|
||||||
{
|
{
|
||||||
if (balloon->isEnabled())
|
if (balloon->isEnabled())
|
||||||
{
|
{
|
||||||
@@ -3431,7 +3450,7 @@ void Game::updateHelper()
|
|||||||
// Solo ofrece ayuda cuando la amenaza es elevada
|
// Solo ofrece ayuda cuando la amenaza es elevada
|
||||||
if (mMenaceCurrent > 15)
|
if (mMenaceCurrent > 15)
|
||||||
{
|
{
|
||||||
for (auto player:players)
|
for (auto player : players)
|
||||||
{
|
{
|
||||||
if (player->getCoffees() == 0)
|
if (player->getCoffees() == 0)
|
||||||
{
|
{
|
||||||
@@ -3463,7 +3482,7 @@ void Game::updateHelper()
|
|||||||
bool Game::allPlayersAreDead()
|
bool Game::allPlayersAreDead()
|
||||||
{
|
{
|
||||||
bool success = true;
|
bool success = true;
|
||||||
for (auto player:players)
|
for (auto player : players)
|
||||||
{
|
{
|
||||||
success &= (!player->isAlive());
|
success &= (!player->isAlive());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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