Trabajando en los globos

This commit is contained in:
2022-10-03 04:15:04 +02:00
parent 80ca04fd64
commit 9c35fadd55
14 changed files with 309 additions and 173 deletions

View File

@@ -2,22 +2,11 @@
#include "balloon.h"
// Constructor
Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture, SDL_Renderer *renderer)
Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture, std::string file, SDL_Renderer *renderer)
{
mSprite = new AnimatedSprite();
mSprite = new AnimatedSprite(texture, renderer, file);
disable();
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:
@@ -42,22 +31,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
// Amenaza que genera el globo
mMenace = 1;
// Establece los frames de cada animación
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
{
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 50 + OFFSET_ORANGE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
}
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
{
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 50 + OFFSET_BLUE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
}
for (int i = 0; i < NUM_FRAMES_BALLON_POP; i++)
{
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 50 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
}
break;
case BALLOON_2:
@@ -82,16 +55,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
// Amenaza que genera el globo
mMenace = 2;
// Establece los frames de cada animación
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_ORANGE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_BLUE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
for (int i = 0; i < NUM_FRAMES_BALLON_POP; i++)
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
break;
case BALLOON_3:
@@ -116,16 +79,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
// Amenaza que genera el globo
mMenace = 4;
// Establece los frames de cada animación
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_ORANGE_BALLOONS, 37 * i, getWidth(), getHeight());
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_BLUE_BALLOONS, 37 * i, getWidth(), getHeight());
for (int i = 0; i < NUM_FRAMES_BALLON_POP; i++)
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
break;
case BALLOON_4:
@@ -150,16 +103,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
// Amenaza que genera el globo
mMenace = 8;
// Establece los frames de cada animación
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, OFFSET_ORANGE_BALLOONS, 37 * i, getWidth(), getHeight());
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, OFFSET_BLUE_BALLOONS, 37 * i, getWidth(), getHeight());
for (int i = 0; i < NUM_FRAMES_BALLON_POP; i++)
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
break;
case HEXAGON_1:
@@ -184,16 +127,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
// Amenaza que genera el globo
mMenace = 1;
// Establece los frames de cada animación
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 50 + OFFSET_GREEN_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 50 + OFFSET_PURPLE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
for (int 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:
@@ -218,16 +151,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
// Amenaza que genera el globo
mMenace = 2;
// Establece los frames de cada animación
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_GREEN_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_PURPLE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
for (int 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:
@@ -252,16 +175,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
// Amenaza que genera el globo
mMenace = 4;
// Establece los frames de cada animación
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_GREEN_BALLOONS, 37 * i, getWidth(), getHeight());
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_PURPLE_BALLOONS, 37 * i, getWidth(), getHeight());
for (int 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:
@@ -286,16 +199,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
// Amenaza que genera el globo
mMenace = 8;
// Establece los frames de cada animación
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, OFFSET_GREEN_BALLOONS, 37 * i, getWidth(), getHeight());
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, OFFSET_PURPLE_BALLOONS, 37 * i, getWidth(), getHeight());
for (int i = 0; i < NUM_FRAMES_BALLON_POP; i++)
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
break;
case POWER_BALL:
@@ -320,20 +223,11 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
// Amenaza que genera el globo
mMenace = 0;
// Establece los frames de cada animación
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, OFFSET_POWER_BALL, 37 * i, getWidth(), getHeight());
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, OFFSET_POWER_BALL, 37 * i, getWidth(), getHeight());
for (int i = 0; i < NUM_FRAMES_BALLON_POP; i++)
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
// Añade rotación al sprite
mSprite->setRotate(false);
mSprite->setRotateSpeed(1);
mSprite->setRotateAmount(2.0);
break;
default:
@@ -357,12 +251,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
mBouncing.w = {1.10f, 1.05f, 1.00f, 0.95f, 0.90f, 0.95f, 1.00f, 1.02f, 1.05f, 1.02f};
mBouncing.h = {0.90f, 0.95f, 1.00f, 1.05f, 1.10f, 1.05f, 1.00f, 0.98f, 0.95f, 0.98f};
// Textura con los gráficos del sprite
mSprite->setTexture(texture);
// Renderizador
mSprite->setRenderer(renderer);
// Alto y ancho del sprite
mSprite->setWidth(mWidth);
mSprite->setHeight(mHeight);
@@ -401,25 +289,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
// Tipo
mKind = kind;
// Inicializa las variables para la animación
// mSprite->setCurrentFrame(0);
// mSprite->setAnimationCounter(0);
// Establece el numero de frames de cada animacion
// mSprite->setAnimationNumFrames(BALLOON_MOVING_ANIMATION, NUM_FRAMES_BALLON);
// mSprite->setAnimationNumFrames(BALLOON_POP_ANIMATION, NUM_FRAMES_BALLON_POP);
// mSprite->setAnimationNumFrames(BALLOON_BORN_ANIMATION, NUM_FRAMES_BALLON_BORN);
// Establece la velocidad de cada animación
mSprite->setAnimationSpeed(BALLOON_MOVING_ANIMATION, 10);
mSprite->setAnimationSpeed(BALLOON_POP_ANIMATION, 5);
mSprite->setAnimationSpeed(BALLOON_BORN_ANIMATION, 20);
// Establece si la animación se reproduce en bucle
mSprite->setAnimationLoop(BALLOON_MOVING_ANIMATION, true);
mSprite->setAnimationLoop(BALLOON_POP_ANIMATION, false);
mSprite->setAnimationLoop(BALLOON_BORN_ANIMATION, true);
// Selecciona un frame para pintar
mSprite->setSpriteClip(mSprite->getAnimationClip(0, 0));
}
@@ -428,7 +297,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
Balloon::~Balloon()
{
delete mSprite;
mSprite = nullptr;
}
// Centra el globo en la posición X
@@ -640,9 +508,13 @@ void Balloon::updateState()
disable();
}
else if (mTimeToLive > 0)
{
mTimeToLive--;
}
else
{
disable();
}
}
// Si se está creando
@@ -690,9 +562,13 @@ void Balloon::updateState()
{
mSprite->setRotate(true);
if (mVelX > 0.0f)
{
mSprite->setRotateAmount(2.0);
}
else
{
mSprite->setRotateAmount(-2.0);
}
}
}
}
@@ -718,15 +594,15 @@ void Balloon::updateAnimation()
// Establece el frame de animación
if (isPopping())
{
mSprite->setCurrentAnimation(BALLOON_POP_ANIMATION);
mSprite->setCurrentAnimation("pop");
}
else if (isBeingCreated())
{
mSprite->setCurrentAnimation(BALLOON_BORN_ANIMATION);
mSprite->setCurrentAnimation("blue");
}
else
{
mSprite->setCurrentAnimation(BALLOON_MOVING_ANIMATION);
mSprite->setCurrentAnimation("orange");
}
mSprite->animate();
@@ -796,11 +672,17 @@ Uint8 Balloon::getSize()
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
@@ -922,9 +804,13 @@ void Balloon::updateColliders()
Uint8 Balloon::getMenace()
{
if (isEnabled())
{
return mMenace;
}
else
{
return 0;
}
}
// Obtiene le valor de la variable
@@ -968,6 +854,8 @@ void Balloon::updateBounce()
mBouncing.despY = (mSprite->getSpriteClip().h - (mSprite->getSpriteClip().h * mBouncing.zoomH));
mBouncing.counter++;
if ((mBouncing.counter / mBouncing.speed) > (MAX_BOUNCE - 1))
{
bounceStop();
}
}
}