Powerup face blinking
This commit is contained in:
109
source/game.cpp
109
source/game.cpp
@@ -1731,10 +1731,47 @@ void Game::updateDeath()
|
||||
// Comprueba si todos los jugadores estan muertos
|
||||
bool allPlayersAreDead = true;
|
||||
for (int i = 0; i < mNumPlayers; i++)
|
||||
{
|
||||
allPlayersAreDead &= (!mPlayer[i]->isAlive());
|
||||
|
||||
if (!mPlayer[i]->isAlive())
|
||||
{
|
||||
// Animación
|
||||
if ((mPlayer[i]->getDeathCounter() / 5) % 4 == 0)
|
||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setSpriteClip(24 * 0, 24, 24, 24);
|
||||
else if ((mPlayer[i]->getDeathCounter() / 5) % 4 == 1)
|
||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setSpriteClip(24 * 1, 24, 24, 24);
|
||||
else if ((mPlayer[i]->getDeathCounter() / 5) % 4 == 2)
|
||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setSpriteClip(24 * 2, 24, 24, 24);
|
||||
else if ((mPlayer[i]->getDeathCounter() / 5) % 4 == 3)
|
||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setSpriteClip(24 * 3, 24, 24, 24);
|
||||
|
||||
// Rebote en los laterales
|
||||
if (mSmartSprite[mPlayer[i]->mDeathIndex]->getVelX() > 0)
|
||||
{
|
||||
if (mSmartSprite[mPlayer[i]->mDeathIndex]->getPosX() > (SCREEN_WIDTH - mSmartSprite[mPlayer[i]->mDeathIndex]->getWidth()))
|
||||
{
|
||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setPosX(SCREEN_WIDTH - mSmartSprite[mPlayer[i]->mDeathIndex]->getWidth());
|
||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setVelX(mSmartSprite[mPlayer[i]->mDeathIndex]->getVelX() * (-1));
|
||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setDestX(mSmartSprite[mPlayer[i]->mDeathIndex]->getDestX() * (-1));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mSmartSprite[mPlayer[i]->mDeathIndex]->getPosX() < 0)
|
||||
{
|
||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setPosX(0);
|
||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setVelX(mSmartSprite[mPlayer[i]->mDeathIndex]->getVelX() * (-1));
|
||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setDestX(mSmartSprite[mPlayer[i]->mDeathIndex]->getDestX() * (-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (allPlayersAreDead)
|
||||
{
|
||||
JA_StopMusic();
|
||||
|
||||
if (mDeathCounter > 0)
|
||||
{
|
||||
mDeathCounter--;
|
||||
@@ -1760,36 +1797,6 @@ void Game::updateDeath()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Animación
|
||||
if ((mDeathCounter / 5) % 4 == 0)
|
||||
mSmartSprite[mDeathIndex]->setSpriteClip(24 * 0, 24, 24, 24);
|
||||
else if ((mDeathCounter / 5) % 4 == 1)
|
||||
mSmartSprite[mDeathIndex]->setSpriteClip(24 * 1, 24, 24, 24);
|
||||
else if ((mDeathCounter / 5) % 4 == 2)
|
||||
mSmartSprite[mDeathIndex]->setSpriteClip(24 * 2, 24, 24, 24);
|
||||
else if ((mDeathCounter / 5) % 4 == 3)
|
||||
mSmartSprite[mDeathIndex]->setSpriteClip(24 * 3, 24, 24, 24);
|
||||
|
||||
// Rebote en los laterales
|
||||
if (mSmartSprite[mDeathIndex]->getVelX() > 0)
|
||||
{
|
||||
if (mSmartSprite[mDeathIndex]->getPosX() > (SCREEN_WIDTH - mSmartSprite[mDeathIndex]->getWidth()))
|
||||
{
|
||||
mSmartSprite[mDeathIndex]->setPosX(SCREEN_WIDTH - mSmartSprite[mDeathIndex]->getWidth());
|
||||
mSmartSprite[mDeathIndex]->setVelX(mSmartSprite[mDeathIndex]->getVelX() * (-1));
|
||||
mSmartSprite[mDeathIndex]->setDestX(mSmartSprite[mDeathIndex]->getDestX() * (-1));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mSmartSprite[mDeathIndex]->getPosX() < 0)
|
||||
{
|
||||
mSmartSprite[mDeathIndex]->setPosX(0);
|
||||
mSmartSprite[mDeathIndex]->setVelX(mSmartSprite[mDeathIndex]->getVelX() * (-1));
|
||||
mSmartSprite[mDeathIndex]->setDestX(mSmartSprite[mDeathIndex]->getDestX() * (-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2050,7 +2057,7 @@ void Game::destroyBalloon(Uint8 index)
|
||||
}
|
||||
|
||||
// Otorga los puntos correspondientes al globo
|
||||
mPlayer[0]->addScore(Uint32(score * mPlayer[0]->getScoreMultiplier()*mDifficultyScoreMultiplier));
|
||||
mPlayer[0]->addScore(Uint32(score * mPlayer[0]->getScoreMultiplier() * mDifficultyScoreMultiplier));
|
||||
//setScore(mPlayer[0]->getScore());
|
||||
updateHiScore();
|
||||
|
||||
@@ -2319,10 +2326,10 @@ void Game::resetItems()
|
||||
// Devuelve un item en función del azar
|
||||
Uint8 Game::dropItem()
|
||||
{
|
||||
//if (mPlayer[0]->isPowerUp() || (mCoffeeMachineEnabled))
|
||||
// return NO_KIND;
|
||||
//else
|
||||
// return ITEM_COFFEE_MACHINE;
|
||||
if (mPlayer[0]->isPowerUp() || (mCoffeeMachineEnabled))
|
||||
return NO_KIND;
|
||||
else
|
||||
return ITEM_COFFEE_MACHINE;
|
||||
|
||||
const Uint8 luckyNumber = rand() % 100;
|
||||
const Uint8 item = rand() % 6;
|
||||
@@ -2454,21 +2461,21 @@ void Game::throwPlayer(int x, int y, int index)
|
||||
{
|
||||
const int sentit = ((rand() % 2) ? 1 : -1);
|
||||
|
||||
mDeathIndex = getSmartSpriteFreeIndex();
|
||||
mSmartSprite[mDeathIndex]->init(mPlayer[index]->getDeadTexture(), mRenderer);
|
||||
mSmartSprite[mDeathIndex]->setPosX(x);
|
||||
mSmartSprite[mDeathIndex]->setPosY(y);
|
||||
mSmartSprite[mDeathIndex]->setWidth(24);
|
||||
mSmartSprite[mDeathIndex]->setHeight(24);
|
||||
mSmartSprite[mDeathIndex]->setVelX(2.0f * sentit);
|
||||
mSmartSprite[mDeathIndex]->setVelY(-5.0f);
|
||||
mSmartSprite[mDeathIndex]->setAccelX(0.0f);
|
||||
mSmartSprite[mDeathIndex]->setAccelY(0.2f);
|
||||
mSmartSprite[mDeathIndex]->setDestX(SCREEN_WIDTH * sentit);
|
||||
mSmartSprite[mDeathIndex]->setDestY(SCREEN_HEIGHT + 1);
|
||||
mSmartSprite[mDeathIndex]->setEnabled(true);
|
||||
mSmartSprite[mDeathIndex]->setEnabledTimer(1);
|
||||
mSmartSprite[mDeathIndex]->setSpriteClip(0, 0, 24, 24);
|
||||
mPlayer[index]->mDeathIndex = getSmartSpriteFreeIndex();
|
||||
mSmartSprite[mPlayer[index]->mDeathIndex]->init(mPlayer[index]->getDeadTexture(), mRenderer);
|
||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setPosX(x);
|
||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setPosY(y);
|
||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setWidth(24);
|
||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setHeight(24);
|
||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setVelX(2.0f * sentit);
|
||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setVelY(-5.0f);
|
||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setAccelX(0.0f);
|
||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setAccelY(0.2f);
|
||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setDestX(SCREEN_WIDTH * sentit);
|
||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setDestY(SCREEN_HEIGHT + 1);
|
||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setEnabled(true);
|
||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setEnabledTimer(1);
|
||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setSpriteClip(0, 0, 24, 24);
|
||||
}
|
||||
|
||||
// Actualiza los SmartSprites
|
||||
@@ -2516,7 +2523,7 @@ void Game::killPlayer(int index)
|
||||
else
|
||||
{
|
||||
stopAllBalloons(10);
|
||||
JA_StopMusic();
|
||||
//JA_StopMusic();
|
||||
JA_PlaySound(mSoundPlayerCollision);
|
||||
shakeScreen();
|
||||
SDL_Delay(500);
|
||||
|
||||
@@ -30,12 +30,15 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
||||
|
||||
// Inicializa variables de estado
|
||||
mAlive = true;
|
||||
mDeathCounter = DEATH_COUNTER;
|
||||
mDeathIndex = 0;
|
||||
mStatusWalking = PLAYER_STATUS_WALKING_STOP;
|
||||
mStatusFiring = PLAYER_STATUS_FIRING_NO;
|
||||
mInvulnerable = false;
|
||||
mInvulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
|
||||
mPowerUp = false;
|
||||
mPowerUpCounter = PLAYER_POWERUP_COUNTER;
|
||||
mPowerUpHeadOffset = 0;
|
||||
mExtraHit = false;
|
||||
mCoffees = 0;
|
||||
mInput = true;
|
||||
@@ -368,12 +371,12 @@ void Player::setAnimation()
|
||||
// Actualiza los frames de la animación en función de si se tiene el PowerUp
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, i, (mWidth * i) + (mPowerUp * 96), mHeight * (0 + (6 * mCoffees)), mWidth, mHeight);
|
||||
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, i, (mWidth * i) + (mPowerUp * 96), mHeight * (1 + (6 * mCoffees)), mWidth, mHeight);
|
||||
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, i, (mWidth * i) + (mPowerUp * 96), mHeight * (2 + (6 * mCoffees)), mWidth, mHeight);
|
||||
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, i, (mWidth * i) + (mPowerUp * 96), mHeight * (3 + (6 * mCoffees)), mWidth, mHeight);
|
||||
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, i, (mWidth * i) + (mPowerUp * 96), mHeight * (4 + (6 * mCoffees)), mWidth, mHeight);
|
||||
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, i, (mWidth * i) + (mPowerUp * 96), mHeight * (5 + (6 * mCoffees)), mWidth, mHeight);
|
||||
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_LEFT, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (0 + (6 * mCoffees)), mWidth, mHeight);
|
||||
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_LEFT, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (1 + (6 * mCoffees)), mWidth, mHeight);
|
||||
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_RIGHT, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (2 + (6 * mCoffees)), mWidth, mHeight);
|
||||
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_RIGHT, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (3 + (6 * mCoffees)), mWidth, mHeight);
|
||||
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_WALKING_STOP, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (4 + (6 * mCoffees)), mWidth, mHeight);
|
||||
mSpriteHead->setAnimationFrames(PLAYER_ANIMATION_HEAD_FIRING_UP, i, (mWidth * i) + mPowerUpHeadOffset, mHeight * (5 + (6 * mCoffees)), mWidth, mHeight);
|
||||
}
|
||||
|
||||
switch (mStatusWalking)
|
||||
@@ -545,6 +548,8 @@ void Player::update()
|
||||
updateCooldown();
|
||||
updatePowerUpCounter();
|
||||
updateInvulnerableCounter();
|
||||
updateDeathCounter();
|
||||
updatePowerUpHeadOffset();
|
||||
}
|
||||
|
||||
// Obtiene la puntuación del jugador
|
||||
@@ -634,9 +639,10 @@ void Player::setInvulnerableCounter(Uint16 value)
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updateInvulnerableCounter()
|
||||
{
|
||||
if (mInvulnerable)
|
||||
if (mInvulnerableCounter > 0)
|
||||
{
|
||||
--mInvulnerableCounter;
|
||||
mInvulnerableCounter--;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -645,6 +651,14 @@ void Player::updateInvulnerableCounter()
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updateDeathCounter()
|
||||
{
|
||||
if (!mAlive)
|
||||
if (mDeathCounter > 0)
|
||||
mDeathCounter--;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool Player::isPowerUp()
|
||||
{
|
||||
@@ -745,3 +759,27 @@ LTexture *Player::getDeadTexture()
|
||||
{
|
||||
return mPlayerDeadTexture;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint16 Player::getDeathCounter()
|
||||
{
|
||||
return mDeathCounter;
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updatePowerUpHeadOffset()
|
||||
{
|
||||
if (!mPowerUp)
|
||||
mPowerUpHeadOffset = 0;
|
||||
else
|
||||
{
|
||||
mPowerUpHeadOffset = 96;
|
||||
if (mPowerUpCounter < 300)
|
||||
{
|
||||
if (mPowerUpCounter % 10 > 4)
|
||||
mPowerUpHeadOffset = 96;
|
||||
else
|
||||
mPowerUpHeadOffset = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,11 +29,13 @@ private:
|
||||
Uint8 mStatusFiring; // Estado del jugador
|
||||
|
||||
bool mAlive; // Indica si el jugador está vivo
|
||||
Uint16 mDeathCounter; // Contador para la animación de morirse
|
||||
bool mInvulnerable; // Indica si el jugador es invulnerable
|
||||
Uint16 mInvulnerableCounter; // Temporizador para la invulnerabilidad
|
||||
Uint16 mInvulnerableCounter; // Contador para la invulnerabilidad
|
||||
bool mExtraHit; // Indica si el jugador tiene un toque extra
|
||||
Uint8 mCoffees; // Indica cuantos cafes lleva acumulados
|
||||
bool mPowerUp; // Indica si el jugador tiene activo el modo PowerUp
|
||||
Uint8 mPowerUpHeadOffset; // Variable para dibujar la cabeza normal o la del powerup
|
||||
bool mInput; // Indica si puede recibir ordenes de entrada
|
||||
|
||||
AnimatedSprite *mSpriteLegs; // Sprite para dibujar las piernas
|
||||
@@ -44,8 +46,19 @@ private:
|
||||
circle_t mCollider; // Circulo de colisión del jugador
|
||||
void shiftColliders(); // Actualiza el circulo de colisión a la posición del jugador
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void updateInvulnerableCounter();
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void updateDeathCounter();
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void updatePowerUpHeadOffset();
|
||||
|
||||
public:
|
||||
Uint8 mDeathIndex; // Apaño rapidito. Indice de SmartSprite donde esta ubicado el sprite de morirse
|
||||
Uint16 mPowerUpCounter; // Temporizador para el modo PowerUp
|
||||
|
||||
// Constructor
|
||||
Player();
|
||||
|
||||
@@ -66,6 +79,8 @@ public:
|
||||
|
||||
// Establece el estado del jugador
|
||||
void setWalkingStatus(Uint8 status);
|
||||
|
||||
// Establece el estado del jugador
|
||||
void setFiringStatus(Uint8 status);
|
||||
|
||||
// Establece la animación correspondiente al estado
|
||||
@@ -134,9 +149,6 @@ public:
|
||||
// Establece el valor de la variable
|
||||
void setInvulnerableCounter(Uint16 value);
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void updateInvulnerableCounter();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool isPowerUp();
|
||||
|
||||
@@ -175,6 +187,9 @@ public:
|
||||
|
||||
// Obtiene el puntero a la textura con los gráficos de la animación de morir
|
||||
LTexture *getDeadTexture();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint16 getDeathCounter();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -133,7 +133,7 @@ void Title::init(bool demo, Uint8 subsection)
|
||||
mPostFade = 0;
|
||||
mTicks = 0;
|
||||
mTicksSpeed = 15;
|
||||
mFade->init(0x00, 0x00, 0x00);
|
||||
mFade->init(0x17, 0x17, 0x26);
|
||||
mDemo = demo;
|
||||
|
||||
// Inicializa el bitmap de Coffee
|
||||
|
||||
Reference in New Issue
Block a user