Trabajando en los globos
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 57 KiB |
37
data/gfx/balloon1.ani
Normal file
37
data/gfx/balloon1.ani
Normal file
@@ -0,0 +1,37 @@
|
||||
frameWidth=8
|
||||
frameHeight=8
|
||||
|
||||
[animation]
|
||||
name=orange
|
||||
speed=10
|
||||
loop=0
|
||||
frames=0,1,2,3,4,5,6,7,8,9
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=blue
|
||||
speed=20
|
||||
loop=0
|
||||
frames=12,13,14,15,16,17,18,19,20,21
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=green
|
||||
speed=10
|
||||
loop=0
|
||||
frames=24,25,26,27,28,29,30,31,32,33
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=red
|
||||
speed=20
|
||||
loop=0
|
||||
frames=36,37,38,39,40,41,42,43,44,45
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=pop
|
||||
speed=5
|
||||
loop=-1
|
||||
frames=48,49,50,51,52,53,54,55,56,57,58,59
|
||||
[/animation]
|
||||
BIN
data/gfx/balloon1.png
Normal file
BIN
data/gfx/balloon1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
37
data/gfx/balloon2.ani
Normal file
37
data/gfx/balloon2.ani
Normal file
@@ -0,0 +1,37 @@
|
||||
frameWidth=13
|
||||
frameHeight=13
|
||||
|
||||
[animation]
|
||||
name=orange
|
||||
speed=10
|
||||
loop=0
|
||||
frames=0,1,2,3,4,5,6,7,8,9
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=blue
|
||||
speed=20
|
||||
loop=0
|
||||
frames=12,13,14,15,16,17,18,19,20,21
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=green
|
||||
speed=10
|
||||
loop=0
|
||||
frames=24,25,26,27,28,29,30,31,32,33
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=red
|
||||
speed=20
|
||||
loop=0
|
||||
frames=36,37,38,39,40,41,42,43,44,45
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=pop
|
||||
speed=5
|
||||
loop=-1
|
||||
frames=48,49,50,51,52,53,54,55,56,57,58,59
|
||||
[/animation]
|
||||
BIN
data/gfx/balloon2.png
Normal file
BIN
data/gfx/balloon2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.7 KiB |
37
data/gfx/balloon3.ani
Normal file
37
data/gfx/balloon3.ani
Normal file
@@ -0,0 +1,37 @@
|
||||
frameWidth=21
|
||||
frameHeight=21
|
||||
|
||||
[animation]
|
||||
name=orange
|
||||
speed=10
|
||||
loop=0
|
||||
frames=0,1,2,3,4,5,6,7,8,9
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=blue
|
||||
speed=20
|
||||
loop=0
|
||||
frames=12,13,14,15,16,17,18,19,20,21
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=green
|
||||
speed=10
|
||||
loop=0
|
||||
frames=24,25,26,27,28,29,30,31,32,33
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=red
|
||||
speed=20
|
||||
loop=0
|
||||
frames=36,37,38,39,40,41,42,43,44,45
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=pop
|
||||
speed=5
|
||||
loop=-1
|
||||
frames=48,49,50,51,52,53,54,55,56,57,58,59
|
||||
[/animation]
|
||||
BIN
data/gfx/balloon3.png
Normal file
BIN
data/gfx/balloon3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.5 KiB |
37
data/gfx/balloon4.ani
Normal file
37
data/gfx/balloon4.ani
Normal file
@@ -0,0 +1,37 @@
|
||||
frameWidth=37
|
||||
frameHeight=37
|
||||
|
||||
[animation]
|
||||
name=orange
|
||||
speed=10
|
||||
loop=0
|
||||
frames=0,1,2,3,4,5,6,7,8,9
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=blue
|
||||
speed=20
|
||||
loop=0
|
||||
frames=12,13,14,15,16,17,18,19,20,21
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=green
|
||||
speed=10
|
||||
loop=0
|
||||
frames=24,25,26,27,28,29,30,31,32,33
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=red
|
||||
speed=20
|
||||
loop=0
|
||||
frames=36,37,38,39,40,41,42,43,44,45
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=pop
|
||||
speed=5
|
||||
loop=-1
|
||||
frames=48,49,50,51,52,53,54,55,56,57,58,59
|
||||
[/animation]
|
||||
BIN
data/gfx/balloon4.png
Normal file
BIN
data/gfx/balloon4.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -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,10 +508,14 @@ void Balloon::updateState()
|
||||
disable();
|
||||
}
|
||||
else if (mTimeToLive > 0)
|
||||
{
|
||||
mTimeToLive--;
|
||||
}
|
||||
else
|
||||
{
|
||||
disable();
|
||||
}
|
||||
}
|
||||
|
||||
// Si se está creando
|
||||
if (isBeingCreated())
|
||||
@@ -690,12 +562,16 @@ void Balloon::updateState()
|
||||
{
|
||||
mSprite->setRotate(true);
|
||||
if (mVelX > 0.0f)
|
||||
{
|
||||
mSprite->setRotateAmount(2.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
mSprite->setRotateAmount(-2.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Solo comprueba el estado detenido cuando no se está creando
|
||||
else if (isStopped())
|
||||
{
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,7 +146,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture, SDL_Renderer *renderer);
|
||||
Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture, std::string file, SDL_Renderer *renderer);
|
||||
|
||||
// Destructor
|
||||
~Balloon();
|
||||
|
||||
@@ -189,7 +189,14 @@ bool Director::setFileList()
|
||||
asset->add("data/sound/powerball.wav", t_sound);
|
||||
|
||||
// Texturas
|
||||
asset->add("data/gfx/balloon.png", t_bitmap);
|
||||
asset->add("data/gfx/balloon1.png", t_bitmap);
|
||||
asset->add("data/gfx/balloon1.ani", t_data);
|
||||
asset->add("data/gfx/balloon2.png", t_bitmap);
|
||||
asset->add("data/gfx/balloon2.ani", t_data);
|
||||
asset->add("data/gfx/balloon3.png", t_bitmap);
|
||||
asset->add("data/gfx/balloon3.ani", t_data);
|
||||
asset->add("data/gfx/balloon4.png", t_bitmap);
|
||||
asset->add("data/gfx/balloon4.ani", t_data);
|
||||
asset->add("data/gfx/bullet.png", t_bitmap);
|
||||
asset->add("data/gfx/game_bg.png", t_bitmap);
|
||||
asset->add("data/gfx/game_text.png", t_bitmap);
|
||||
|
||||
135
source/game.cpp
135
source/game.cpp
@@ -39,7 +39,10 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
|
||||
players.push_back(player2);
|
||||
}
|
||||
|
||||
mTextureBalloon = new LTexture(mRenderer, mAsset->get("balloon.png"));
|
||||
balloon1Texture = new LTexture(mRenderer, mAsset->get("balloon1.png"));
|
||||
balloon2Texture = new LTexture(mRenderer, mAsset->get("balloon2.png"));
|
||||
balloon3Texture = new LTexture(mRenderer, mAsset->get("balloon3.png"));
|
||||
balloon4Texture = new LTexture(mRenderer, mAsset->get("balloon4.png"));
|
||||
mTextureBullet = new LTexture(mRenderer, mAsset->get("bullet.png"));
|
||||
mTextureGameBG = new LTexture(mRenderer, mAsset->get("game_bg.png"));
|
||||
mTextureGameText = new LTexture(mRenderer, mAsset->get("game_text.png"));
|
||||
@@ -112,9 +115,17 @@ Game::~Game()
|
||||
delete smartSprite;
|
||||
};
|
||||
|
||||
mTextureBalloon->unload();
|
||||
delete mTextureBalloon;
|
||||
mTextureBalloon = nullptr;
|
||||
balloon1Texture->unload();
|
||||
delete balloon1Texture;
|
||||
|
||||
balloon2Texture->unload();
|
||||
delete balloon2Texture;
|
||||
|
||||
balloon3Texture->unload();
|
||||
delete balloon3Texture;
|
||||
|
||||
balloon4Texture->unload();
|
||||
delete balloon4Texture;
|
||||
|
||||
mTextureBullet->unload();
|
||||
delete mTextureBullet;
|
||||
@@ -1386,15 +1397,16 @@ void Game::deployEnemyFormation()
|
||||
if (mDebug.enabled)
|
||||
set = mDebug.enemySet;
|
||||
|
||||
Uint8 numEnemies = mStage[mCurrentStage].enemyPool->set[set]->numberOfEnemies;
|
||||
for (int i = 0; i < numEnemies; i++)
|
||||
const Uint8 numEnemies = mStage[mCurrentStage].enemyPool->set[set]->numberOfEnemies;
|
||||
for (int i = 0; i < numEnemies; ++i)
|
||||
{
|
||||
createNewBalloon(mStage[mCurrentStage].enemyPool->set[set]->init[i].x,
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].y,
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].kind,
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].velX,
|
||||
mEnemySpeed,
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].creationCounter,
|
||||
mTextureBalloon);
|
||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].creationCounter);
|
||||
}
|
||||
|
||||
mEnemyDeployCounter = 300;
|
||||
}
|
||||
@@ -1754,11 +1766,12 @@ void Game::renderBalloons()
|
||||
}
|
||||
|
||||
// Crea un globo nuevo en el vector de globos
|
||||
Uint8 Game::createNewBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture)
|
||||
Uint8 Game::createNewBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 creationtimer)
|
||||
{
|
||||
// Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, texture, mRenderer);
|
||||
// balloons.push_back(b);
|
||||
// return (Uint8)(balloons.size() - 1);
|
||||
const std::string file = balloonAnimation(kind);
|
||||
Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, balloonTexture(kind), file, mRenderer);
|
||||
balloons.push_back(b);
|
||||
return (Uint8)(balloons.size() - 1);
|
||||
}
|
||||
|
||||
// Crea una PowerBall
|
||||
@@ -1773,7 +1786,7 @@ void Game::createPowerBall()
|
||||
const int x[3] = {left, center, right};
|
||||
const int posX = x[rand() % 3];
|
||||
|
||||
Balloon *b = new Balloon(posX, posY, POWER_BALL, BALLOON_VELX_POSITIVE * (((rand() % 2) * 2) - 1), mEnemySpeed, 100, mTextureBalloon, mRenderer);
|
||||
Balloon *b = new Balloon(posX, posY, POWER_BALL, BALLOON_VELX_POSITIVE * (((rand() % 2) * 2) - 1), mEnemySpeed, 100, balloon4Texture, mAsset->get("balloon4.ani"), mRenderer);
|
||||
balloons.push_back(b);
|
||||
|
||||
mPowerBallEnabled = true;
|
||||
@@ -1897,28 +1910,27 @@ void Game::popBalloon(Balloon *balloon)
|
||||
|
||||
// En cualquier otro caso, crea dos globos de un tipo inferior
|
||||
default:
|
||||
Balloon *b1 = new Balloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_NEGATIVE, mEnemySpeed, 0, mTextureBalloon, mRenderer);
|
||||
balloons.push_back(b1);
|
||||
b1->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
||||
if (b1->getClass() == BALLOON_CLASS)
|
||||
// Balloon *b1 = new Balloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_NEGATIVE, mEnemySpeed, 0, mRenderer);
|
||||
const int index = createNewBalloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_NEGATIVE, mEnemySpeed, 0);
|
||||
balloons.at(index)->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
||||
if (balloons.at(index)->getClass() == BALLOON_CLASS)
|
||||
{
|
||||
b1->setVelY(-2.50f);
|
||||
balloons.at(index)->setVelY(-2.50f);
|
||||
}
|
||||
else if (b1->getClass() == HEXAGON_CLASS)
|
||||
else if (balloons.at(index)->getClass() == HEXAGON_CLASS)
|
||||
{
|
||||
b1->setVelY(BALLOON_VELX_NEGATIVE);
|
||||
balloons.at(index)->setVelY(BALLOON_VELX_NEGATIVE);
|
||||
}
|
||||
|
||||
Balloon *b2 = new Balloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_POSITIVE, mEnemySpeed, 0, mTextureBalloon, mRenderer);
|
||||
balloons.push_back(b2);
|
||||
b2->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
||||
if (b2->getClass() == BALLOON_CLASS)
|
||||
const int index2 = createNewBalloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_POSITIVE, mEnemySpeed, 0);
|
||||
balloons.at(index2)->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
||||
if (balloons.at(index2)->getClass() == BALLOON_CLASS)
|
||||
{
|
||||
b2->setVelY(-2.50f);
|
||||
balloons.at(index2)->setVelY(-2.50f);
|
||||
}
|
||||
else if (b2->getClass() == HEXAGON_CLASS)
|
||||
else if (balloons.at(index2)->getClass() == HEXAGON_CLASS)
|
||||
{
|
||||
b2->setVelY(BALLOON_VELX_NEGATIVE);
|
||||
balloons.at(index2)->setVelY(BALLOON_VELX_NEGATIVE);
|
||||
}
|
||||
|
||||
// Elimina el globo
|
||||
@@ -2059,6 +2071,74 @@ Uint8 Game::countBalloons()
|
||||
return num;
|
||||
}
|
||||
|
||||
// Obtiene la textura correspondiente en funcion del tipo
|
||||
LTexture *Game::balloonTexture(int kind)
|
||||
{
|
||||
if (kind == 1 || kind == 5)
|
||||
{
|
||||
return balloon1Texture;
|
||||
}
|
||||
|
||||
else if (kind == 2 || kind == 6)
|
||||
{
|
||||
return balloon2Texture;
|
||||
}
|
||||
|
||||
else if (kind == 3 || kind == 7)
|
||||
{
|
||||
return balloon4Texture;
|
||||
}
|
||||
|
||||
else if (kind == 4 || kind == 8 || kind == 9)
|
||||
{
|
||||
return balloon4Texture;
|
||||
}
|
||||
|
||||
return balloon1Texture;
|
||||
}
|
||||
|
||||
// Obtiene la animacion correspondiente en funcion del tipo
|
||||
std::string Game::balloonAnimation(int kind)
|
||||
{
|
||||
if (kind == 1 || kind == 5)
|
||||
{
|
||||
return mAsset->get("balloon1.ani");
|
||||
}
|
||||
|
||||
else if (kind == 2 || kind == 6)
|
||||
{
|
||||
return mAsset->get("balloon2.ani");
|
||||
}
|
||||
|
||||
else if (kind == 3 || kind == 7)
|
||||
{
|
||||
return mAsset->get("balloon3.ani");
|
||||
}
|
||||
|
||||
else if (kind == 4 || kind == 8 || kind == 9)
|
||||
{
|
||||
return mAsset->get("balloon4.ani");
|
||||
}
|
||||
|
||||
return mAsset->get("balloon1.ani");
|
||||
}
|
||||
|
||||
// Vacia el vector de globos
|
||||
void Game::freeBalloons()
|
||||
{
|
||||
if (balloons.empty() == false)
|
||||
{
|
||||
for (int i = balloons.size() - 1; i >= 0; --i)
|
||||
{
|
||||
if (balloons.at(i)->isEnabled() == false)
|
||||
{
|
||||
delete balloons.at(i);
|
||||
balloons.erase(balloons.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba la colisión entre el jugador y los globos activos
|
||||
bool Game::checkPlayerBalloonCollision(Player *player)
|
||||
{
|
||||
@@ -2610,6 +2690,7 @@ void Game::updatePlayField()
|
||||
|
||||
// Vacia los vectores
|
||||
freeBullets();
|
||||
freeBalloons();
|
||||
}
|
||||
|
||||
// Actualiza el fondo
|
||||
|
||||
@@ -141,7 +141,10 @@ private:
|
||||
std::vector<Item *> items; // Vector con los items
|
||||
std::vector<SmartSprite *> smartSprites; // Vector con los smartsprites
|
||||
|
||||
LTexture *mTextureBalloon; // Textura para los enemigos
|
||||
LTexture *balloon1Texture; // Textura para los enemigos
|
||||
LTexture *balloon2Texture; // Textura para los enemigos
|
||||
LTexture *balloon3Texture; // Textura para los enemigos
|
||||
LTexture *balloon4Texture; // Textura para los enemigos
|
||||
LTexture *mTextureBullet; // Textura para las balas
|
||||
LTexture *mTextureGameBG; // Textura para el fondo del juego
|
||||
LTexture *mTextureGameText; // Textura para los sprites con textos
|
||||
@@ -303,7 +306,7 @@ private:
|
||||
void renderBalloons();
|
||||
|
||||
// Crea un globo nuevo en el vector de globos
|
||||
Uint8 createNewBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 stoppedcounter, LTexture *texture);
|
||||
Uint8 createNewBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 stoppedcounter);
|
||||
|
||||
// Crea una PowerBall
|
||||
void createPowerBall();
|
||||
@@ -341,6 +344,15 @@ private:
|
||||
// Obtiene el numero de globos activos
|
||||
Uint8 countBalloons();
|
||||
|
||||
// Obtiene la textura correspondiente en funcion del tipo
|
||||
LTexture *balloonTexture(int kind);
|
||||
|
||||
// Obtiene la animacion correspondiente en funcion del tipo
|
||||
std::string balloonAnimation(int kind);
|
||||
|
||||
// Vacia el vector de globos
|
||||
void freeBalloons();
|
||||
|
||||
// Comprueba la colisión entre el jugador y los globos activos
|
||||
bool checkPlayerBalloonCollision(Player *player);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user