v1.4
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
Balloon::Balloon()
|
||||
{
|
||||
mSprite = new AnimatedSprite();
|
||||
init(0, 0, NO_KIND, BALLOON_VELX_POSITIVE, 0, nullptr, nullptr);
|
||||
disable();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -15,29 +15,34 @@ Balloon::~Balloon()
|
||||
}
|
||||
|
||||
// Inicializador
|
||||
void Balloon::init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer, LTexture *texture, SDL_Renderer *renderer)
|
||||
void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
const Uint8 NUM_FRAMES_BALLON = 10;
|
||||
const Uint8 NUM_FRAMES_BALLON_POP = 12;
|
||||
const Uint8 NUM_FRAMES_BALLON_BORN = 10;
|
||||
|
||||
const Uint8 OFFSET_ORANGE_BALLOONS = 58 * 0;
|
||||
const Uint8 OFFSET_BLUE_BALLOONS = 58 * 1;
|
||||
const Uint8 OFFSET_GREEN_BALLOONS = 58 * 2;
|
||||
const Uint8 OFFSET_PURPLE_BALLOONS = 58 * 3;
|
||||
const Uint8 OFFSET_POWER_BALL = 58 * 4;
|
||||
const int OFFSET_EXPLOSIONS = 58 * 5;
|
||||
|
||||
switch (kind)
|
||||
{
|
||||
case BALLOON_1:
|
||||
// Posición inicial
|
||||
mPosX = x;
|
||||
mPosY = y;
|
||||
mEnabled = true;
|
||||
|
||||
// Alto y ancho del objeto
|
||||
mWidth = 8;
|
||||
mHeight = mWidth;
|
||||
mWidth = BALLOON_SIZE_1;
|
||||
mHeight = BALLOON_SIZE_1;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
mVelX = velx;
|
||||
mVelY = 0;
|
||||
mMaxVelY = 3;
|
||||
mMaxVelY = 3.0f;
|
||||
mGravity = 0.09f;
|
||||
mDefaultVelY = 3;
|
||||
mDefaultVelY = 2.6f;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
mScore = 50;
|
||||
@@ -47,35 +52,29 @@ void Balloon::init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer,
|
||||
|
||||
// Establece los frames de cada animación
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||
{
|
||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 50, 21 + (37 * i), getWidth(), getHeight());
|
||||
}
|
||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 50 + OFFSET_ORANGE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||
{
|
||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 50 + 58, 21 + (37 * i), getWidth(), getHeight());
|
||||
}
|
||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 50 + OFFSET_BLUE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||
{
|
||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 50 + 58 + 58, 21 + (37 * i), getWidth(), getHeight());
|
||||
}
|
||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 50 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
|
||||
|
||||
break;
|
||||
|
||||
case BALLOON_2:
|
||||
// Posición inicial
|
||||
mPosX = x;
|
||||
mPosY = y;
|
||||
mEnabled = true;
|
||||
|
||||
// Alto y ancho del objeto
|
||||
mWidth = 13;
|
||||
mHeight = mWidth;
|
||||
mWidth = BALLOON_SIZE_2;
|
||||
mHeight = BALLOON_SIZE_2;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
mVelX = velx;
|
||||
mVelY = 0;
|
||||
mMaxVelY = 3;
|
||||
mMaxVelY = 3.0f;
|
||||
mGravity = 0.10f;
|
||||
mDefaultVelY = 4;
|
||||
mDefaultVelY = 3.5f;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
mScore = 100;
|
||||
@@ -85,35 +84,29 @@ void Balloon::init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer,
|
||||
|
||||
// Establece los frames de cada animación
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||
{
|
||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37, 21 + (37 * i), getWidth(), getHeight());
|
||||
}
|
||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_ORANGE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||
{
|
||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + 58, 21 + (37 * i), getWidth(), getHeight());
|
||||
}
|
||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_BLUE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||
{
|
||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + 58 + 58, 21 + (37 * i), getWidth(), getHeight());
|
||||
}
|
||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
|
||||
|
||||
break;
|
||||
|
||||
case BALLOON_3:
|
||||
// Posición inicial
|
||||
mPosX = x;
|
||||
mPosY = y;
|
||||
mEnabled = true;
|
||||
|
||||
// Alto y ancho del objeto
|
||||
mWidth = 21;
|
||||
mHeight = mWidth;
|
||||
mWidth = BALLOON_SIZE_3;
|
||||
mHeight = BALLOON_SIZE_3;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
mVelX = velx;
|
||||
mVelY = 0;
|
||||
mMaxVelY = 3;
|
||||
mMaxVelY = 3.0f;
|
||||
mGravity = 0.10f;
|
||||
mDefaultVelY = 4.5;
|
||||
mDefaultVelY = 4.50f;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
mScore = 200;
|
||||
@@ -123,35 +116,29 @@ void Balloon::init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer,
|
||||
|
||||
// Establece los frames de cada animación
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||
{
|
||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37, 37 * i, getWidth(), getHeight());
|
||||
}
|
||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_ORANGE_BALLOONS, 37 * i, getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||
{
|
||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + 58, 37 * i, getWidth(), getHeight());
|
||||
}
|
||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_BLUE_BALLOONS, 37 * i, getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||
{
|
||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + 58 + 58, 37 * i, getWidth(), getHeight());
|
||||
}
|
||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
|
||||
|
||||
break;
|
||||
|
||||
case BALLOON_4:
|
||||
// Posición inicial
|
||||
mPosX = x;
|
||||
mPosY = y;
|
||||
mEnabled = true;
|
||||
|
||||
// Alto y ancho del objeto
|
||||
mWidth = 37;
|
||||
mHeight = mWidth;
|
||||
mWidth = BALLOON_SIZE_4;
|
||||
mHeight = BALLOON_SIZE_4;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
mVelX = velx;
|
||||
mVelY = 0;
|
||||
mMaxVelY = 3;
|
||||
mMaxVelY = 3.0f;
|
||||
mGravity = 0.10f;
|
||||
mDefaultVelY = 5;
|
||||
mDefaultVelY = 4.95f;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
mScore = 400;
|
||||
@@ -161,35 +148,157 @@ void Balloon::init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer,
|
||||
|
||||
// Establece los frames de cada animación
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||
{
|
||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 0, 37 * i, getWidth(), getHeight());
|
||||
}
|
||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, OFFSET_ORANGE_BALLOONS, 37 * i, getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||
{
|
||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 58, 37 * i, getWidth(), getHeight());
|
||||
}
|
||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, OFFSET_BLUE_BALLOONS, 37 * i, getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||
{
|
||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 58 + 58, 37 * i, getWidth(), getHeight());
|
||||
}
|
||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
// Posición inicial
|
||||
mPosX = x;
|
||||
mPosY = y;
|
||||
case HEXAGON_1:
|
||||
mEnabled = true;
|
||||
|
||||
// Alto y ancho del objeto
|
||||
mWidth = 0;
|
||||
mHeight = mWidth;
|
||||
mWidth = BALLOON_SIZE_1;
|
||||
mHeight = BALLOON_SIZE_1;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
mVelX = velx;
|
||||
mVelY = abs(velx) * 2;
|
||||
mMaxVelY = abs(velx) * 2;
|
||||
mGravity = 0.00f;
|
||||
mDefaultVelY = abs(velx) * 2;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
mScore = 50;
|
||||
|
||||
// Amenaza que genera el globo
|
||||
mMenace = 1;
|
||||
|
||||
// Establece los frames de cada animación
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 50 + OFFSET_GREEN_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 50 + OFFSET_PURPLE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 50 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
|
||||
|
||||
break;
|
||||
|
||||
case HEXAGON_2:
|
||||
mEnabled = true;
|
||||
|
||||
// Alto y ancho del objeto
|
||||
mWidth = BALLOON_SIZE_2;
|
||||
mHeight = BALLOON_SIZE_2;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
mVelX = velx;
|
||||
mVelY = abs(velx) * 2;
|
||||
mMaxVelY = abs(velx) * 2;
|
||||
mGravity = 0.00f;
|
||||
mDefaultVelY = abs(velx) * 2;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
mScore = 100;
|
||||
|
||||
// Amenaza que genera el globo
|
||||
mMenace = 2;
|
||||
|
||||
// Establece los frames de cada animación
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_GREEN_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_PURPLE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
|
||||
|
||||
break;
|
||||
|
||||
case HEXAGON_3:
|
||||
mEnabled = true;
|
||||
|
||||
// Alto y ancho del objeto
|
||||
mWidth = BALLOON_SIZE_3;
|
||||
mHeight = BALLOON_SIZE_3;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
mVelX = velx;
|
||||
mVelY = abs(velx) * 2;
|
||||
mMaxVelY = abs(velx) * 2;
|
||||
mGravity = 0.00f;
|
||||
mDefaultVelY = abs(velx) * 2;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
mScore = 200;
|
||||
|
||||
// Amenaza que genera el globo
|
||||
mMenace = 4;
|
||||
|
||||
// Establece los frames de cada animación
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_GREEN_BALLOONS, 37 * i, getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_PURPLE_BALLOONS, 37 * i, getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
|
||||
|
||||
break;
|
||||
|
||||
case HEXAGON_4:
|
||||
mEnabled = true;
|
||||
|
||||
// Alto y ancho del objeto
|
||||
mWidth = BALLOON_SIZE_4;
|
||||
mHeight = BALLOON_SIZE_4;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
mVelX = velx;
|
||||
mVelY = abs(velx) * 2;
|
||||
mMaxVelY = abs(velx) * 2;
|
||||
mGravity = 0.00f;
|
||||
mDefaultVelY = abs(velx) * 2;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
mScore = 400;
|
||||
|
||||
// Amenaza que genera el globo
|
||||
mMenace = 8;
|
||||
|
||||
// Establece los frames de cada animación
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, OFFSET_GREEN_BALLOONS, 37 * i, getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, OFFSET_PURPLE_BALLOONS, 37 * i, getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
|
||||
|
||||
break;
|
||||
|
||||
case POWER_BALL:
|
||||
mEnabled = true;
|
||||
|
||||
// Alto y ancho del objeto
|
||||
mWidth = BALLOON_SIZE_4;
|
||||
mHeight = BALLOON_SIZE_4;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
mVelX = velx;
|
||||
mVelY = 0;
|
||||
mMaxVelY = 0;
|
||||
mGravity = 0;
|
||||
mDefaultVelY = 0;
|
||||
mMaxVelY = 3.0f;
|
||||
mGravity = 0.10f;
|
||||
mDefaultVelY = 4.95f;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
mScore = 0;
|
||||
@@ -198,13 +307,35 @@ void Balloon::init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer,
|
||||
mMenace = 0;
|
||||
|
||||
// Establece los frames de cada animación
|
||||
mSprite->setAnimationFrames(0, 0, 0, 0, getWidth(), getHeight());
|
||||
mSprite->setAnimationFrames(1, 0, 0, 0, getWidth(), getHeight());
|
||||
mSprite->setAnimationFrames(2, 0, 0, 0, getWidth(), getHeight());
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, OFFSET_POWER_BALL, 37 * i, getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, OFFSET_BLUE_BALLOONS, 37 * i, getWidth(), getHeight());
|
||||
|
||||
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
mEnabled = false;
|
||||
mMenace = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// Posición inicial
|
||||
mPosX = x;
|
||||
mPosY = y;
|
||||
|
||||
mBouncing.enabled = false; // Si el efecto está activo
|
||||
mBouncing.counter = 0; // Countador para el efecto
|
||||
mBouncing.speed = 0; // Velocidad a la que transcurre el efecto
|
||||
mBouncing.zoomW = 1.0f; // Zoom aplicado a la anchura
|
||||
mBouncing.zoomH = 1.0f; // Zoom aplicado a la altura
|
||||
mBouncing.despX = 0.0f; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom
|
||||
mBouncing.despY = 0.0f;
|
||||
|
||||
// Textura con los gráficos del sprite
|
||||
mSprite->setTexture(texture);
|
||||
|
||||
@@ -216,14 +347,14 @@ void Balloon::init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer,
|
||||
mSprite->setHeight(mHeight);
|
||||
|
||||
// Posición X,Y del sprite
|
||||
mSprite->setPosX(int(mPosX));
|
||||
mSprite->setPosY(mPosY);
|
||||
mSprite->setPosX((int)mPosX);
|
||||
mSprite->setPosY((int)mPosY);
|
||||
|
||||
// Tamaño del circulo de colisión
|
||||
mCollider.r = mWidth / 2;
|
||||
|
||||
// Alinea el circulo de colisión con el objeto
|
||||
shiftColliders();
|
||||
updateColliders();
|
||||
|
||||
// Inicializa variables
|
||||
mStopped = true;
|
||||
@@ -242,6 +373,9 @@ void Balloon::init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer,
|
||||
mBouncing.zoomH = 1;
|
||||
mBouncing.despX = 0;
|
||||
mBouncing.despY = 0;
|
||||
mCounter = 0;
|
||||
mTravelY = 1.0f;
|
||||
mSpeed = speed;
|
||||
|
||||
// Tipo
|
||||
mKind = kind;
|
||||
@@ -288,16 +422,17 @@ void Balloon::allignTo(int x)
|
||||
mSprite->setPosY(getPosY());
|
||||
|
||||
// Alinea el circulo de colisión con el objeto
|
||||
shiftColliders();
|
||||
updateColliders();
|
||||
}
|
||||
|
||||
// Pinta el globo en la pantalla
|
||||
void Balloon::render()
|
||||
{
|
||||
if (mVisible)
|
||||
if ((mVisible) && (mEnabled))
|
||||
{
|
||||
if (mBouncing.enabled)
|
||||
{
|
||||
// Aplica desplazamiento para el zoom
|
||||
mSprite->setPosX(getPosX() + mBouncing.despX);
|
||||
mSprite->setPosY(getPosY() + mBouncing.despY);
|
||||
mSprite->render();
|
||||
@@ -306,7 +441,8 @@ void Balloon::render()
|
||||
}
|
||||
else if (isBeingCreated())
|
||||
{
|
||||
mSprite->getTexture()->setAlpha(255 - (int)((float)mCreationCounter * (255.0f/(float)mCreationCounterIni)));
|
||||
// Aplica alpha blending
|
||||
mSprite->getTexture()->setAlpha(255 - (int)((float)mCreationCounter * (255.0f / (float)mCreationCounterIni)));
|
||||
mSprite->render();
|
||||
mSprite->getTexture()->setAlpha(255);
|
||||
}
|
||||
@@ -320,127 +456,116 @@ void Balloon::render()
|
||||
// Actualiza la posición y estados del globo
|
||||
void Balloon::move()
|
||||
{
|
||||
// Comprobamos si se puede mover
|
||||
if (isStopped() == false)
|
||||
// Comprueba si se puede mover
|
||||
if (!isStopped())
|
||||
{
|
||||
// Lo movemos a izquierda o derecha
|
||||
mPosX += mVelX;
|
||||
// Lo mueve a izquierda o derecha
|
||||
mPosX += (mVelX * mSpeed);
|
||||
|
||||
// Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido
|
||||
if ((mPosX < PLAY_AREA_LEFT) || (mPosX + mWidth > PLAY_AREA_RIGHT))
|
||||
{
|
||||
// Corregir posición
|
||||
mPosX -= mVelX;
|
||||
// Corrige posición
|
||||
mPosX -= (mVelX * mSpeed);
|
||||
|
||||
// Invertir sentido
|
||||
// Invierte sentido
|
||||
mVelX = -mVelX;
|
||||
|
||||
// Activa el efecto de rebote
|
||||
bounceStart();
|
||||
}
|
||||
|
||||
// Mueve el globo hacia arriba o hacia abajo
|
||||
mPosY += int(mVelY);
|
||||
mPosY += (mVelY * mSpeed);
|
||||
|
||||
// Si se sale por arriba
|
||||
if (mPosY < PLAY_AREA_TOP)
|
||||
{
|
||||
// Corregimos
|
||||
mPosY -= int(mVelY);
|
||||
// Corrige
|
||||
mPosY = PLAY_AREA_TOP;
|
||||
|
||||
// Invertimos sentido
|
||||
// Invierte sentido
|
||||
mVelY = -mVelY;
|
||||
|
||||
// Activa el efecto de rebote
|
||||
bounceStart();
|
||||
}
|
||||
|
||||
// Si el globo se sale por la parte inferior
|
||||
if (mPosY + mHeight > PLAY_AREA_BOTTOM)
|
||||
{
|
||||
// Corregimos
|
||||
//mPosY -= int(mVelY);
|
||||
// Corrige
|
||||
mPosY = PLAY_AREA_BOTTOM - mHeight;
|
||||
|
||||
// Invertimos colocando una velocidad por defecto
|
||||
// Invierte colocando una velocidad por defecto
|
||||
mVelY = -mDefaultVelY;
|
||||
|
||||
// Activa el efecto de rebote
|
||||
bounceStart();
|
||||
}
|
||||
|
||||
// Aplica gravedad al objeto, sin pasarse de un limite establecido
|
||||
if (int(mVelY) > mMaxVelY)
|
||||
{
|
||||
mVelY = float(mMaxVelY);
|
||||
}
|
||||
else
|
||||
/*
|
||||
Para aplicar la gravedad, el diseño original la aplicaba en cada iteración del bucle
|
||||
Al añadir el modificador de velocidad se reduce la distancia que recorre el objeto y por
|
||||
tanto recibe mas gravedad. Para solucionarlo se va a aplicar la gravedad cuando se haya
|
||||
recorrido una distancia igual a la velocidad en Y, que era el cálculo inicial
|
||||
*/
|
||||
|
||||
// Incrementa la variable que calcula la distancia acumulada en Y
|
||||
mTravelY += mSpeed;
|
||||
|
||||
// Si la distancia acumulada en Y es igual a la velocidad, se aplica la gravedad
|
||||
if (mTravelY >= 1.0f)
|
||||
{
|
||||
// Quita el excedente
|
||||
mTravelY -= 1.0f;
|
||||
|
||||
// Aplica la gravedad al objeto sin pasarse de una velocidad máxima
|
||||
mVelY += mGravity;
|
||||
std::min(mVelY, mMaxVelY);
|
||||
}
|
||||
// Aplica la gravedad al objeto
|
||||
//if (mVelY > mMaxVelY)
|
||||
// mVelY = mMaxVelY;
|
||||
//else if (mCounter % 1 == 0)
|
||||
// mVelY += mGravity;
|
||||
|
||||
// Actualiza la posición del sprite
|
||||
mSprite->setPosX(getPosX());
|
||||
mSprite->setPosY(mPosY);
|
||||
}
|
||||
// Si no se puede mover:
|
||||
// Comprobar si se está creando
|
||||
else if (isBeingCreated() == true)
|
||||
{
|
||||
// Actualiza el valor de las variables
|
||||
setStop(true);
|
||||
setInvulnerable(true);
|
||||
|
||||
// Todavia tiene tiempo en el contador
|
||||
if (mCreationCounter > 0)
|
||||
{
|
||||
// Desplaza lentamente el globo hacia abajo y hacia un lado
|
||||
if (mCreationCounter % 10 == 0)
|
||||
{
|
||||
++mPosY;
|
||||
mPosX += mVelX;
|
||||
|
||||
// Actualiza la posición del sprite
|
||||
mSprite->setPosX(getPosX());
|
||||
mSprite->setPosY(mPosY);
|
||||
|
||||
// Actualiza la posición del circulo de colisión
|
||||
shiftColliders();
|
||||
}
|
||||
|
||||
// Hace visible el globo de forma intermitente
|
||||
if (mCreationCounter > 100)
|
||||
{
|
||||
setVisible(mCreationCounter / 10 % 2 == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
setVisible(mCreationCounter / 5 % 2 == 0);
|
||||
}
|
||||
|
||||
--mCreationCounter;
|
||||
}
|
||||
// El contador ha llegado a cero
|
||||
else
|
||||
{
|
||||
setBeingCreated(false);
|
||||
setStop(false);
|
||||
setVisible(true);
|
||||
setInvulnerable(false);
|
||||
}
|
||||
}
|
||||
// Comprobar si está detenido
|
||||
else if (isStopped() == true)
|
||||
{
|
||||
// Si todavía está detenido, reduce el contador
|
||||
if (mStoppedCounter > 0)
|
||||
{
|
||||
--mStoppedCounter;
|
||||
} // Si el contador ha llegado a cero, ya no está detenido
|
||||
else
|
||||
{
|
||||
setStop(false);
|
||||
}
|
||||
mSprite->setPosY(getPosY());
|
||||
}
|
||||
}
|
||||
|
||||
// Pone a cero todos los valores del globo
|
||||
void Balloon::erase()
|
||||
// Deshabilita el globo y pone a cero todos los valores
|
||||
void Balloon::disable()
|
||||
{
|
||||
init(0, 0, NO_KIND, 0, 0, nullptr, nullptr);
|
||||
mEnabled = false;
|
||||
|
||||
mPosX = 0.0f;
|
||||
mPosY = 0.0f;
|
||||
mWidth = 0;
|
||||
mHeight = 0;
|
||||
mVelX = 0.0f;
|
||||
mVelY = 0.0f;
|
||||
mGravity = 0.0f;
|
||||
mDefaultVelY = 0.0f;
|
||||
mMaxVelY = 0.0f;
|
||||
mBeingCreated = false;
|
||||
mBlinking = false;
|
||||
mInvulnerable = false;
|
||||
mPopping = false;
|
||||
mStopped = false;
|
||||
mVisible = false;
|
||||
mCollider.x = 0;
|
||||
mCollider.y = 0;
|
||||
mCollider.r = 0;
|
||||
mCreationCounter = 0;
|
||||
mCreationCounterIni = 0;
|
||||
mScore = 0;
|
||||
mStoppedCounter = 0;
|
||||
mTimeToLive = 0;
|
||||
mKind = 0;
|
||||
mMenace = 0;
|
||||
}
|
||||
|
||||
// Explosiona el globo
|
||||
@@ -458,64 +583,124 @@ void Balloon::pop()
|
||||
// Actualiza al globo a su posicion, animación y controla los contadores
|
||||
void Balloon::update()
|
||||
{
|
||||
move();
|
||||
setAnimation();
|
||||
shiftColliders();
|
||||
bounceUpdate();
|
||||
if (mEnabled)
|
||||
{
|
||||
move();
|
||||
updateAnimation();
|
||||
updateColliders();
|
||||
updateState();
|
||||
updateBounce();
|
||||
mCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza los estados del globo
|
||||
void Balloon::updateState()
|
||||
{
|
||||
// Si está explotando
|
||||
if (isPopping())
|
||||
{
|
||||
setInvulnerable(true);
|
||||
setStop(true);
|
||||
if (mTimeToLive > 0)
|
||||
if (mSprite->isCompleted(BALLOON_POP_ANIMATION))
|
||||
{
|
||||
--mTimeToLive;
|
||||
mSprite->setCompleted(BALLOON_POP_ANIMATION, false);
|
||||
mTimeToLive = 0;
|
||||
disable();
|
||||
}
|
||||
else if (mTimeToLive > 0)
|
||||
mTimeToLive--;
|
||||
else
|
||||
disable();
|
||||
}
|
||||
|
||||
// Si se está creando
|
||||
if (isBeingCreated())
|
||||
{
|
||||
// Actualiza el valor de las variables
|
||||
setStop(true);
|
||||
setInvulnerable(true);
|
||||
|
||||
// Todavia tiene tiempo en el contador
|
||||
if (mCreationCounter > 0)
|
||||
{
|
||||
// Desplaza lentamente el globo hacia abajo y hacia un lado
|
||||
if (mCreationCounter % 10 == 0)
|
||||
{
|
||||
mPosY++;
|
||||
mPosX += mVelX;
|
||||
|
||||
// Comprueba no se salga por los laterales
|
||||
if ((mPosX < PLAY_AREA_LEFT) || (mPosX > (PLAY_AREA_RIGHT - mWidth)))
|
||||
{
|
||||
// Corrige y cambia el sentido de la velocidad
|
||||
mPosX -= mVelX;
|
||||
mVelX = -mVelX;
|
||||
}
|
||||
|
||||
// Actualiza la posición del sprite
|
||||
mSprite->setPosX(getPosX());
|
||||
mSprite->setPosY(getPosY());
|
||||
|
||||
// Actualiza la posición del circulo de colisión
|
||||
updateColliders();
|
||||
}
|
||||
|
||||
// Hace visible el globo de forma intermitente
|
||||
//if (mCreationCounter > 100)
|
||||
// setVisible(mCreationCounter / 10 % 2 == 0);
|
||||
//else
|
||||
// setVisible(mCreationCounter / 5 % 2 == 0);
|
||||
|
||||
mCreationCounter--;
|
||||
}
|
||||
// El contador ha llegado a cero
|
||||
else
|
||||
{
|
||||
erase();
|
||||
setBeingCreated(false);
|
||||
setStop(false);
|
||||
setVisible(true);
|
||||
setInvulnerable(false);
|
||||
}
|
||||
}
|
||||
// Solo comprueba el estado detenido cuando no se está creando
|
||||
else if (isStopped())
|
||||
{
|
||||
// Si está detenido, reduce el contador
|
||||
if (mStoppedCounter > 0)
|
||||
mStoppedCounter--;
|
||||
// Si el contador ha llegado a cero, ya no está detenido
|
||||
else if (!isPopping()) // Quitarles el estado "detenido" si no estan explosionandoxq
|
||||
setStop(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Establece la animación correspondiente al estado
|
||||
void Balloon::setAnimation()
|
||||
void Balloon::updateAnimation()
|
||||
{
|
||||
// Establece el frame de animación
|
||||
if (isPopping())
|
||||
{
|
||||
mSprite->animate(BALLOON_POP_ANIMATION);
|
||||
}
|
||||
else if (isBeingCreated())
|
||||
{
|
||||
mSprite->animate(BALLOON_BORN_ANIMATION);
|
||||
}
|
||||
else
|
||||
{
|
||||
mSprite->animate(BALLOON_MOVING_ANIMATION);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba si el globo tiene algun tipo asignado
|
||||
bool Balloon::isActive()
|
||||
// Comprueba si el globo está habilitado
|
||||
bool Balloon::isEnabled()
|
||||
{
|
||||
if (mKind == NO_KIND)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return mEnabled;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
int Balloon::getPosX()
|
||||
float Balloon::getPosX()
|
||||
{
|
||||
return int(mPosX);
|
||||
return mPosX;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
int Balloon::getPosY()
|
||||
float Balloon::getPosY()
|
||||
{
|
||||
return mPosY;
|
||||
}
|
||||
@@ -544,12 +729,29 @@ void Balloon::setVelY(float velY)
|
||||
mVelY = velY;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Balloon::setSpeed(float speed)
|
||||
{
|
||||
mSpeed = speed;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
int Balloon::getKind()
|
||||
{
|
||||
return mKind;
|
||||
}
|
||||
|
||||
// Obtiene la clase a la que pertenece el globo
|
||||
Uint8 Balloon::getClass()
|
||||
{
|
||||
if ((mKind >= BALLOON_1) && (mKind <= BALLOON_4))
|
||||
return BALLOON_CLASS;
|
||||
else if ((mKind >= HEXAGON_1) && (mKind <= HEXAGON_4))
|
||||
return HEXAGON_CLASS;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Balloon::setStop(bool state)
|
||||
{
|
||||
@@ -653,13 +855,13 @@ Uint16 Balloon::getScore()
|
||||
}
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
Circle &Balloon::getCollider()
|
||||
circle_t &Balloon::getCollider()
|
||||
{
|
||||
return mCollider;
|
||||
}
|
||||
|
||||
// Alinea el circulo de colisión con la posición del objeto globo
|
||||
void Balloon::shiftColliders()
|
||||
void Balloon::updateColliders()
|
||||
{
|
||||
// Align collider to center of balloon
|
||||
mCollider.x = Uint16(mPosX + mCollider.r);
|
||||
@@ -669,7 +871,10 @@ void Balloon::shiftColliders()
|
||||
// Obtiene le valor de la variable
|
||||
Uint8 Balloon::getMenace()
|
||||
{
|
||||
return mMenace;
|
||||
if (isEnabled())
|
||||
return mMenace;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Balloon::bounceStart()
|
||||
@@ -686,14 +891,14 @@ void Balloon::bounceStop()
|
||||
{
|
||||
mBouncing.enabled = false;
|
||||
mBouncing.counter = 0;
|
||||
mBouncing.zoomW = 1;
|
||||
mBouncing.zoomH = 1;
|
||||
mBouncing.zoomW = 1.0f;
|
||||
mBouncing.zoomH = 1.0f;
|
||||
mSprite->setZoomW(mBouncing.zoomW);
|
||||
mSprite->setZoomH(mBouncing.zoomH);
|
||||
mBouncing.despX = 0;
|
||||
mBouncing.despY = 0;
|
||||
mBouncing.despX = 0.0f;
|
||||
mBouncing.despY = 0.0f;
|
||||
}
|
||||
void Balloon::bounceUpdate()
|
||||
void Balloon::updateBounce()
|
||||
{
|
||||
if (mBouncing.enabled)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user