This commit is contained in:
2021-03-17 12:34:11 +01:00
parent a3e608b01e
commit 965ed711f7
22 changed files with 2081 additions and 839 deletions

BIN
media/.DS_Store vendored

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

@@ -24,6 +24,7 @@ void AnimatedSprite::init(LTexture *texture, SDL_Renderer *renderer)
mAnimation[i].numFrames = 0;
mAnimation[i].speed = 0;
mAnimation[i].loop = true;
mAnimation[i].completed = false;
for (Uint8 j = 0; i < 20; i++)
{
mAnimation[i].frames[j].x = 0;
@@ -105,6 +106,18 @@ void AnimatedSprite::setAnimationLoop(Uint8 index, bool loop)
mAnimation[index].loop = loop;
}
// Establece el valor de la variable
void AnimatedSprite::setCompleted(Uint8 index, bool value)
{
mAnimation[index].completed = value;
}
// Comprueba si ha terminado la animación
bool AnimatedSprite::isCompleted(Uint8 index)
{
return mAnimation[index].completed;
}
// Devuelve el rectangulo de una animación y frame concreto
SDL_Rect AnimatedSprite::getAnimationClip(Uint8 index_animation, Uint8 index_frame)
{

View File

@@ -5,9 +5,26 @@
#ifndef ANIMATEDSPRITE_H
#define ANIMATEDSPRITE_H
#define MAX_FRAMES 30
#define MAX_ANIMATIONS 20
// Clase AnimatedSprite
class AnimatedSprite : public MovingSprite
{
private:
struct sAnimation
{
SDL_Rect frames[MAX_FRAMES]; // Cada uno de los frames que componen la animación
Uint8 numFrames; // Numero de frames que componen la animación
Uint8 speed; // Velocidad de la animación
bool loop; // Indica si la animación se reproduce en bucle
bool completed; // Indica si ha finalizado la animación
};
sAnimation mAnimation[MAX_ANIMATIONS]; // Vector con las diferentes animaciones
Uint8 mCurrentFrame; // Frame actual
Uint16 mAnimationCounter; // Contador para las animaciones
public:
// Constructor
AnimatedSprite();
@@ -39,26 +56,14 @@ public:
// Establece si la animación se reproduce en bucle
void setAnimationLoop(Uint8 index, bool loop);
// Establece el valor de la variable
void setCompleted(Uint8 index, bool value);
// Comprueba si ha terminado la animación
bool isCompleted(Uint8 index);
// Devuelve el rectangulo de una animación y frame concreto
SDL_Rect getAnimationClip(Uint8 index_animation, Uint8 index_frame);
private:
struct sAnimation
{
SDL_Rect frames[20]; // Hasta 20 frames
Uint8 numFrames;
Uint8 speed;
bool loop;
};
// Vector con las diferentes animaciones y los diferentes frames de cada animación
sAnimation mAnimation[20]; // Hasta 20 animaciones
// Frame actual
Uint8 mCurrentFrame;
// Contador para las animaciones
Uint16 mAnimationCounter;
};
#endif

View File

@@ -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)
{

View File

@@ -11,33 +11,34 @@
class Balloon
{
private:
float mPosX; // Posición en el eje X
int mPosY; // Posición en el eje Y
Uint8 mWidth; // Ancho
Uint8 mHeight; // Alto
float mVelX; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
float mVelY; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
float mGravity; // Aceleración en el eje Y. Modifica la velocidad
float mDefaultVelY; // Velocidad inicial que tienen al rebotar contra el suelo
int mMaxVelY; // Máxima velocidad que puede alcanzar el objeto en el eje Y
float mPosX; // Posición en el eje X
float mPosY; // Posición en el eje Y
Uint8 mWidth; // Ancho
Uint8 mHeight; // Alto
float mVelX; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
float mVelY; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
float mGravity; // Aceleración en el eje Y. Modifica la velocidad
float mDefaultVelY; // Velocidad inicial que tienen al rebotar contra el suelo
float mMaxVelY; // Máxima velocidad que puede alcanzar el objeto en el eje Y
AnimatedSprite *mSprite; // Sprite del objeto globo
bool mBeingCreated; // Indica si el globo se está creando
bool mBlinking; // Indica si el globo está intermitente
bool mEnabled; // Indica si el globo esta activo
bool mInvulnerable; // Indica si el globo es invulnerable
bool mPopping; // Indica si el globo está explotando
bool mStopped; // Indica si el globo está parado
bool mVisible; // Indica si el globo es visible
Circle mCollider; // Circulo de colisión del objeto
circle_t mCollider; // Circulo de colisión del objeto
Uint16 mCreationCounter; // Temporizador para controlar el estado "creandose"
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
Uint8 mKind; // Tipo de globo
Uint8 mMenace; // Cantidad de amenaza que genera el globo
Uint8 mMenace; // Cantidad de amenaza que genera el globo
Uint32 mCounter; // Contador interno
float mTravelY; // Distancia que ha de recorrer el globo en el eje Y antes de que se le aplique la gravedad
float mSpeed; // Velocidad a la que se mueven los globos
struct bouncing // Estructura para las variables para el efecto de los rebotes
{
@@ -53,13 +54,17 @@ private:
float w[MAX_BOUNCE] = {1.10f, 1.05f, 1.00f, 0.95f, 0.90f, 0.95f, 1.00f, 1.02f, 1.05f, 1.02f};
float h[MAX_BOUNCE] = {0.90f, 0.95f, 1.00f, 1.05f, 1.10f, 1.05f, 1.00f, 0.98f, 0.95f, 0.98f};
};
bouncing mBouncing;
void shiftColliders(); // Alinea el circulo de colisión con la posición del objeto globo
void bounceStart(); // Activa el efecto
void bounceStop(); // Detiene el efecto
void bounceUpdate(); // Aplica el efecto
void updateColliders(); // Alinea el circulo de colisión con la posición del objeto globo
void bounceStart(); // Activa el efecto
void bounceStop(); // Detiene el efecto
void updateBounce(); // Aplica el efecto
void updateState(); // Actualiza los estados del globo
void updateAnimation(); // Establece la animación correspondiente
void setBeingCreated(bool state); // Establece el valor de la variable
void setTimeToLive(Uint16 time); // Establece el valor de la variable
Uint16 getTimeToLive(); // Obtiene del valor de la variable
public:
// Constructor
@@ -69,7 +74,7 @@ public:
~Balloon();
// Inicializador
void init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer, LTexture *texture, SDL_Renderer *renderer);
void init(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture, SDL_Renderer *renderer);
// Centra el globo en la posición X
void allignTo(int x);
@@ -80,8 +85,8 @@ public:
// Actualiza la posición y estados del globo
void move();
// Pone a cero todos los valores del globo
void erase();
// Deshabilita el globo y pone a cero todos los valores
void disable();
// Explosiona el globo
void pop();
@@ -89,17 +94,14 @@ public:
// Actualiza al globo a su posicion, animación y controla los contadores
void update();
// Establece la animación correspondiente
void setAnimation();
// Comprueba si el globo tiene algun tipo asignado
bool isActive();
// Comprueba si el globo está habilitado
bool isEnabled();
// Obtiene del valor de la variable
int getPosX();
float getPosX();
// Obtiene del valor de la variable
int getPosY();
float getPosY();
// Obtiene del valor de la variable
float getVelY();
@@ -113,9 +115,15 @@ public:
// Establece el valor de la variable
void setVelY(float velY);
// Establece el valor de la variable
void setSpeed(float speed);
// Obtiene del valor de la variable
int getKind();
// Obtiene la clase a la que pertenece el globo
Uint8 getClass();
// Establece el valor de la variable
void setStop(bool state);
@@ -140,9 +148,6 @@ public:
// Obtiene del valor de la variable
bool isInvulnerable();
// Establece el valor de la variable
void setBeingCreated(bool state);
// Obtiene del valor de la variable
bool isBeingCreated();
@@ -152,12 +157,6 @@ public:
// Obtiene del valor de la variable
bool isPopping();
// Establece el valor de la variable
void setTimeToLive(Uint16 time);
// Obtiene del valor de la variable
Uint16 getTimeToLive();
// Establece el valor de la variable
void setStoppedTimer(Uint16 time);
@@ -168,7 +167,7 @@ public:
Uint16 getScore();
// Obtiene el circulo de colisión
Circle &getCollider();
circle_t &getCollider();
// Obtiene le valor de la variable
Uint8 getMenace();

View File

@@ -200,7 +200,7 @@ int Bullet::getKind()
}
// Obtiene el circulo de colisión
Circle &Bullet::getCollider()
circle_t &Bullet::getCollider()
{
return mCollider;
}

View File

@@ -49,7 +49,7 @@ public:
int getKind();
// Obtiene el circulo de colisión
Circle &getCollider();
circle_t &getCollider();
private:
// Posición X/Y del objeto
@@ -71,7 +71,7 @@ private:
Sprite *mSprite;
// Balloon's collision circle
Circle mCollider;
circle_t mCollider;
// Alinea el circulo de colisión con el objeto
void shiftColliders();

View File

@@ -75,7 +75,7 @@ const int VIEW_HEIGHT = SCREEN_HEIGHT * 3;
// Cantidad de enteros a escribir en los ficheros de datos
#define TOTAL_SCORE_DATA 3
#define TOTAL_DEMO_DATA 2000
#define TOTAL_DEMO_DATA 2000
// Zona de juego
const int PLAY_AREA_TOP = (0 * BLOCK);
@@ -85,6 +85,8 @@ const int PLAY_AREA_RIGHT = SCREEN_WIDTH - (0 * BLOCK);
const int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
const int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
const int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
const int PLAY_AREA_CENTER_FIRST_QUARTER_X = (PLAY_AREA_WIDTH / 4);
const int PLAY_AREA_CENTER_THIRD_QUARTER_X = (PLAY_AREA_WIDTH / 4) * 3;
const int PLAY_AREA_CENTER_Y = PLAY_AREA_TOP + (PLAY_AREA_HEIGHT / 2);
const int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
const int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
@@ -127,12 +129,6 @@ const int SCREEN_THIRD_QUARTER_Y = (SCREEN_HEIGHT / 4) * 3;
#define PLAYER_ANIMATION_BODY_FIRING_RIGHT 3
#define PLAYER_ANIMATION_BODY_WALKING_STOP 4
#define PLAYER_ANIMATION_BODY_FIRING_UP 5
#define PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT 6
#define PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT 7
#define PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT 8
#define PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT 9
#define PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT 10
#define PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT 11
// Variables del jugador
#define PLAYER_INVULNERABLE_COUNTER 200
@@ -208,6 +204,15 @@ const int MULTIPLIER_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
#define BALLOON_2 2
#define BALLOON_3 3
#define BALLOON_4 4
#define HEXAGON_1 5
#define HEXAGON_2 6
#define HEXAGON_3 7
#define HEXAGON_4 8
#define POWER_BALL 9
// Clases de globo
#define BALLOON_CLASS 0
#define HEXAGON_CLASS 1
// Velocidad del globo
#define BALLOON_VELX_POSITIVE 0.7f
@@ -219,7 +224,20 @@ const int MULTIPLIER_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
#define BALLOON_BORN_ANIMATION 2
// Cantidad posible de globos
#define MAX_BALLOONS 75
#define MAX_BALLOONS 100
// Velocidades a las que se mueven los enemigos
#define BALLOON_SPEED_1 0.60f
#define BALLOON_SPEED_2 0.70f
#define BALLOON_SPEED_3 0.80f
#define BALLOON_SPEED_4 0.90f
#define BALLOON_SPEED_5 1.00f
// Tamaño de los globos
#define BALLOON_SIZE_1 8
#define BALLOON_SIZE_2 13
#define BALLOON_SIZE_3 21
#define BALLOON_SIZE_4 37
// Tipos de bala
#define BULLET_UP 1
@@ -236,6 +254,7 @@ const int MULTIPLIER_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
#define ITEM_CLOCK 4
#define ITEM_TNT 5
#define ITEM_COFFEE 6
#define ITEM_POWER_BALL 7
// Cantidad de objetos simultaneos
#define MAX_ITEMS 5
@@ -280,5 +299,6 @@ const int MULTIPLIER_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
#define STAGE_COUNTER 200
#define INSTRUCTIONS_COUNTER 600
#define DEATH_COUNTER 350
#define SHAKE_COUNTER 10
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -39,7 +39,7 @@ private:
CoffeeDrop *mCoffeeDrop[MAX_COFFEE_DROPS]; // Vector con todas ls gotas de café;
#endif
struct text
struct text_t
{
Text *white; // Texto blanco de 8x8
Text *whiteX2; // Texto blanco de 16x16
@@ -47,9 +47,9 @@ private:
Text *blackX2; // Texto negro de 16x16
Text *nokia; // Texto de anchura variable y 10px de alto
};
text mText; // Variable con todos los objetos de texto
text_t mText; // Variable con todos los objetos de texto
struct menu
struct menu_t
{
Menu *title; // Menu de la pantalla de título
Menu *pause; // Menú de la pantalla de pausa
@@ -58,29 +58,70 @@ private:
Menu *active; // Menu activo (de momento para la pantalla del titulo)
bool keyPressed; // Variable para evitar la repetición de teclas en los menus
};
menu mMenu; // Variable con todos los objetos menus y sus variables
menu_t mMenu; // Variable con todos los objetos menus y sus variables
struct intro
struct intro_t
{
SmartSprite *bitmap[INTRO_TOTAL_BITMAPS]; // Vector con los sprites inteligentes para los dibujos de la intro
Text2 *text[INTRO_TOTAL_TEXTS]; // Textos de la intro
Uint8 events[INTRO_TOTAL_EVENTS]; // Vector para coordinar los eventos de la intro
};
intro mIntro; // Contiene todas las variables de la sección 'Intro'
intro_t mIntro; // Contiene todas las variables de la sección 'Intro'
struct game
struct enemyInits_t
{
int x; // Posición en el eje X donde crear al enemigo
int y; // Posición en el eje Y donde crear al enemigo
float velX; // Velocidad inicial en el eje X
Uint8 kind; // Tipo de enemigo
Uint16 creationCounter; // Temporizador para la creación del enemigo
};
struct enemyFormation_t // Contiene la información de una formación enemiga
{
Uint8 numberOfEnemies; // Cantidad de enemigos que forman la formación
enemyInits_t init[50]; // Vector con todas las inicializaciones de los enemigos de la formación
};
enemyFormation_t mEnemyFormation[100]; // Vector con todas las formaciones enemigas
struct enemyPool_t
{
enemyFormation_t *set[10]; // Conjunto de formaciones enemigas
};
enemyPool_t mEnemyPool[10]; // Variable con los diferentes conjuntos de formaciones enemigas
struct stage_t // Contiene todas las variables relacionadas con una fase
{
enemyPool_t *enemyPool; // El conjunto de formaciones enemigas de la fase
Uint16 currentPower; // Cantidad actual de poder
Uint16 powerToComplete; // Cantidad de poder que se necesita para completar la fase
Uint8 maxMenace; // Umbral máximo de amenaza de la fase
Uint8 minMenace; // Umbral mínimo de amenaza de la fase
Uint8 number; // Numero de fase
};
struct effect_t
{
bool flash; // Indica si se ha de pintar la pantalla de blanco
bool shake; // Indica si se ha de agitar la pantalla
Uint8 shakeCounter; // Contador para medir el tiempo que dura el efecto
};
struct game_t
{
Uint32 score; // Puntuación actual
Uint32 hiScore; // Puntuación máxima
Uint8 section; // Seccion actual dentro del juego
bool hiScoreAchieved; // Indica si se ha superado la puntuación máxima
Uint8 stage; // Pantalla actual
Uint8 stageCounter; // Contador para el tiempo visible del texto de Stage
float stagePath[STAGE_COUNTER]; // Vector con los puntos Y por donde pasará la etiqueta
Uint8 currentStage; // Indica la fase actual
stage_t stage[10]; // Variable con los datos de cada pantalla
Uint8 stageBitmapCounter; // Contador para el tiempo visible del texto de Stage
float stageBitmapPath[STAGE_COUNTER]; // Vector con los puntos Y por donde se desplaza el texto
float getReadyBitmapPath[STAGE_COUNTER]; // Vector con los puntos X por donde se desplaza el texto
Uint16 deathCounter; // Contador para la animación de muerte del jugador
Uint8 deathIndex; // Indice del vector de smartsprites que contiene el sprite del jugador
Uint8 menaceLevelCurrent; // Nivel de amenaza actual
Uint8 menaceLevelThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el numero de globos
Uint8 menaceCurrent; // Nivel de amenaza actual
Uint8 menaceThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el numero de globos
bool timeStopped; // Indica si el tiempo está detenido
Uint16 timeStoppedCounter; // Temporizador para llevar la cuenta del tiempo detenido
Uint8 remainingExplosions; // Cantidad de explosiones restantes
@@ -88,26 +129,34 @@ private:
bool explosionTime; // Indica si las explosiones estan en marcha
Uint32 counter; // Contador para el juego
Uint32 scoreDataFile[TOTAL_SCORE_DATA]; // Datos del fichero de puntos
SmartSprite *getReadyBitmap; // Sprite para el texto de GetReady del principio de la partida
Sprite *getReadyBitmap; // Sprite para el texto de GetReady del principio de la partida
SmartSprite *_1000Bitmap; // Sprite con el texto 1.000
SmartSprite *_2500Bitmap; // Sprite con el texto 2.500
SmartSprite *_5000Bitmap; // Sprite con el texto 5.000
Sprite *background; // Sprite con los graficos frontales del fondo
Sprite *gradient; // Sprite con los graficos del degradado de color de fondo
SDL_Rect gradientRect[4]; // Vector con las coordenadas de los 4 gradientes
Uint16 balloonsPopped; // Lleva la cuenta de los globos explotados
MovingSprite *clouds1a; // Sprite para las nubes superiores
MovingSprite *clouds1b; // Sprite para las nubes superiores
MovingSprite *clouds2a; // Sprite para las nubes inferiores
MovingSprite *clouds2b; // Sprite para las nubes inferiores
Sprite *grass; // Sprite para la hierba
Sprite *scoreBoard; // Sprite para el fondo del marcador
Sprite *powerMeter; // Sprite para el medidor de poder de la fase
Player *player; // El jugador
Balloon *balloon[MAX_BALLOONS]; // Vector con los objetos globo
Bullet *bullet[MAX_BULLETS]; // Vector con los objetos bala
Item *item[MAX_ITEMS]; // Vector con los objetos item
SmartSprite *smartSprite[MAX_SMART_SPRITES]; // Vector para almacenar y gestionar SmartSprites
Uint8 lastEnemyDeploy; // Guarda cual ha sido la última formación desplegada para no repetir;
Uint8 enemyDeployCounter; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero
float enemySpeed; // Velocidad a la que se mueven los enemigos
effect_t effect; // Variable para gestionar los efectos visuales
};
game mGame; // Variable con todas las variables usadas durante el juego
game_t mGame; // Variable con todas las variables usadas durante el juego
struct title
struct title_t
{
Uint16 counter; // Temporizador para la pantalla de titulo
Uint16 backgroundCounter; // Temporizador para el fondo de tiles de la pantalla de titulo
@@ -124,19 +173,19 @@ private:
AnimatedSprite *dustBitmapL; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
AnimatedSprite *dustBitmapR; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
};
title mTitle; // Variable con todas las variables de la pantalla de titulo
title_t mTitle; // Variable con todas las variables de la pantalla de titulo
struct demo
struct demo_t
{
bool enabled; // Indica si está activo el modo demo
bool recording; // Indica si está activado el modo para grabar la demo
Uint16 counter; // Contador para el modo demo
DemoKeys keys; // Variable con las pulsaciones de teclas del modo demo
DemoKeys dataFile[TOTAL_DEMO_DATA]; // Datos del fichero con los movimientos para la demo
bool enabled; // Indica si está activo el modo demo
bool recording; // Indica si está activado el modo para grabar la demo
Uint16 counter; // Contador para el modo demo
demoKeys_t keys; // Variable con las pulsaciones de teclas del modo demo
demoKeys_t dataFile[TOTAL_DEMO_DATA]; // Datos del fichero con los movimientos para la demo
};
demo mDemo; // Variable con todas las variables relacionadas con el modo demo
demo_t mDemo; // Variable con todas las variables relacionadas con el modo demo
struct options
struct options_t
{
Uint32 fullScreenMode; // Contiene el valor del modo de pantalla completa
Uint32 fullScreenModePrevious;
@@ -144,55 +193,63 @@ private:
Uint8 windowSizePrevious;
bool displayCoffeeDrops; // Indica si se han de mostar las gotas de cafe
};
options mOptions; // Variable con todas las variables de las opciones del programa
options_t mOptions; // Variable con todas las variables de las opciones del programa
struct logo
struct logo_t
{
Uint16 counter; // Contador
Sprite *sprite; // Sprite con la textura del logo
};
logo mLogo; // Variable con las variables para el logo
logo_t mLogo; // Variable con las variables para el logo
struct prog
struct prog_t
{
bool debug; // Indica si se va a mostrar la información de debug
bool quit; // Indica si hay que salir del programa
Input keyboard; // Almacena los códigos de teclado correspondientes
Input keyboardBuffer; // Buffer para teclas pulsadas
input_t keyboard; // Almacena los códigos de teclado correspondientes
input_t keyboardBuffer; // Buffer para teclas pulsadas
std::string executablePath; // Path del ejecutable
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint8 section; // Sección actual del programa;
Uint8 subsection; // Subseccion dentro de la sección;
Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
};
prog mProg; // Contiene todas las variables globales del programa
prog_t mProg; // Contiene todas las variables globales del programa
struct resourceBinFile
struct debug_t
{
bool enabled; // Indica si se va a mostrar la información de debug
Uint8 enemySet; // Escoge el set enemigo a generar
Uint8 gradR, gradG, gradB; // Colores RGB para modificar el color del gradiente de fondo
float hudW, hudH; // Multiplica el tamaño del hud de debug;
};
debug_t mDebug;
struct resourceBinFile_t
{
std::string file; // Ruta al fichero
};
resourceBinFile mBinFile[TOTAL_BINFILE]; // Todos los ficheros binarios
resourceBinFile_t mBinFile[TOTAL_BINFILE]; // Todos los ficheros binarios
struct resourceSound
struct resourceSound_t
{
std::string file; // Ruta al fichero
JA_Sound sound; // Variable con el sonido
};
resourceSound mSound[TOTAL_SOUND]; // Todos los sonidos
resourceSound_t mSound[TOTAL_SOUND]; // Todos los sonidos
struct resourceMusic
struct resourceMusic_t
{
std::string file; // Ruta al fichero
JA_Music music; // Variable con la música
};
resourceMusic mMusic[TOTAL_MUSIC]; // Todas las músicas
resourceMusic_t mMusic[TOTAL_MUSIC]; // Todas las músicas
struct resourceTexture
struct resourceTexture_t
{
std::string file; // Ruta al fichero
LTexture *texture; // Variable con la textura
};
resourceTexture mTexture[TOTAL_TEXTURE]; // Todos los gráficos
resourceTexture_t mTexture[TOTAL_TEXTURE]; // Todos los gráficos
public:
// Constructor
@@ -294,6 +351,21 @@ public:
// Establece el valor de la variable
void setExecutablePath(std::string path);
// Inicializa las formaciones enemigas
void initEnemyFormations();
// Inicializa los conjuntos de formaciones
void initEnemyPools();
// Inicializa las fases del juego
void initGameStages();
// Crea una formación de enemigos
void deployEnemyFormation();
// Aumenta el poder de la fase
void increaseStageCurrentPower();
// Establece el valor de la variable
void setScore(Uint32 score);
@@ -309,7 +381,10 @@ public:
// Pinta el marcador en pantalla usando un objeto texto
void renderScoreBoard();
// Actualiza el valor de la variable mStage
// Actualiza las variables del jugador
void updatePlayer();
// Actualiza las variables de la fase
void updateStage();
// Actualiza el estado de muerte
@@ -318,8 +393,8 @@ public:
// Renderiza el fade final cuando se acaba la partida
void renderDeathFade();
// Mueve todos los globos activos
void moveBalloons();
// Actualiza los globos
void updateBalloons();
// Pinta en pantalla todos los globos activos
void renderBalloons();
@@ -328,17 +403,38 @@ public:
Uint8 getBalloonFreeIndex();
// Crea un globo nuevo en el vector de globos
Uint8 createNewBalloon(float x, int y, Uint8 kind, float velx, Uint16 stoppedcounter, LTexture *texture);
Uint8 createNewBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 stoppedcounter, LTexture *texture);
// Crea una PowerBall
void createPowerBall();
// Establece a cero todos los valores del vector de objetos globo
void resetBalloons();
// Establece la velocidad de los globos
void setBalloonSpeed(float speed);
// Incrementa la velocidad de los globos
void incBalloonSpeed();
// Decrementa la velocidad de los globos
void decBalloonSpeed();
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
void updateBalloonSpeed();
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
void popBalloon(Uint8 index);
// Explosiona un globo. Lo destruye
void destroyBalloon(Uint8 index);
// Explosiona todos los globos
void popAllBalloons();
// Destruye todos los globos
void destroyAllBalloons();
// Detiene todos los globos
void stopAllBalloons(Uint16 time);
@@ -393,6 +489,15 @@ public:
// Crea un objeto SmartSprite
void createItemScoreSprite(int x, int y, SmartSprite *sprite);
// Crea un objeto de bonus en función del azar
void dropBonus();
// Dibuja el efecto de flash
void renderFlashEffect();
// Actualiza el efecto de agitar la pantalla
void updateShakeEffect();
// Crea un SmartSprite para arrojar el item café al recibir un impacto
void throwCoffee(int x, int y);
@@ -434,10 +539,10 @@ public:
Uint8 getSubsection();
// Calcula y establece el valor de amenaza en funcion de los globos activos
void setMenaceLevel();
void setMenace();
// Obtiene el valor de la variable
Uint8 getMenaceLevel();
Uint8 getMenace();
// Establece el valor de la variable
void setTimeStopped(bool value);
@@ -448,6 +553,9 @@ public:
// Establece el valor de la variable
void setTimeStoppedCounter(Uint16 value);
// Actualiza la variable EnemyDeployCounter
void updateEnemyDeployCounter();
// Actualiza y comprueba el valor de la variable
void updateTimeStoppedCounter();
@@ -464,7 +572,10 @@ public:
void updateRemainingExplosionsCounter();
// Gestiona el nivel de amenaza
void updateMenaceLevel();
void old_updateMenace();
// Gestiona el nivel de amenaza
void updateMenace();
// Actualiza el campo de juego
void updatePlayField();
@@ -514,6 +625,9 @@ public:
// Agita la pantalla
void shakeScreen();
// Agita la pantalla
void shakeScreen2();
// Bucle para el logo del juego
void runLogo();
@@ -535,9 +649,6 @@ public:
// Bucle para la pantalla de game over
void runGameOverScreen();
// Dibuja la informacion de debug en pantalla
void renderDebugInfo();
// Activa el modo Demo
void enableDemoMode();
@@ -546,6 +657,9 @@ public:
// Intercambia el proximo estado del juego despues del titulo
void toogleTitleNextGS();
// Dibuja la informacion de debug en pantalla
void renderDebugInfo();
};
#endif

View File

@@ -251,7 +251,7 @@ void Item::setEnabled(bool value)
}
// Obtiene el circulo de colisión
Circle &Item::getCollider()
circle_t &Item::getCollider()
{
return mCollider;
}

View File

@@ -62,7 +62,7 @@ public:
void setEnabled(bool value);
// Obtiene el circulo de colisión
Circle &getCollider();
circle_t &getCollider();
// Temporizador con el tiempo que el objeto está presente
Uint16 mTimeToLive;
@@ -93,10 +93,8 @@ private:
// Especifica si está habilitado el objeto
bool mEnabled;
// Circulo de colisión del objeto
Circle mCollider;
circle_t mCollider;
// Alinea el circulo de colisión con la posición del objeto
void shiftColliders();

View File

@@ -56,7 +56,7 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
mBaseSpeed = 1.5;
// Establece la puntuación inicial
mScore = 9500;
mScore = 0;
// Establece el multiplicador de puntos inicial
mScoreMultiplier = 1.0f;
@@ -100,12 +100,6 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 4);
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 4);
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 4);
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 4);
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 4);
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 4);
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 4);
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 4);
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 4);
// Establece la velocidad de cada animación
mSpriteLegs->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_STOP, 10);
@@ -118,12 +112,6 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 5);
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_STOP, 10);
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_UP, 5);
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 5);
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 5);
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 5);
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 5);
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 10);
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 5);
// Establece si la animación se reproduce en bucle
mSpriteLegs->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_STOP, true);
@@ -136,12 +124,6 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_RIGHT, true);
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_STOP, true);
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_UP, true);
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, true);
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, true);
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, true);
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, true);
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, true);
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, true);
// Establece los frames de cada animación
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 0, mWidth * 0, mHeight * 0, mWidth, mHeight);
@@ -189,36 +171,6 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 2, mWidth * 2, mHeight * 5, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 3, mWidth * 3, mHeight * 5, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 0, mWidth * 0, mHeight * 6, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 1, mWidth * 1, mHeight * 6, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 2, mWidth * 2, mHeight * 6, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 3, mWidth * 3, mHeight * 6, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 0, mWidth * 0, mHeight * 7, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 1, mWidth * 1, mHeight * 7, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 2, mWidth * 2, mHeight * 7, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 3, mWidth * 3, mHeight * 7, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 0, mWidth * 0, mHeight * 8, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 1, mWidth * 1, mHeight * 8, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 2, mWidth * 2, mHeight * 8, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 3, mWidth * 3, mHeight * 8, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 0, mWidth * 0, mHeight * 9, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 1, mWidth * 1, mHeight * 9, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 2, mWidth * 2, mHeight * 9, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 3, mWidth * 3, mHeight * 9, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 0, mWidth * 0, mHeight * 10, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 1, mWidth * 1, mHeight * 10, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 2, mWidth * 2, mHeight * 10, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 3, mWidth * 3, mHeight * 10, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 0, mWidth * 0, mHeight * 11, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 1, mWidth * 1, mHeight * 11, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 2, mWidth * 2, mHeight * 11, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 3, mWidth * 3, mHeight * 11, mWidth, mHeight);
// Selecciona un frame para pintar
mSpriteLegs->setSpriteClip(mSpriteLegs->getAnimationClip(PLAYER_ANIMATION_LEGS_WALKING_STOP, 0));
mSpriteBody->setSpriteClip(mSpriteBody->getAnimationClip(PLAYER_ANIMATION_BODY_WALKING_STOP, 0));
@@ -231,71 +183,29 @@ void Player::setInput(Uint8 input)
{
case INPUT_LEFT:
mVelX = -mBaseSpeed;
if (mExtraHit)
{
setWalkingStatus(PLAYER_STATUS_WALKING_LEFT);
}
else
{
setWalkingStatus(PLAYER_STATUS_WALKING_LEFT);
}
setWalkingStatus(PLAYER_STATUS_WALKING_LEFT);
break;
case INPUT_RIGHT:
mVelX = mBaseSpeed;
if (mExtraHit)
{
setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT);
}
else
{
setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT);
}
setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT);
break;
case INPUT_FIRE_UP:
if (mExtraHit)
{
setFiringStatus(PLAYER_STATUS_FIRING_UP);
}
else
{
setFiringStatus(PLAYER_STATUS_FIRING_UP);
}
setFiringStatus(PLAYER_STATUS_FIRING_UP);
break;
case INPUT_FIRE_LEFT:
if (mExtraHit)
{
setFiringStatus(PLAYER_STATUS_FIRING_LEFT);
}
else
{
setFiringStatus(PLAYER_STATUS_FIRING_LEFT);
}
setFiringStatus(PLAYER_STATUS_FIRING_LEFT);
break;
case INPUT_FIRE_RIGHT:
if (mExtraHit)
{
setFiringStatus(PLAYER_STATUS_FIRING_RIGHT);
}
else
{
setFiringStatus(PLAYER_STATUS_FIRING_RIGHT);
}
setFiringStatus(PLAYER_STATUS_FIRING_RIGHT);
break;
default:
mVelX = 0;
if (mExtraHit)
{
setWalkingStatus(PLAYER_STATUS_WALKING_STOP);
}
else
{
setWalkingStatus(PLAYER_STATUS_WALKING_STOP);
}
setWalkingStatus(PLAYER_STATUS_WALKING_STOP);
break;
}
}
@@ -309,7 +219,7 @@ void Player::move()
mPosX += mVelX;
// Si el jugador abandona el area de juego por los laterales
if ((mPosX < PLAY_AREA_LEFT) || (mPosX + mWidth > PLAY_AREA_RIGHT))
if ((mPosX < PLAY_AREA_LEFT - 5) || (mPosX + mWidth > PLAY_AREA_RIGHT + 5))
{
// Restaura su posición
mPosX -= mVelX;
@@ -370,6 +280,17 @@ void Player::setFiringStatus(Uint8 status)
// Establece la animación correspondiente al estado
void Player::setAnimation()
{
// Actualiza los frames de la animación en función del número de cafes
for (Uint8 i = 0; i < 4; i++)
{
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, i, mWidth * i, mHeight * (0 + (6 * mCoffees)), mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, i, mWidth * i, mHeight * (1 + (6 * mCoffees)), mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, i, mWidth * i, mHeight * (2 + (6 * mCoffees)), mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, i, mWidth * i, mHeight * (3 + (6 * mCoffees)), mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, i, mWidth * i, mHeight * (4 + (6 * mCoffees)), mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, i, mWidth * i, mHeight * (5 + (6 * mCoffees)), mWidth, mHeight);
}
switch (mStatusWalking)
{
case PLAYER_STATUS_WALKING_LEFT:
@@ -377,51 +298,19 @@ void Player::setAnimation()
switch (mStatusFiring)
{
case PLAYER_STATUS_FIRING_UP:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
break;
case PLAYER_STATUS_FIRING_LEFT:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
break;
case PLAYER_STATUS_FIRING_RIGHT:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
break;
case PLAYER_STATUS_FIRING_NO:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_LEFT);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_LEFT);
break;
default:
@@ -435,51 +324,19 @@ void Player::setAnimation()
switch (mStatusFiring)
{
case PLAYER_STATUS_FIRING_UP:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
break;
case PLAYER_STATUS_FIRING_LEFT:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
break;
case PLAYER_STATUS_FIRING_RIGHT:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
break;
case PLAYER_STATUS_FIRING_NO:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_RIGHT);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_RIGHT);
break;
default:
@@ -493,51 +350,19 @@ void Player::setAnimation()
switch (mStatusFiring)
{
case PLAYER_STATUS_FIRING_UP:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
break;
case PLAYER_STATUS_FIRING_LEFT:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
break;
case PLAYER_STATUS_FIRING_RIGHT:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
break;
case PLAYER_STATUS_FIRING_NO:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
break;
default:
@@ -616,7 +441,7 @@ void Player::update()
setAnimation();
shiftColliders();
updateCooldown();
updateInvulnerableTimer();
updateInvulnerableCounter();
}
// Obtiene la puntuación del jugador
@@ -692,19 +517,19 @@ void Player::setInvulnerable(bool value)
}
// Obtiene el valor de la variable
bool Player::getInvulnerableTimer()
Uint16 Player::getInvulnerableCounter()
{
return mInvulnerableCounter;
}
// Establece el valor de la variable
void Player::setInvulnerableTimer(Uint16 value)
void Player::setInvulnerableCounter(Uint16 value)
{
mInvulnerableCounter = value;
}
// Actualiza el valor de la variable
void Player::updateInvulnerableTimer()
void Player::updateInvulnerableCounter()
{
if (mInvulnerableCounter > 0)
{
@@ -762,7 +587,7 @@ Uint8 Player::getCoffees()
}
// Obtiene el circulo de colisión
Circle &Player::getCollider()
circle_t &Player::getCollider()
{
return mCollider;
}

View File

@@ -38,7 +38,7 @@ private:
AnimatedSprite *mSpriteBody; // Sprite para dibujar el cuerpo
AnimatedSprite *mSpriteHead; // Sprite para dibujar la cabeza
Circle mCollider; // Circulo de colisión del jugador
circle_t mCollider; // Circulo de colisión del jugador
void shiftColliders(); // Actualiza el circulo de colisión a la posición del jugador
public:
@@ -125,13 +125,13 @@ public:
void setInvulnerable(bool value);
// Obtiene el valor de la variable
bool getInvulnerableTimer();
Uint16 getInvulnerableCounter();
// Establece el valor de la variable
void setInvulnerableTimer(Uint16 value);
void setInvulnerableCounter(Uint16 value);
// Actualiza el valor de la variable
void updateInvulnerableTimer();
void updateInvulnerableCounter();
// Obtiene el valor de la variable
bool hasExtraHit();
@@ -152,7 +152,7 @@ public:
Uint8 getCoffees();
// Obtiene el circulo de colisión
Circle &getCollider();
circle_t &getCollider();
};
#endif

View File

@@ -16,14 +16,14 @@ Sprite::~Sprite()
// Inicializador
void Sprite::init(int x, int y, int w, int h, LTexture *texture, SDL_Renderer *renderer)
{
// Establece el alto y el ancho del sprite
setWidth(w);
setHeight(h);
// Establece la posición X,Y del sprite
setPosX(x);
setPosY(y);
// Establece el alto y el ancho del sprite
setWidth(w);
setHeight(h);
// Establece el puntero al renderizador de la ventana
setRenderer(renderer);

View File

@@ -191,6 +191,15 @@ void Text::writeColored(int x, int y, std::string text, Uint8 R, Uint8 G, Uint8
mSprite->getTexture()->setColor(255, 255, 255);
}
// Escribe el texto con sombra
void Text::writeShadowed(int x, int y, std::string text, Uint8 R, Uint8 G, Uint8 B)
{
mSprite->getTexture()->setColor(R, G, B);
write(x+1, y+1, text);
mSprite->getTexture()->setColor(255, 255, 255);
write(x, y, text);
}
// Escribe el texto centrado en un punto x y con kerning
void Text::writeCentered(int x, int y, std::string text, int kerning)
{

View File

@@ -39,6 +39,9 @@ public:
// Escribe el texto con colores
void writeColored(int x, int y, std::string text, Uint8 R, Uint8 G, Uint8 B);
// Escribe el texto con sombra
void writeShadowed(int x, int y, std::string text, Uint8 R, Uint8 G, Uint8 B);
// Escribe el texto centrado en un punto x y con kerning
void writeCentered(int x, int y, std::string text, int kerning = 0);

View File

@@ -9,7 +9,7 @@ double distanceSquared(int x1, int y1, int x2, int y2)
}
// Detector de colisiones entre dos circulos
bool checkCollision(Circle &a, Circle &b)
bool checkCollision(circle_t &a, circle_t &b)
{
// Calcula el radio total al cuadrado
int totalRadiusSquared = a.r + b.r;
@@ -27,7 +27,7 @@ bool checkCollision(Circle &a, Circle &b)
}
// Detector de colisiones entre un circulo y un rectangulo
bool checkCollision(Circle &a, SDL_Rect &b)
bool checkCollision(circle_t &a, SDL_Rect &b)
{
//Closest point on collision box
int cX, cY;
@@ -60,10 +60,10 @@ bool checkCollision(Circle &a, SDL_Rect &b)
cY = a.y;
}
//If the closest point is inside the circle
//If the closest point is inside the circle_t
if (distanceSquared(a.x, a.y, cX, cY) < a.r * a.r)
{
//This box and the circle have collided
//This box and the circle_t have collided
return true;
}

View File

@@ -5,7 +5,7 @@
#define UTILS_H
// Estructura para definir un circulo
struct Circle
struct circle_t
{
Uint16 x;
Uint16 y;
@@ -13,7 +13,7 @@ struct Circle
};
// Estructura para definir todas las entradas que aceptará el programa
struct Input
struct input_t
{
Uint8 up;
Uint8 down;
@@ -29,7 +29,7 @@ struct Input
};
// Estructura para mapear el teclado usado en la demo
struct DemoKeys
struct demoKeys_t
{
Uint8 left;
Uint8 right;
@@ -43,15 +43,12 @@ struct DemoKeys
double distanceSquared(int x1, int y1, int x2, int y2);
// Detector de colisiones entre dos circulos
bool checkCollision(Circle &a, Circle &b);
bool checkCollision(circle_t &a, circle_t &b);
// Detector de colisiones entre un circulo y un rectangulo
bool checkCollision(Circle &a, SDL_Rect &b);
bool checkCollision(circle_t &a, SDL_Rect &b);
// Detector de colisiones entre un dos rectangulos
bool checkCollision(SDL_Rect a, SDL_Rect b);
// Inicializa el vector con los valores del seno
void initSin();
#endif