code reorganized
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
Balloon::Balloon()
|
||||
{
|
||||
mSprite = new AnimatedSprite();
|
||||
init(0, 0, NO_KIND, BALLON_VELX_POSITIVE, 0, nullptr, nullptr);
|
||||
init(0, 0, NO_KIND, BALLOON_VELX_POSITIVE, 0, nullptr, nullptr);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -227,13 +227,21 @@ void Balloon::init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer,
|
||||
|
||||
// Inicializa variables
|
||||
mStopped = true;
|
||||
mStoppedTimer = 0;
|
||||
mStoppedCounter = 0;
|
||||
mBlinking = false;
|
||||
mVisible = true;
|
||||
mInvulnerable = false;
|
||||
mBeingCreated = true;
|
||||
mCreationTimer = creationtimer;
|
||||
mCreationCounter = creationtimer;
|
||||
mCreationCounterIni = creationtimer;
|
||||
mPopping = false;
|
||||
mBouncing.enabled = false;
|
||||
mBouncing.counter = 0;
|
||||
mBouncing.speed = 2;
|
||||
mBouncing.zoomW = 1;
|
||||
mBouncing.zoomH = 1;
|
||||
mBouncing.despX = 0;
|
||||
mBouncing.despY = 0;
|
||||
|
||||
// Tipo
|
||||
mKind = kind;
|
||||
@@ -288,7 +296,24 @@ void Balloon::render()
|
||||
{
|
||||
if (mVisible)
|
||||
{
|
||||
mSprite->render();
|
||||
if (mBouncing.enabled)
|
||||
{
|
||||
mSprite->setPosX(getPosX() + mBouncing.despX);
|
||||
mSprite->setPosY(getPosY() + mBouncing.despY);
|
||||
mSprite->render();
|
||||
mSprite->setPosX(getPosX() - mBouncing.despX);
|
||||
mSprite->setPosY(getPosY() - mBouncing.despY);
|
||||
}
|
||||
else if (isBeingCreated())
|
||||
{
|
||||
mSprite->getTexture()->setAlpha(255 - (int)((float)mCreationCounter * (255.0f/(float)mCreationCounterIni)));
|
||||
mSprite->render();
|
||||
mSprite->getTexture()->setAlpha(255);
|
||||
}
|
||||
else
|
||||
{
|
||||
mSprite->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,10 +353,13 @@ void Balloon::move()
|
||||
if (mPosY + mHeight > PLAY_AREA_BOTTOM)
|
||||
{
|
||||
// Corregimos
|
||||
mPosY -= int(mVelY);
|
||||
//mPosY -= int(mVelY);
|
||||
mPosY = PLAY_AREA_BOTTOM - mHeight;
|
||||
|
||||
// Invertimos colocando una velocidad por defecto
|
||||
mVelY = -mDefaultVelY;
|
||||
|
||||
bounceStart();
|
||||
}
|
||||
|
||||
// Aplica gravedad al objeto, sin pasarse de un limite establecido
|
||||
@@ -357,10 +385,10 @@ void Balloon::move()
|
||||
setInvulnerable(true);
|
||||
|
||||
// Todavia tiene tiempo en el contador
|
||||
if (mCreationTimer > 0)
|
||||
if (mCreationCounter > 0)
|
||||
{
|
||||
// Desplaza lentamente el globo hacia abajo y hacia un lado
|
||||
if (mCreationTimer % 10 == 0)
|
||||
if (mCreationCounter % 10 == 0)
|
||||
{
|
||||
++mPosY;
|
||||
mPosX += mVelX;
|
||||
@@ -374,16 +402,16 @@ void Balloon::move()
|
||||
}
|
||||
|
||||
// Hace visible el globo de forma intermitente
|
||||
if (mCreationTimer > 100)
|
||||
if (mCreationCounter > 100)
|
||||
{
|
||||
setVisible(mCreationTimer / 10 % 2 == 0);
|
||||
setVisible(mCreationCounter / 10 % 2 == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
setVisible(mCreationTimer / 5 % 2 == 0);
|
||||
setVisible(mCreationCounter / 5 % 2 == 0);
|
||||
}
|
||||
|
||||
--mCreationTimer;
|
||||
--mCreationCounter;
|
||||
}
|
||||
// El contador ha llegado a cero
|
||||
else
|
||||
@@ -398,9 +426,9 @@ void Balloon::move()
|
||||
else if (isStopped() == true)
|
||||
{
|
||||
// Si todavía está detenido, reduce el contador
|
||||
if (mStoppedTimer > 0)
|
||||
if (mStoppedCounter > 0)
|
||||
{
|
||||
--mStoppedTimer;
|
||||
--mStoppedCounter;
|
||||
} // Si el contador ha llegado a cero, ya no está detenido
|
||||
else
|
||||
{
|
||||
@@ -433,6 +461,7 @@ void Balloon::update()
|
||||
move();
|
||||
setAnimation();
|
||||
shiftColliders();
|
||||
bounceUpdate();
|
||||
if (isPopping())
|
||||
{
|
||||
setInvulnerable(true);
|
||||
@@ -608,13 +637,13 @@ Uint16 Balloon::getTimeToLive()
|
||||
// Establece el valor de la variable
|
||||
void Balloon::setStoppedTimer(Uint16 time)
|
||||
{
|
||||
mStoppedTimer = time;
|
||||
mStoppedCounter = time;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
Uint16 Balloon::getStoppedTimer()
|
||||
{
|
||||
return mStoppedTimer;
|
||||
return mStoppedCounter;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
@@ -641,4 +670,41 @@ void Balloon::shiftColliders()
|
||||
Uint8 Balloon::getMenace()
|
||||
{
|
||||
return mMenace;
|
||||
}
|
||||
|
||||
void Balloon::bounceStart()
|
||||
{
|
||||
mBouncing.enabled = true;
|
||||
mBouncing.zoomW = 1;
|
||||
mBouncing.zoomH = 1;
|
||||
mSprite->setZoomW(mBouncing.zoomW);
|
||||
mSprite->setZoomH(mBouncing.zoomH);
|
||||
mBouncing.despX = 0;
|
||||
mBouncing.despY = 0;
|
||||
}
|
||||
void Balloon::bounceStop()
|
||||
{
|
||||
mBouncing.enabled = false;
|
||||
mBouncing.counter = 0;
|
||||
mBouncing.zoomW = 1;
|
||||
mBouncing.zoomH = 1;
|
||||
mSprite->setZoomW(mBouncing.zoomW);
|
||||
mSprite->setZoomH(mBouncing.zoomH);
|
||||
mBouncing.despX = 0;
|
||||
mBouncing.despY = 0;
|
||||
}
|
||||
void Balloon::bounceUpdate()
|
||||
{
|
||||
if (mBouncing.enabled)
|
||||
{
|
||||
mBouncing.zoomW = mBouncing.w[mBouncing.counter / mBouncing.speed];
|
||||
mBouncing.zoomH = mBouncing.h[mBouncing.counter / mBouncing.speed];
|
||||
mSprite->setZoomW(mBouncing.zoomW);
|
||||
mSprite->setZoomH(mBouncing.zoomH);
|
||||
mBouncing.despX = (mSprite->getSpriteClip().w - (mSprite->getSpriteClip().w * mBouncing.zoomW));
|
||||
mBouncing.despY = (mSprite->getSpriteClip().h - (mSprite->getSpriteClip().h * mBouncing.zoomH));
|
||||
mBouncing.counter++;
|
||||
if ((mBouncing.counter / mBouncing.speed) > (MAX_BOUNCE - 1))
|
||||
bounceStop();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user