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