Los items ya parecen funcionar. revisar power ball y los puntos al coger items

This commit is contained in:
2022-10-03 14:11:13 +02:00
parent 91b868572e
commit 99b61c4b2d
5 changed files with 32 additions and 63 deletions

View File

@@ -7,11 +7,11 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
mSprite = new AnimatedSprite(texture, renderer, file);
disable();
mEnabled = true;
switch (kind)
{
case BALLOON_1:
mEnabled = true;
// Alto y ancho del objeto
mWidth = BALLOON_WIDTH_1;
mHeight = BALLOON_WIDTH_1;
@@ -34,8 +34,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
break;
case BALLOON_2:
mEnabled = true;
// Alto y ancho del objeto
mWidth = BALLOON_WIDTH_2;
mHeight = BALLOON_WIDTH_2;
@@ -58,8 +56,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
break;
case BALLOON_3:
mEnabled = true;
// Alto y ancho del objeto
mWidth = BALLOON_WIDTH_3;
mHeight = BALLOON_WIDTH_3;
@@ -82,8 +78,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
break;
case BALLOON_4:
mEnabled = true;
// Alto y ancho del objeto
mWidth = BALLOON_WIDTH_4;
mHeight = BALLOON_WIDTH_4;
@@ -106,8 +100,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
break;
case HEXAGON_1:
mEnabled = true;
// Alto y ancho del objeto
mWidth = BALLOON_WIDTH_1;
mHeight = BALLOON_WIDTH_1;
@@ -130,8 +122,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
break;
case HEXAGON_2:
mEnabled = true;
// Alto y ancho del objeto
mWidth = BALLOON_WIDTH_2;
mHeight = BALLOON_WIDTH_2;
@@ -154,8 +144,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
break;
case HEXAGON_3:
mEnabled = true;
// Alto y ancho del objeto
mWidth = BALLOON_WIDTH_3;
mHeight = BALLOON_WIDTH_3;
@@ -178,8 +166,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
break;
case HEXAGON_4:
mEnabled = true;
// Alto y ancho del objeto
mWidth = BALLOON_WIDTH_4;
mHeight = BALLOON_WIDTH_4;
@@ -202,8 +188,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
break;
case POWER_BALL:
mEnabled = true;
// Alto y ancho del objeto
mWidth = BALLOON_WIDTH_4;
mHeight = BALLOON_WIDTH_4;
@@ -231,8 +215,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
break;
default:
mEnabled = false;
mMenace = 0;
break;
}
@@ -456,7 +438,7 @@ void Balloon::disable()
mSpeed = 0;
mStopped = false;
mStoppedCounter = 0;
mTimeToLive = 0;
//mTimeToLive = 0;
mTravelY = 0;
mVelX = 0.0f;
mVelY = 0.0f;
@@ -469,9 +451,7 @@ void Balloon::disable()
void Balloon::pop()
{
setPopping(true);
mSprite->setAnimationCounter(0);
mSprite->disableRotate();
setTimeToLive(120);
setStop(true);
setStoppedTimer(2000);
setInvulnerable(true);
@@ -503,18 +483,18 @@ void Balloon::updateState()
setStop(true);
if (mSprite->animationIsCompleted())
{
mSprite->setAnimationCompleted(BALLOON_POP_ANIMATION, false);
mTimeToLive = 0;
//mSprite->setAnimationCompleted(BALLOON_POP_ANIMATION, false);
//mTimeToLive = 0;
disable();
}
else if (mTimeToLive > 0)
/*else if (mTimeToLive > 0)
{
mTimeToLive--;
}
else
{
disable();
}
}*/
}
// Si se está creando
@@ -757,18 +737,6 @@ bool Balloon::isPopping()
return mPopping;
}
// Establece el valor de la variable
void Balloon::setTimeToLive(Uint16 time)
{
mTimeToLive = time;
}
// Obtiene del valor de la variable
Uint16 Balloon::getTimeToLive()
{
return mTimeToLive;
}
// Establece el valor de la variable
void Balloon::setStoppedTimer(Uint16 time)
{

View File

@@ -107,7 +107,7 @@ private:
Uint16 mCreationCounterIni; // Valor inicial para el temporizador para controlar el estado "creandose"
Uint16 mScore; // Puntos que da el globo al ser destruido
Uint16 mStoppedCounter; // Contador para controlar el estado "parado"
Uint16 mTimeToLive; // Indica el tiempo de vida que le queda al globo
//Uint16 mTimeToLive; // Indica el tiempo de vida que le queda al globo
Uint8 mKind; // Tipo de globo
Uint8 mMenace; // Cantidad de amenaza que genera el globo
Uint32 mCounter; // Contador interno
@@ -138,12 +138,6 @@ private:
// Establece el valor de la variable
void setBeingCreated(bool state);
// Establece el valor de la variable
void setTimeToLive(Uint16 time);
// Obtiene del valor de la variable
Uint16 getTimeToLive();
public:
// Constructor
Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture, std::string file, SDL_Renderer *renderer);

View File

@@ -2165,7 +2165,6 @@ void Game::checkPlayerItemCollision(Player *player)
}
for (auto item : items)
// for (int i = 0; i < MAX_ITEMS; i++)
{
if (item->isEnabled())
{
@@ -2214,6 +2213,7 @@ void Game::checkPlayerItemCollision(Player *player)
default:
break;
}
item->disable();
}
}
@@ -2255,12 +2255,12 @@ void Game::checkBulletBalloonCollision()
{
if (droppeditem != ITEM_COFFEE_MACHINE)
{
createItem(balloon->getPosX(), balloon->getPosY(), droppeditem);
createItem(droppeditem, balloon->getPosX(), balloon->getPosY());
JA_PlaySound(mSoundItemDrop);
}
else
{
createItem(players.at(index)->getPosX(), 0, droppeditem);
createItem(droppeditem, players.at(index)->getPosX(), 0);
mCoffeeMachineEnabled = true;
}
}
@@ -2326,11 +2326,14 @@ void Game::updateItems()
{
for (auto item : items)
{
item->update();
if (item->isOnFloor())
if (item->isEnabled())
{
JA_PlaySound(mSoundCollision);
mEffect.shake = true;
item->update();
if (item->isOnFloor())
{
JA_PlaySound(mSoundCollision);
mEffect.shake = true;
}
}
}
}
@@ -2354,22 +2357,30 @@ Uint8 Game::dropItem()
{
case 0:
if (luckyNumber < mHelper.itemPoints1Odds)
{
return ITEM_POINTS_1_DISK;
}
break;
case 1:
if (luckyNumber < mHelper.itemPoints2Odds)
{
return ITEM_POINTS_2_GAVINA;
}
break;
case 2:
if (luckyNumber < mHelper.itemPoints3Odds)
{
return ITEM_POINTS_3_PACMAR;
}
break;
case 3:
if (luckyNumber < mHelper.itemClockOdds)
{
return ITEM_CLOCK;
}
break;
case 4:
@@ -2415,8 +2426,8 @@ Uint8 Game::dropItem()
// Crea un objeto item
void Game::createItem(Uint8 type, float x, float y)
{
Item *i = new Item(mRenderer, mAsset, type, x, y);
items.push_back(i);
Item *item = new Item(mRenderer, mAsset, type, x, y);
items.push_back(item);
}
// Vacia el vector de items

View File

@@ -190,13 +190,10 @@ void Item::disable()
// Actualiza el objeto a su posicion, animación y controla los contadores
void Item::update()
{
if (enabled)
{
move();
sprite->animate();
updateTimeToLive();
checkTimeToLive();
}
move();
sprite->animate();
updateTimeToLive();
checkTimeToLive();
}
// Actualiza el contador

View File

@@ -21,7 +21,6 @@ class Item
{
private:
// Objetos
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
AnimatedSprite *sprite; // Sprite con los graficos del objeto
LTexture *texture; // Objeto con los graficos del item