added poerup and helper

This commit is contained in:
2021-08-22 16:15:10 +02:00
parent eb8f84a4b8
commit 2fd4334259
7 changed files with 152 additions and 56 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -286,6 +286,15 @@ const int MULTIPLIER_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
#define ITEM_POWER_BALL 6 #define ITEM_POWER_BALL 6
#define ITEM_COFFEE_MACHINE 7 #define ITEM_COFFEE_MACHINE 7
// Porcentaje de aparición de los objetos
#define ITEM_POINTS_1_DISK_ODDS 10
#define ITEM_POINTS_2_GAVINA_ODDS 6
#define ITEM_POINTS_3_PACMAR_ODDS 3
#define ITEM_CLOCK_ODDS 5
#define ITEM_COFFEE_ODDS 5
#define ITEM_POWER_BALL_ODDS 0
#define ITEM_COFFEE_MACHINE_ODDS 4
// Cantidad de objetos simultaneos // Cantidad de objetos simultaneos
#define MAX_ITEMS 5 #define MAX_ITEMS 5
@@ -324,6 +333,7 @@ const int MULTIPLIER_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
#define INSTRUCTIONS_COUNTER 600 #define INSTRUCTIONS_COUNTER 600
#define DEATH_COUNTER 350 #define DEATH_COUNTER 350
#define SHAKE_COUNTER 10 #define SHAKE_COUNTER 10
#define HELP_COUNTER 1000
// Colores // Colores
const color_t bgColor = {0x27, 0x27, 0x36}; const color_t bgColor = {0x27, 0x27, 0x36};

View File

@@ -219,6 +219,7 @@ Game::~Game()
JA_DeleteSound(mSoundBubble4); JA_DeleteSound(mSoundBubble4);
JA_DeleteSound(mSoundClock); JA_DeleteSound(mSoundClock);
JA_DeleteSound(mSoundPowerBall); JA_DeleteSound(mSoundPowerBall);
JA_DeleteSound(mSoundCollision);
JA_DeleteMusic(mMusicPlaying); JA_DeleteMusic(mMusicPlaying);
} }
@@ -253,7 +254,7 @@ void Game::init()
mMenaceThreshold = 0; mMenaceThreshold = 0;
mScore = 0; mScore = 0;
mHiScoreAchieved = false; mHiScoreAchieved = false;
mCurrentStage = 9; mCurrentStage = 0;
mStageBitmapCounter = STAGE_COUNTER; mStageBitmapCounter = STAGE_COUNTER;
mDeathCounter = DEATH_COUNTER; mDeathCounter = DEATH_COUNTER;
mExplosionTime = false; mExplosionTime = false;
@@ -269,7 +270,18 @@ void Game::init()
mEffect.flash = false; mEffect.flash = false;
mEffect.shake = false; mEffect.shake = false;
mEffect.shakeCounter = SHAKE_COUNTER; mEffect.shakeCounter = SHAKE_COUNTER;
mHelper.needCoffee = false;
mHelper.needCoffeeMachine = false;
mHelper.needPowerBall = false;
mHelper.counter = HELP_COUNTER;
mHelper.itemPoints1Odds = ITEM_POINTS_1_DISK_ODDS;
mHelper.itemPoints2Odds = ITEM_POINTS_2_GAVINA_ODDS;
mHelper.itemPoints3Odds = ITEM_POINTS_3_PACMAR_ODDS;
mHelper.itemClockOdds = ITEM_CLOCK_ODDS;
mHelper.itemCoffeeOdds = ITEM_COFFEE_ODDS;
mHelper.itemCoffeeMachineOdds = ITEM_COFFEE_MACHINE_ODDS;
mPowerBallEnabled = false; mPowerBallEnabled = false;
mCoffeeMachineEnabled = false;
mPostFade = 0; mPostFade = 0;
if (mDemo.enabled) if (mDemo.enabled)
@@ -468,6 +480,7 @@ bool Game::loadMedia()
mSoundPlayerCollision = JA_LoadSound(mFileList[19].c_str()); mSoundPlayerCollision = JA_LoadSound(mFileList[19].c_str());
mSoundPowerBall = JA_LoadSound(mFileList[23].c_str()); mSoundPowerBall = JA_LoadSound(mFileList[23].c_str());
mSoundStageChange = JA_LoadSound(mFileList[20].c_str()); mSoundStageChange = JA_LoadSound(mFileList[20].c_str());
mSoundCollision = JA_LoadSound(mFileList[21].c_str());
// Musicas // Musicas
mMusicPlaying = JA_LoadMusic(mFileList[4].c_str()); mMusicPlaying = JA_LoadMusic(mFileList[4].c_str());
@@ -1617,10 +1630,14 @@ void Game::updateDeath()
} }
// Animación // Animación
if ((mDeathCounter / 5) % 2 == 0) if ((mDeathCounter / 5) % 4 == 0)
mSmartSprite[mDeathIndex]->setSpriteClip(0, 0, 24, 24); mSmartSprite[mDeathIndex]->setSpriteClip(24 * 0, 24, 24, 24);
else else if ((mDeathCounter / 5) % 4 == 1)
mSmartSprite[mDeathIndex]->setSpriteClip(24, 0, 24, 24); 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 // Rebote en los laterales
if (mSmartSprite[mDeathIndex]->getVelX() > 0) if (mSmartSprite[mDeathIndex]->getVelX() > 0)
@@ -2026,6 +2043,7 @@ void Game::checkPlayerItemCollision()
case ITEM_COFFEE_MACHINE: case ITEM_COFFEE_MACHINE:
mPlayer->setPowerUp(true); mPlayer->setPowerUp(true);
JA_PlaySound(mSoundItemPickup); JA_PlaySound(mSoundItemPickup);
mCoffeeMachineEnabled = false;
break; break;
default: default:
@@ -2055,7 +2073,10 @@ void Game::checkBulletBalloonCollision()
if ((droppeditem != NO_KIND) && !(mDemo.enabled) && !(mDemo.recording)) if ((droppeditem != NO_KIND) && !(mDemo.enabled) && !(mDemo.recording))
{ {
createItem(mBalloon[i]->getPosX(), mBalloon[i]->getPosY(), droppeditem); createItem(mBalloon[i]->getPosX(), mBalloon[i]->getPosY(), droppeditem);
if (droppeditem != ITEM_COFFEE_MACHINE)
JA_PlaySound(mSoundItemDrop); JA_PlaySound(mSoundItemDrop);
else
mCoffeeMachineEnabled = true;
} }
break; break;
} }
@@ -2105,7 +2126,11 @@ void Game::createBullet(int x, int y, Uint8 kind, bool poweredUp)
void Game::updateItems() void Game::updateItems()
{ {
for (int i = 0; i < MAX_ITEMS; i++) for (int i = 0; i < MAX_ITEMS; i++)
mItem[i]->update(); if (mItem[i]->update() == 1)
{
JA_PlaySound(mSoundCollision);
mEffect.shake = true;
}
} }
// Pinta los items activos // Pinta los items activos
@@ -2135,39 +2160,56 @@ void Game::resetItems()
// Devuelve un item en función del azar // Devuelve un item en función del azar
Uint8 Game::dropItem() Uint8 Game::dropItem()
{ {
if (mPlayer->isPowerUp()) /*if (mPlayer->isPowerUp() || (mCoffeeMachineEnabled))
return NO_KIND; return NO_KIND;
else else
return ITEM_COFFEE_MACHINE; return ITEM_COFFEE_MACHINE;*/
const Uint8 luckyNumber = rand() % 99; const Uint8 luckyNumber = rand() % 100;
const Uint8 item = rand() % 6; const Uint8 item = rand() % 6;
switch (item) switch (item)
{ {
case 0: case 0:
if (luckyNumber < 10) if (luckyNumber < mHelper.itemPoints1Odds)
return ITEM_POINTS_1_DISK; return ITEM_POINTS_1_DISK;
break; break;
case 1: case 1:
if (luckyNumber < 6) if (luckyNumber < mHelper.itemPoints2Odds)
return ITEM_POINTS_2_GAVINA; return ITEM_POINTS_2_GAVINA;
break; break;
case 2: case 2:
if (luckyNumber < 3) if (luckyNumber < mHelper.itemPoints3Odds)
return ITEM_POINTS_3_PACMAR; return ITEM_POINTS_3_PACMAR;
break; break;
case 3: case 3:
if (luckyNumber < 5) if (luckyNumber < mHelper.itemClockOdds)
return ITEM_CLOCK; return ITEM_CLOCK;
break; break;
case 4: case 4:
if (luckyNumber < 5) if (luckyNumber < mHelper.itemCoffeeOdds)
{
mHelper.itemCoffeeOdds = ITEM_COFFEE_ODDS;
return ITEM_COFFEE; return ITEM_COFFEE;
}
else
{
if (mHelper.needCoffee)
mHelper.itemCoffeeOdds++;
}
break; break;
case 5: case 5:
if (luckyNumber < 4) if (luckyNumber < mHelper.itemCoffeeMachineOdds)
{
mHelper.itemCoffeeMachineOdds = ITEM_COFFEE_MACHINE_ODDS;
if ((!mCoffeeMachineEnabled) && (mHelper.needCoffeeMachine))
return ITEM_COFFEE_MACHINE; return ITEM_COFFEE_MACHINE;
}
else
{
if (mHelper.needCoffeeMachine)
mHelper.itemCoffeeMachineOdds++;
}
break; break;
default: default:
break; break;
@@ -2217,7 +2259,10 @@ void Game::updateShakeEffect()
if (mEffect.shakeCounter > 0) if (mEffect.shakeCounter > 0)
mEffect.shakeCounter--; mEffect.shakeCounter--;
else else
{
mEffect.shake = false; mEffect.shake = false;
mEffect.shakeCounter = SHAKE_COUNTER;
}
} }
} }
@@ -2464,6 +2509,9 @@ void Game::updatePlayField()
updateEnemyDeployCounter(); updateEnemyDeployCounter();
updateShakeEffect(); updateShakeEffect();
// Actualiza el ayudante
updateHelper();
// Comprueba las colisiones entre globos y balas // Comprueba las colisiones entre globos y balas
checkBulletBalloonCollision(); checkBulletBalloonCollision();
@@ -2512,7 +2560,7 @@ void Game::updateBackground()
// Dibuja el fondo // Dibuja el fondo
void Game::renderBackground() void Game::renderBackground()
{ {
const float gradientNumber = std::min(((float)mBalloonsPopped / 900.0f), 3.0f); const float gradientNumber = std::min(((float)mBalloonsPopped / 1000.0f), 3.0f);
const float percent = gradientNumber - (int)gradientNumber; const float percent = gradientNumber - (int)gradientNumber;
const int alpha = std::max((255 - (int)(255 * percent)), 0); const int alpha = std::max((255 - (int)(255 * percent)), 0);
@@ -3213,3 +3261,26 @@ void Game::updateGameCompleted()
if (mGameCompletedCounter == 500) if (mGameCompletedCounter == 500)
mSection.subsection = GAME_SECTION_GAMEOVER; mSection.subsection = GAME_SECTION_GAMEOVER;
} }
// Actualiza las variables de ayuda
void Game::updateHelper()
{
// Solo ofrece ayuda cuando la amenaza o la velocidad es elevada
if (mMenaceCurrent > 15)
{
if (mPlayer->getCoffees() == 0)
mHelper.needCoffee = true;
else
mHelper.needCoffee = false;
if (!mPlayer->isPowerUp())
mHelper.needCoffeeMachine = true;
else
mHelper.needCoffeeMachine = false;
}
else
{
mHelper.needCoffee = false;
mHelper.needCoffeeMachine = false;
}
}

View File

@@ -65,6 +65,20 @@ private:
Uint8 shakeCounter; // Contador para medir el tiempo que dura el efecto Uint8 shakeCounter; // Contador para medir el tiempo que dura el efecto
}; };
struct helper_t
{
bool needCoffee; // Indica si se necesitan cafes
bool needCoffeeMachine; // Indica si se necesita PowerUp
bool needPowerBall; // Indica si se necesita una PowerBall
int counter; // Contador para no dar ayudas consecutivas
int itemPoints1Odds; // Probabilidad de aparición del objeto
int itemPoints2Odds; // Probabilidad de aparición del objeto
int itemPoints3Odds; // Probabilidad de aparición del objeto
int itemClockOdds; // Probabilidad de aparición del objeto
int itemCoffeeOdds; // Probabilidad de aparición del objeto
int itemCoffeeMachineOdds; // Probabilidad de aparición del objeto
};
SDL_Renderer *mRenderer; // El renderizador de la ventana SDL_Renderer *mRenderer; // El renderizador de la ventana
std::string *mFileList; // Lista de ficheros con los recursos std::string *mFileList; // Lista de ficheros con los recursos
std::string *mTextStrings; // Vector con los textos del juego std::string *mTextStrings; // Vector con los textos del juego
@@ -126,6 +140,7 @@ private:
JA_Sound mSoundBubble4; // Sonido para cuando el jugador muere JA_Sound mSoundBubble4; // Sonido para cuando el jugador muere
JA_Sound mSoundClock; // Sonido para cuando se detiene el tiempo con el item reloj JA_Sound mSoundClock; // Sonido para cuando se detiene el tiempo con el item reloj
JA_Sound mSoundPowerBall; // Sonido para cuando se explota una Power Ball JA_Sound mSoundPowerBall; // Sonido para cuando se explota una Power Ball
JA_Sound mSoundCollision; // Sonido para cuando la máquina de café toca el suelo
JA_Music mMusicPlaying; // Musica de fondo JA_Music mMusicPlaying; // Musica de fondo
@@ -158,7 +173,9 @@ private:
Uint8 mEnemyDeployCounter; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero Uint8 mEnemyDeployCounter; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero
float mEnemySpeed; // Velocidad a la que se mueven los enemigos float mEnemySpeed; // Velocidad a la que se mueven los enemigos
effect_t mEffect; // Variable para gestionar los efectos visuales effect_t mEffect; // Variable para gestionar los efectos visuales
helper_t mHelper; // Variable para gestionar las ayudas
bool mPowerBallEnabled; // Indica si hay una powerball ya activa bool mPowerBallEnabled; // Indica si hay una powerball ya activa
bool mCoffeeMachineEnabled; // Indica si hay una máquina de café en el terreno de juego
Uint8 mPostFade; // Qué hacer al acabar el fade Uint8 mPostFade; // Qué hacer al acabar el fade
float mSin[360]; // Vector con los valores del seno para 360 grados float mSin[360]; // Vector con los valores del seno para 360 grados
bool mGameCompleted; // Indica si se ha completado la partida, llegando al final de la ultima pantalla bool mGameCompleted; // Indica si se ha completado la partida, llegando al final de la ultima pantalla
@@ -471,6 +488,9 @@ public:
// Actualiza el tramo final de juego, una vez completado // Actualiza el tramo final de juego, una vez completado
void updateGameCompleted(); void updateGameCompleted();
// Actualiza las variables de ayuda
void updateHelper();
}; };
#endif #endif

View File

@@ -29,6 +29,7 @@ void Item::init(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *
mVelY = -4.0f; mVelY = -4.0f;
mAccelX = 0.0f; mAccelX = 0.0f;
mAccelY = 0.2f; mAccelY = 0.2f;
mStatus = 0;
mCollider.r = mWidth / 2; mCollider.r = mWidth / 2;
shiftColliders(); shiftColliders();
@@ -83,7 +84,8 @@ void Item::init(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *
case ITEM_COFFEE_MACHINE: case ITEM_COFFEE_MACHINE:
mWidth = 32; mWidth = 32;
mHeight = 32; mHeight = 32;
mPosX = (rand() % (PLAY_AREA_WIDTH - mWidth - 3)) + 3; //mPosX = (rand() % (PLAY_AREA_WIDTH - mWidth - 3)) + 3;
mPosX = (((int)x + (PLAY_AREA_WIDTH / 2)) % (PLAY_AREA_WIDTH - mWidth));
mPosY = PLAY_AREA_TOP - mHeight; mPosY = PLAY_AREA_TOP - mHeight;
mVelX = 0.0f; mVelX = 0.0f;
mVelY = -2.0f; mVelY = -2.0f;
@@ -142,6 +144,8 @@ void Item::render()
// Actualiza la posición y estados del globo // Actualiza la posición y estados del globo
void Item::move() void Item::move()
{ {
mStatus = 0;
// Calcula la nueva posición // Calcula la nueva posición
mPosX += mVelX; mPosX += mVelX;
mPosY += mVelY; mPosY += mVelY;
@@ -182,6 +186,7 @@ void Item::move()
mAccelX = 0; mAccelX = 0;
mAccelY = 0; mAccelY = 0;
mPosY = PLAY_AREA_BOTTOM - mHeight; mPosY = PLAY_AREA_BOTTOM - mHeight;
if (mClass == ITEM_COFFEE_MACHINE) mStatus = 1;
} }
// Actualiza la posición del sprite // Actualiza la posición del sprite
@@ -196,7 +201,7 @@ void Item::erase()
} }
// Actualiza el objeto a su posicion, animación y controla los contadores // Actualiza el objeto a su posicion, animación y controla los contadores
void Item::update() int Item::update()
{ {
if (mEnabled) if (mEnabled)
{ {
@@ -206,6 +211,8 @@ void Item::update()
updateTimeToLive(); updateTimeToLive();
checkTimeToLive(); checkTimeToLive();
} }
return mStatus;
} }
// Actualiza el contador // Actualiza el contador

View File

@@ -9,6 +9,26 @@
// Clase AnimatedSprite // Clase AnimatedSprite
class Item class Item
{ {
private:
float mPosX; // Posición X del objeto
float mPosY; // Posición Y del objeto
Uint8 mWidth; // Ancho del objeto
Uint8 mHeight; // Alto del objeto
float mVelX; // Velocidad en el eje X
float mVelY; // Velocidad en el eje Y
float mAccelX; // Aceleración en el eje X
float mAccelY; // Aceleración en el eje Y
int mStatus; // Contiene mensajes de estado
AnimatedSprite *mSprite; // Sprite con los graficos del objeto
Uint8 mClass; // Especifica el tipo de objeto que es
bool mEnabled; // Especifica si el objeto está habilitado
circle_t mCollider; // Circulo de colisión del objeto
// Alinea el circulo de colisión con la posición del objeto
void shiftColliders();
public: public:
// Constructor // Constructor
Item(); Item();
@@ -32,7 +52,7 @@ public:
void erase(); void erase();
// Actualiza al objeto a su posicion, animación y controla los contadores // Actualiza al objeto a su posicion, animación y controla los contadores
void update(); int update();
// Actualiza el contador // Actualiza el contador
void updateTimeToLive(); void updateTimeToLive();
@@ -66,38 +86,6 @@ public:
// Temporizador con el tiempo que el objeto está presente // Temporizador con el tiempo que el objeto está presente
Uint16 mTimeToLive; Uint16 mTimeToLive;
private:
// Posición X,Y del objeto
float mPosX;
float mPosY;
// Alto y ancho del objeto
Uint8 mWidth;
Uint8 mHeight;
// Variables para controlar la velocidad del objeto
float mVelX;
float mVelY;
// Aceleración
float mAccelX;
float mAccelY;
// Sprite con los graficos del objeto
AnimatedSprite *mSprite;
// Especifica el tipo de objeto que es
Uint8 mClass;
// Especifica si está habilitado el objeto
bool mEnabled;
// Circulo de colisión del objeto
circle_t mCollider;
// Alinea el circulo de colisión con la posición del objeto
void shiftColliders();
}; };
#endif #endif

View File

@@ -268,7 +268,7 @@ const std::string gTextStrings[MAX_TEXT_STRINGS][3] =
// 50 - TEXTO DE COMPLETAR EL JUEGO // 50 - TEXTO DE COMPLETAR EL JUEGO
{"FELICIDADES!!", {"FELICIDADES!!",
"FELICITATS!!", "FELICITATS!!",
"CONGRATULATIONS!!"}, "NICE!!"},
}; };