3 Commits

Author SHA1 Message Date
91b868572e trabajando los items 2022-10-03 11:45:09 +02:00
9c35fadd55 Trabajando en los globos 2022-10-03 04:15:04 +02:00
80ca04fd64 Balas funcionales 2022-10-03 03:02:46 +02:00
31 changed files with 663 additions and 409 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 57 KiB

37
data/gfx/balloon1.ani Normal file
View 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=60,61,62,63,64,65,66,67,68,69,70,71
[/animation]

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
View 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=60,61,62,63,64,65,66,67,68,69,70,71
[/animation]

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
View 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=60,61,62,63,64,65,66,67,68,69,70,71
[/animation]

BIN
data/gfx/balloon3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

44
data/gfx/balloon4.ani Normal file
View File

@@ -0,0 +1,44 @@
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=powerball
speed=20
loop=0
frames=48
[/animation]
[animation]
name=pop
speed=5
loop=-1
frames=60,61,62,63,64,65,66,67,68,69,70,71
[/animation]

BIN
data/gfx/balloon4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

9
data/gfx/item_clock.ani Normal file
View File

@@ -0,0 +1,9 @@
frameWidth=16
frameHeight=16
[animation]
name=default
speed=10
loop=0
frames=0,1
[/animation]

BIN
data/gfx/item_clock.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

9
data/gfx/item_coffee.ani Normal file
View File

@@ -0,0 +1,9 @@
frameWidth=16
frameHeight=16
[animation]
name=default
speed=10
loop=0
frames=0,1
[/animation]

BIN
data/gfx/item_coffee.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 462 B

View File

@@ -0,0 +1,9 @@
frameWidth=23
frameHeight=29
[animation]
name=default
speed=10
loop=0
frames=0,1,2,3
[/animation]

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 B

View File

@@ -0,0 +1,9 @@
frameWidth=16
frameHeight=16
[animation]
name=default
speed=10
loop=0
frames=0,1
[/animation]

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 B

View File

@@ -0,0 +1,9 @@
frameWidth=16
frameHeight=16
[animation]
name=default
speed=10
loop=0
frames=0,1
[/animation]

Binary file not shown.

After

Width:  |  Height:  |  Size: 422 B

View File

@@ -0,0 +1,9 @@
frameWidth=16
frameHeight=16
[animation]
name=default
speed=10
loop=0
frames=0,1
[/animation]

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

View File

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

View File

@@ -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();

View File

@@ -4,7 +4,7 @@
// Constructor
Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, LTexture *texture, SDL_Renderer *renderer)
{
mSprite = new Sprite({x,y,10,10},texture, renderer);
mSprite = new Sprite({x, y, 10, 10}, texture, renderer);
// Posición inicial del objeto
mPosX = x;
@@ -12,7 +12,7 @@ Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, LTexture *text
// Alto y ancho del objeto
mWidth = 10;
mHeight = mWidth;
mHeight = 10;
// Velocidad inicial en el eje Y
mVelY = -3;
@@ -32,9 +32,13 @@ Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, LTexture *text
// Rectangulo con los gráficos del objeto
if (!poweredUp)
{
mSprite->setSpriteClip(0 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
}
else
{
mSprite->setSpriteClip((0 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
}
break;
case BULLET_LEFT:
@@ -43,9 +47,13 @@ Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, LTexture *text
// Rectangulo con los gráficos del objeto
if (!poweredUp)
{
mSprite->setSpriteClip(1 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
}
else
{
mSprite->setSpriteClip((1 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
}
break;
case BULLET_RIGHT:
@@ -54,9 +62,13 @@ Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, LTexture *text
// Rectangulo con los gráficos del objeto
if (!poweredUp)
{
mSprite->setSpriteClip(2 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
}
else
{
mSprite->setSpriteClip((2 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
}
break;
default:
@@ -74,7 +86,6 @@ Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, LTexture *text
Bullet::~Bullet()
{
delete mSprite;
mSprite = nullptr;
}
// Pinta el objeto en pantalla
@@ -129,9 +140,19 @@ Uint8 Bullet::move()
bool Bullet::isActive()
{
if (mKind == NO_KIND)
{
return false;
}
else
{
return true;
}
}
// Desactiva el objeto
void Bullet::deactivate()
{
mKind = NO_KIND;
}
// Obtiene el valor de la variable

View File

@@ -50,6 +50,9 @@ public:
// Comprueba si el objeto está activo
bool isActive();
// Desactiva el objeto
void deactivate();
// Obtiene el valor de la variable
int getPosX();

View File

@@ -189,13 +189,32 @@ 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);
asset->add("data/gfx/intro.png", t_bitmap);
asset->add("data/gfx/items.png", t_bitmap);
asset->add("data/gfx/logo.png", t_bitmap);
asset->add("data/gfx/items.png", t_bitmap);
asset->add("data/gfx/item_points1_disk.png", t_bitmap);
asset->add("data/gfx/item_points1_disk.ani", t_data);
asset->add("data/gfx/item_points2_gavina.png", t_bitmap);
asset->add("data/gfx/item_points2_gavina.ani", t_data);
asset->add("data/gfx/item_points3_pacmar.png", t_bitmap);
asset->add("data/gfx/item_points3_pacmar.ani", t_data);
asset->add("data/gfx/item_clock.png", t_bitmap);
asset->add("data/gfx/item_clock.ani", t_data);
asset->add("data/gfx/item_coffee.png", t_bitmap);
asset->add("data/gfx/item_coffee.ani", t_data);
asset->add("data/gfx/item_coffee_machine.png", t_bitmap);
asset->add("data/gfx/item_coffee_machine.ani", t_data);
asset->add("data/gfx/title_bg_tile.png", t_bitmap);
asset->add("data/gfx/title_coffee.png", t_bitmap);

View File

@@ -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;
@@ -337,33 +348,33 @@ void Game::init()
mFade->init(0x27, 0x27, 0x36);
// Inicializa el objeto con el menu de pausa
//mMenuPause->setName("PAUSE");
//mMenuPause->setPos(0, 12 * BLOCK);
//mMenuPause->setBackgroundType(MENU_BACKGROUND_SOLID);
//mMenuPause->addItem(mLang->getText(46), 2);
//mMenuPause->addItem(mLang->getText(47), 0);
//mMenuPause->setDefaultActionWhenCancel(0);
//mMenuPause->setBackgroundColor({0x29, 0x39, 0x41}, 240);
//mMenuPause->setSelectorColor({0xFF, 0x7A, 0x00}, 255);
//mMenuPause->setSelectorTextColor({0xFF, 0xFF, 0xFF});
//mMenuPause->centerMenuOnX(SCREEN_CENTER_X);
//mMenuPause->centerMenuElementsOnX();
// mMenuPause->setName("PAUSE");
// mMenuPause->setPos(0, 12 * BLOCK);
// mMenuPause->setBackgroundType(MENU_BACKGROUND_SOLID);
// mMenuPause->addItem(mLang->getText(46), 2);
// mMenuPause->addItem(mLang->getText(47), 0);
// mMenuPause->setDefaultActionWhenCancel(0);
// mMenuPause->setBackgroundColor({0x29, 0x39, 0x41}, 240);
// mMenuPause->setSelectorColor({0xFF, 0x7A, 0x00}, 255);
// mMenuPause->setSelectorTextColor({0xFF, 0xFF, 0xFF});
// mMenuPause->centerMenuOnX(SCREEN_CENTER_X);
// mMenuPause->centerMenuElementsOnX();
// Inicializa el objeto con el menu de la pantalla de game over
//mMenuGameOver->setName("GAME OVER");
//mMenuGameOver->setPos(0, PLAY_AREA_CENTER_Y + BLOCK * 4);
//mMenuGameOver->setBackgroundType(MENU_BACKGROUND_TRANSPARENT);
//mMenuGameOver->addItem(mLang->getText(48), 2);
//mMenuGameOver->addItem(mLang->getText(49));
//mMenuGameOver->setDefaultActionWhenCancel(1);
//mMenuGameOver->setBackgroundColor({0, 0, 0}, 255);
//mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 255);
//mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 0);
//mMenuGameOver->setSelectorTextColor({0xFF, 0xFF, 0xFF});
//mMenuGameOver->setSelectorTextColor({0xFF, 0xF1, 0x76});
//mMenuGameOver->setSelectorTextColor({0xFF, 0x7A, 0x00});
//mMenuGameOver->centerMenuOnX(SCREEN_CENTER_X);
//mMenuGameOver->centerMenuElementsOnX();
// mMenuGameOver->setName("GAME OVER");
// mMenuGameOver->setPos(0, PLAY_AREA_CENTER_Y + BLOCK * 4);
// mMenuGameOver->setBackgroundType(MENU_BACKGROUND_TRANSPARENT);
// mMenuGameOver->addItem(mLang->getText(48), 2);
// mMenuGameOver->addItem(mLang->getText(49));
// mMenuGameOver->setDefaultActionWhenCancel(1);
// mMenuGameOver->setBackgroundColor({0, 0, 0}, 255);
// mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 255);
// mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 0);
// mMenuGameOver->setSelectorTextColor({0xFF, 0xFF, 0xFF});
// mMenuGameOver->setSelectorTextColor({0xFF, 0xF1, 0x76});
// mMenuGameOver->setSelectorTextColor({0xFF, 0x7A, 0x00});
// mMenuGameOver->centerMenuOnX(SCREEN_CENTER_X);
// mMenuGameOver->centerMenuElementsOnX();
// Sprites
mClouds1a->setSpriteClip(256, 0, 256, 52);
@@ -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 balloon3Texture;
}
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)
{
@@ -2134,7 +2214,7 @@ void Game::checkPlayerItemCollision(Player *player)
default:
break;
}
item->erase();
item->disable();
}
}
}
@@ -2153,8 +2233,8 @@ void Game::checkBulletBalloonCollision()
{
// Otorga los puntos correspondientes al globo al jugador que disparó la bala
int index = bullet->getOwner();
players[index]->incScoreMultiplier();
players[index]->addScore(Uint32(balloon->getScore() * players[index]->getScoreMultiplier() * mDifficultyScoreMultiplier));
players.at(index)->incScoreMultiplier();
players.at(index)->addScore(Uint32(balloon->getScore() * players.at(index)->getScoreMultiplier() * mDifficultyScoreMultiplier));
updateHiScore();
// Explota el globo
@@ -2166,8 +2246,8 @@ void Game::checkBulletBalloonCollision()
JA_PlaySound(mSoundBalloon);
}
// Destruye la bala
delete bullet;
// Desactiva la bala
bullet->deactivate();
// Suelta el item en caso de que salga uno
const Uint8 droppeditem = dropItem();
@@ -2175,12 +2255,12 @@ void Game::checkBulletBalloonCollision()
{
if (droppeditem != ITEM_COFFEE_MACHINE)
{
createItem(mTextureItems, mRenderer, balloon->getPosX(), balloon->getPosY(), droppeditem);
createItem(balloon->getPosX(), balloon->getPosY(), droppeditem);
JA_PlaySound(mSoundItemDrop);
}
else
{
createItem(mTextureItems, mRenderer, players[index]->getPosX(), 0, droppeditem);
createItem(players.at(index)->getPosX(), 0, droppeditem);
mCoffeeMachineEnabled = true;
}
}
@@ -2200,7 +2280,7 @@ void Game::moveBullets()
{
if (bullet->move() == BULLET_MOVE_OUT)
{
players[bullet->getOwner()]->decScoreMultiplier();
players.at(bullet->getOwner())->decScoreMultiplier();
}
}
}
@@ -2225,13 +2305,29 @@ void Game::createBullet(int x, int y, Uint8 kind, bool poweredUp, int owner)
bullets.push_back(b);
}
// Vacia el vector de balas
void Game::freeBullets()
{
if (bullets.empty() == false)
{
for (int i = bullets.size() - 1; i >= 0; --i)
{
if (bullets.at(i)->isActive() == false)
{
delete bullets.at(i);
bullets.erase(bullets.begin() + i);
}
}
}
}
// Actualiza los items
void Game::updateItems()
{
for (auto item : items)
{
item->update();
if (item->floorCollision())
if (item->isOnFloor())
{
JA_PlaySound(mSoundCollision);
mEffect.shake = true;
@@ -2317,20 +2413,36 @@ Uint8 Game::dropItem()
}
// Crea un objeto item
void Game::createItem(LTexture *texture, SDL_Renderer *renderer, Uint8 type, float x, float y)
void Game::createItem(Uint8 type, float x, float y)
{
Item *i = new Item(texture, renderer, type, x, y);
Item *i = new Item(mRenderer, mAsset, type, x, y);
items.push_back(i);
}
// Vacia el vector de items
void Game::freeItems()
{
if (items.empty() == false)
{
for (int i = items.size() - 1; i >= 0; --i)
{
if (items.at(i)->isEnabled() == false)
{
delete items.at(i);
items.erase(items.begin() + i);
}
}
}
}
// Crea un objeto SmartSprite para mostrar la puntuación al coger un objeto
void Game::createItemScoreSprite(int x, int y, SmartSprite *sprite)
{
SmartSprite *ss = new SmartSprite(nullptr, mRenderer);
smartSprites.push_back(ss);
// Crea una copia del objeto
*ss = *sprite;
*ss = *sprite;
ss->setPosX(x);
ss->setPosY(y);
ss->setDestX(x);
@@ -2398,7 +2510,7 @@ void Game::throwPlayer(int x, int y, Player *player)
{
const int sentit = ((rand() % 2) ? 1 : -1);
//player->deathIndex = getSmartSpriteFreeIndex();
// player->deathIndex = getSmartSpriteFreeIndex();
SmartSprite *ss = new SmartSprite(nullptr, mRenderer);
smartSprites.push_back(ss);
@@ -2422,7 +2534,7 @@ void Game::throwPlayer(int x, int y, Player *player)
// Actualiza los SmartSprites
void Game::updateSmartSprites()
{
for (auto ss:smartSprites)
for (auto ss : smartSprites)
{
ss->update();
}
@@ -2431,7 +2543,7 @@ void Game::updateSmartSprites()
// Pinta los SmartSprites activos
void Game::renderSmartSprites()
{
for (auto ss:smartSprites)
for (auto ss : smartSprites)
{
ss->render();
}
@@ -2474,7 +2586,7 @@ void Game::killPlayer(Player *player)
void Game::evaluateAndSetMenace()
{
mMenaceCurrent = 0;
for (auto balloon:balloons)
for (auto balloon : balloons)
{
if (balloon->isEnabled())
{
@@ -2591,6 +2703,11 @@ void Game::updatePlayField()
// Actualiza el tramo final de juego, una vez completado
updateGameCompleted();
// Vacia los vectores
freeBullets();
freeBalloons();
freeItems();
}
// Actualiza el fondo
@@ -2671,12 +2788,12 @@ void Game::renderPlayField()
renderSmartSprites();
renderScoreBoard();
for (auto player:players)
for (auto player : players)
{
player->render();
}
if ((mDeathCounter <= 150) && !players[0]->isAlive())
if ((mDeathCounter <= 150) && !players.at(0)->isAlive())
{
renderDeathFade(150 - mDeathCounter);
}
@@ -2687,6 +2804,8 @@ void Game::renderPlayField()
}
renderFlashEffect();
mText->write(0, 0, std::to_string(balloons.size()));
}
// Gestiona el nivel de amenaza
@@ -2725,45 +2844,45 @@ void Game::checkGameInput()
const int index = 0;
if (mDemo.dataFile[mDemo.counter].left == 1)
{
players[index]->setInput(INPUT_LEFT);
players.at(index)->setInput(INPUT_LEFT);
}
if (mDemo.dataFile[mDemo.counter].right == 1)
{
players[index]->setInput(INPUT_RIGHT);
players.at(index)->setInput(INPUT_RIGHT);
}
if (mDemo.dataFile[mDemo.counter].noInput == 1)
{
players[index]->setInput(INPUT_NULL);
players.at(index)->setInput(INPUT_NULL);
}
if (mDemo.dataFile[mDemo.counter].fire == 1)
{
if (players[index]->canFire())
if (players.at(index)->canFire())
{
players[index]->setInput(INPUT_BUTTON_2);
createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_UP, players[index]->isPowerUp(), index);
players[index]->setFireCooldown(10);
players.at(index)->setInput(INPUT_BUTTON_2);
createBullet(players.at(index)->getPosX() + (players.at(index)->getWidth() / 2) - 4, players.at(index)->getPosY() + (players.at(index)->getHeight() / 2), BULLET_UP, players.at(index)->isPowerUp(), index);
players.at(index)->setFireCooldown(10);
}
}
if (mDemo.dataFile[mDemo.counter].fireLeft == 1)
{
if (players[index]->canFire())
if (players.at(index)->canFire())
{
players[index]->setInput(INPUT_BUTTON_1);
createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_UP, players[index]->isPowerUp(), index);
players[index]->setFireCooldown(10);
players.at(index)->setInput(INPUT_BUTTON_1);
createBullet(players.at(index)->getPosX() + (players.at(index)->getWidth() / 2) - 4, players.at(index)->getPosY() + (players.at(index)->getHeight() / 2), BULLET_UP, players.at(index)->isPowerUp(), index);
players.at(index)->setFireCooldown(10);
}
}
if (mDemo.dataFile[mDemo.counter].fireRight == 1)
{
if (players[index]->canFire())
if (players.at(index)->canFire())
{
players[index]->setInput(INPUT_BUTTON_3);
createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_UP, players[index]->isPowerUp(), index);
players[index]->setFireCooldown(10);
players.at(index)->setInput(INPUT_BUTTON_3);
createBullet(players.at(index)->getPosX() + (players.at(index)->getWidth() / 2) - 4, players.at(index)->getPosY() + (players.at(index)->getHeight() / 2), BULLET_UP, players.at(index)->isPowerUp(), index);
players.at(index)->setFireCooldown(10);
}
}
@@ -2787,7 +2906,7 @@ void Game::checkGameInput()
else
{
int i = 0;
for (auto player:players)
for (auto player : players)
{
if (player->isAlive())
{
@@ -3016,7 +3135,7 @@ void Game::shakeScreen()
renderBalloons();
renderBullets();
renderItems();
for (auto player:players)
for (auto player : players)
{
player->render();
}
@@ -3056,7 +3175,7 @@ section_t Game::run()
// Reproduce la música
if (!mGameCompleted)
{
if (players[0]->isAlive())
if (players.at(0)->isAlive())
{
JA_PlayMusic(mMusicPlaying);
}
@@ -3340,7 +3459,7 @@ int Game::calculateScreenPower()
{
int power = 0;
for (auto balloon:balloons)
for (auto balloon : balloons)
{
if (balloon->isEnabled())
{
@@ -3431,7 +3550,7 @@ void Game::updateHelper()
// Solo ofrece ayuda cuando la amenaza es elevada
if (mMenaceCurrent > 15)
{
for (auto player:players)
for (auto player : players)
{
if (player->getCoffees() == 0)
{
@@ -3463,7 +3582,7 @@ void Game::updateHelper()
bool Game::allPlayersAreDead()
{
bool success = true;
for (auto player:players)
for (auto player : players)
{
success &= (!player->isAlive());
}

View File

@@ -141,11 +141,14 @@ private:
std::vector<Item *> items; // Vector con los items
std::vector<SmartSprite *> smartSprites; // Vector con los smartsprites
LTexture *mTextureBalloon; // 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
LTexture *mTextureItems; // Textura para los items
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
LTexture *mTextureItems; // Textura para los items
Text *mText; // Fuente para los textos del juego
Text *mTextBig; // Fuente de texto grande
@@ -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);
@@ -359,6 +371,9 @@ private:
// Crea un objeto bala
void createBullet(int x, int y, Uint8 kind, bool poweredUp, int owner);
// Vacia el vector de balas
void freeBullets();
// Actualiza los items
void updateItems();
@@ -369,7 +384,10 @@ private:
Uint8 dropItem();
// Crea un objeto item
void createItem(LTexture *texture, SDL_Renderer *renderer, Uint8 type, float x, float y);
void createItem(Uint8 type, float x, float y);
// Vacia el vector de items
void freeItems();
// Crea un objeto SmartSprite
void createItemScoreSprite(int x, int y, SmartSprite *sprite);

View File

@@ -13,7 +13,7 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *mAsset
// Reserva memoria para los punteros
mEventHandler = new SDL_Event();
mItemTexture = new LTexture(mRenderer,mAsset->get("items.png"));
mItemTexture = new LTexture(mRenderer, mAsset->get("items.png"));
mSprite = new Sprite(0, 0, GAME_WIDTH, GAME_HEIGHT, mItemTexture, mRenderer);
mText = new Text(mAsset->get("smb2.png"), mAsset->get("smb2.txt"), mRenderer);
@@ -28,26 +28,14 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *mAsset
// Destructor
Instructions::~Instructions()
{
mRenderer = nullptr;
mScreen = nullptr;
mAsset = nullptr;
mLang = nullptr;
mItemTexture->unload();
delete mItemTexture;
mItemTexture = nullptr;
delete mSprite;
mSprite = nullptr;
delete mEventHandler;
mEventHandler = nullptr;
delete mText;
mText = nullptr;
SDL_DestroyTexture(mBackbuffer);
mBackbuffer = nullptr;
}
// Inicializa las variables necesarias para la sección 'Instructions'
@@ -87,7 +75,9 @@ void Instructions::run(Uint8 mode)
mSection.subsection = TITLE_SECTION_1;
}
else
{
mManualQuit = true;
}
}
}
@@ -97,9 +87,8 @@ void Instructions::run(Uint8 mode)
// Actualiza el contador de ticks
mTicks = SDL_GetTicks();
// Modo automático
if (mode == INSTRUCTIONS_MODE_AUTO)
{
{ // Modo automático
mCounter++;
if (mCounter == INSTRUCTIONS_COUNTER)
@@ -108,9 +97,8 @@ void Instructions::run(Uint8 mode)
mSection.subsection = TITLE_SECTION_1;
}
}
// Modo manual
else
{
{ // Modo manual
++mCounter %= 60000;
if (mManualQuit)
@@ -153,7 +141,9 @@ void Instructions::run(Uint8 mode)
mText->writeShadowed(84, 156, mLang->getText(21), shdwTxtColor);
if ((mode == INSTRUCTIONS_MODE_MANUAL) && (mCounter % 50 > 14))
{
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, GAME_HEIGHT - 12, mLang->getText(22), 1, orangeColor, 1, shdwTxtColor);
}
// Disquito
mSprite->setPos(destRect1);
@@ -201,9 +191,13 @@ void Instructions::run(Uint8 mode)
// Establece la ventana del backbuffer
if (mode == INSTRUCTIONS_MODE_AUTO)
{
window.y = std::max(8, GAME_HEIGHT - mCounter + 100);
}
else
{
window.y = 0;
}
// Copia el backbuffer al renderizador
SDL_RenderCopy(mRenderer, mBackbuffer, nullptr, &window);

View File

@@ -2,120 +2,107 @@
#include "item.h"
// Constructor
Item::Item(LTexture *texture, SDL_Renderer *renderer, Uint8 type, float x, float y)
Item::Item(SDL_Renderer *renderer, Asset *asset, Uint8 type, float x, float y)
{
mSprite = new AnimatedSprite(texture, renderer);
mClass = type;
mEnabled = true;
mTimeToLive = 600;
mPosX = x;
mPosY = y;
mWidth = 16;
mHeight = 16;
mVelX = -1.0f + ((rand() % 5) * 0.5f);
mVelY = -4.0f;
mAccelX = 0.0f;
mAccelY = 0.2f;
mFloorCollision = false;
mCollider.r = mWidth / 2;
shiftColliders();
mSprite->setAnimationFrames(0, 0, 0, 48, mWidth, mHeight);
mSprite->setAnimationFrames(0, 1, 0, 64, mWidth, mHeight);
mSprite->setCurrentFrame(0);
mSprite->setAnimationCounter(0);
mSprite->setAnimationSpeed(0, 10);
mSprite->setAnimationLoop(0, true);
mSprite->setSpriteClip(mSprite->getAnimationClip(0, 0));
mSprite->setPosX(mPosX);
mSprite->setPosY(mPosY);
std::string filePNG;
std::string fileANI;
switch (type)
{
case NO_KIND:
mEnabled = false;
mTimeToLive = 0;
mPosX = 0;
mPosY = 0;
mWidth = 0;
mHeight = 0;
mVelX = 0;
mVelY = 0;
break;
case ITEM_POINTS_1_DISK:
mSprite->setAnimationFrames(0, 0, 16 * 0, 16 * 0, mWidth, mHeight);
mSprite->setAnimationFrames(0, 1, 16 * 0, 16 * 1, mWidth, mHeight);
filePNG = asset->get("item_points1_disk.png");
fileANI = asset->get("item_points1_disk.ani");
break;
case ITEM_POINTS_2_GAVINA:
mSprite->setAnimationFrames(0, 0, 16 * 1, 16 * 0, mWidth, mHeight);
mSprite->setAnimationFrames(0, 1, 16 * 1, 16 * 1, mWidth, mHeight);
filePNG = asset->get("item_points2_gavina.png");
fileANI = asset->get("item_points2_gavina.ani");
break;
case ITEM_POINTS_3_PACMAR:
mSprite->setAnimationFrames(0, 0, 16 * 2, 16 * 0, mWidth, mHeight);
mSprite->setAnimationFrames(0, 1, 16 * 2, 16 * 1, mWidth, mHeight);
filePNG = asset->get("item_points3_pacmar.png");
fileANI = asset->get("item_points3_pacmar.ani");
break;
case ITEM_CLOCK:
mSprite->setAnimationFrames(0, 0, 16 * 3, 16 * 0, mWidth, mHeight);
mSprite->setAnimationFrames(0, 1, 16 * 3, 16 * 1, mWidth, mHeight);
filePNG = asset->get("item_clock.png");
fileANI = asset->get("item_clock.ani");
break;
case ITEM_COFFEE:
mSprite->setAnimationFrames(0, 0, 16 * 5, 16 * 0, mWidth, mHeight);
mSprite->setAnimationFrames(0, 1, 16 * 5, 16 * 1, mWidth, mHeight);
filePNG = asset->get("item_coffee.png");
fileANI = asset->get("item_coffee.ani");
break;
case ITEM_COFFEE_MACHINE:
mWidth = 32;
mHeight = 32;
mPosX = (((int)x + (PLAY_AREA_WIDTH / 2)) % (PLAY_AREA_WIDTH - mWidth - 5)) + 2;
mPosY = PLAY_AREA_TOP - mHeight;
mVelX = 0.0f;
mVelY = -0.1f;
mAccelY = 0.1f;
mSprite->setAnimationFrames(0, 0, 32 * 0, 16 * 2, mWidth, mHeight);
mSprite->setAnimationFrames(0, 1, 32 * 1, 16 * 2, mWidth, mHeight);
mSprite->setAnimationFrames(0, 2, 32 * 2, 16 * 2, mWidth, mHeight);
mSprite->setAnimationFrames(0, 3, 32 * 3, 16 * 2, mWidth, mHeight);
mSprite->setPosX(mPosX);
mSprite->setPosY(mPosY);
mCollider.r = 10;
shiftColliders();
filePNG = asset->get("item_coffee_machine.png");
fileANI = asset->get("item_coffee_machine.ani");
break;
default:
break;
}
texture = new LTexture(renderer, filePNG);
sprite = new AnimatedSprite(texture, renderer, fileANI);
this->type = type;
enabled = true;
timeToLive = 600;
accelX = 0.0f;
floorCollision = false;
if (type == ITEM_COFFEE_MACHINE)
{
width = 32;
height = 32;
posX = (((int)x + (PLAY_AREA_WIDTH / 2)) % (PLAY_AREA_WIDTH - width - 5)) + 2;
posY = PLAY_AREA_TOP - height;
velX = 0.0f;
velY = -0.1f;
accelY = 0.1f;
collider.r = 10;
}
else
{
width = 16;
height = 16;
posX = x;
posY = y;
velX = -1.0f + ((rand() % 5) * 0.5f);
velY = -4.0f;
accelY = 0.2f;
collider.r = width / 2;
}
sprite->setPosX(posX);
sprite->setPosY(posY);
shiftColliders();
}
// Destructor
Item::~Item()
{
delete mSprite;
mSprite = nullptr;
delete texture;
delete sprite;
}
// Centra el objeto en la posición X
void Item::allignTo(int x)
{
mPosX = float(x - (mWidth / 2));
posX = float(x - (width / 2));
if (mPosX < PLAY_AREA_LEFT)
if (posX < PLAY_AREA_LEFT)
{
mPosX = PLAY_AREA_LEFT + 1;
posX = PLAY_AREA_LEFT + 1;
}
else if ((mPosX + mWidth) > PLAY_AREA_RIGHT)
else if ((posX + width) > PLAY_AREA_RIGHT)
{
mPosX = float(PLAY_AREA_RIGHT - mWidth - 1);
posX = float(PLAY_AREA_RIGHT - width - 1);
}
// Posición X,Y del sprite
mSprite->setPosX(int(mPosX));
mSprite->setPosY(int(mPosY));
sprite->setPosX(int(posX));
sprite->setPosY(int(posY));
// Alinea el circulo de colisión con el objeto
shiftColliders();
@@ -124,15 +111,15 @@ void Item::allignTo(int x)
// Pinta el objeto en la pantalla
void Item::render()
{
if (mEnabled)
if (enabled)
{
if (mTimeToLive > 200)
if (timeToLive > 200)
{
mSprite->render();
sprite->render();
}
else if (mTimeToLive % 20 > 10)
else if (timeToLive % 20 > 10)
{
mSprite->render();
sprite->render();
}
}
}
@@ -140,71 +127,73 @@ void Item::render()
// Actualiza la posición y estados del objeto
void Item::move()
{
mFloorCollision = false;
floorCollision = false;
// Calcula la nueva posición
mPosX += mVelX;
mPosY += mVelY;
posX += velX;
posY += velY;
// Aplica las aceleraciones a la velocidad
mVelX += mAccelX;
mVelY += mAccelY;
velX += accelX;
velY += accelY;
// Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido
if ((mPosX < PLAY_AREA_LEFT) || (mPosX + mWidth > PLAY_AREA_RIGHT))
if ((posX < PLAY_AREA_LEFT) || (posX + width > PLAY_AREA_RIGHT))
{
// Corregir posición
mPosX -= mVelX;
posX -= velX;
// Invertir sentido
mVelX = -mVelX;
velX = -velX;
}
// Si se sale por arriba rebota (excepto la maquina de café)
if ((mPosY < PLAY_AREA_TOP) && !(mClass == ITEM_COFFEE_MACHINE))
if ((posY < PLAY_AREA_TOP) && !(type == ITEM_COFFEE_MACHINE))
{
// Corrige
mPosY = PLAY_AREA_TOP;
posY = PLAY_AREA_TOP;
// Invierte el sentido
mVelY = -mVelY;
velY = -velY;
}
// Si el objeto se sale por la parte inferior
if (mPosY + mHeight > PLAY_AREA_BOTTOM)
if (posY + height > PLAY_AREA_BOTTOM)
{
// Corrige
mPosY -= mVelY;
posY -= velY;
// Detiene el objeto
mVelY = 0;
mVelX = 0;
mAccelX = 0;
mAccelY = 0;
mPosY = PLAY_AREA_BOTTOM - mHeight;
if (mClass == ITEM_COFFEE_MACHINE)
mFloorCollision = true;
velY = 0;
velX = 0;
accelX = 0;
accelY = 0;
posY = PLAY_AREA_BOTTOM - height;
if (type == ITEM_COFFEE_MACHINE)
{
floorCollision = true;
}
}
// Actualiza la posición del sprite
mSprite->setPosX(int(mPosX));
mSprite->setPosY(int(mPosY));
sprite->setPosX(int(posX));
sprite->setPosY(int(posY));
shiftColliders();
}
// Pone a cero todos los valores del objeto
void Item::erase()
void Item::disable()
{
// init(NO_KIND, 0, 0, nullptr, nullptr);
enabled = false;
}
// Actualiza el objeto a su posicion, animación y controla los contadores
void Item::update()
{
if (mEnabled)
if (enabled)
{
move();
shiftColliders();
mSprite->animate();
sprite->animate();
updateTimeToLive();
checkTimeToLive();
}
@@ -213,76 +202,70 @@ void Item::update()
// Actualiza el contador
void Item::updateTimeToLive()
{
if (mTimeToLive > 0)
if (timeToLive > 0)
{
mTimeToLive--;
timeToLive--;
}
}
// Comprueba si el objeto sigue vivo
void Item::checkTimeToLive()
{
if (mTimeToLive == 0)
erase();
if (timeToLive == 0)
disable();
}
// Obtiene del valor de la variable
float Item::getPosX()
{
return mPosX;
return posX;
}
// Obtiene del valor de la variable
float Item::getPosY()
{
return mPosY;
return posY;
}
// Obtiene del valor de la variable
int Item::getWidth()
{
return mWidth;
return width;
}
// Obtiene del valor de la variable
int Item::getHeight()
{
return mHeight;
return height;
}
// Obtiene del valor de la variable
int Item::getClass()
{
return mClass;
return type;
}
// Obtiene el valor de la variable
bool Item::isEnabled()
{
return mEnabled;
}
// Establece el valor de la variable
void Item::setEnabled(bool value)
{
mEnabled = value;
return enabled;
}
// Obtiene el circulo de colisión
circle_t &Item::getCollider()
{
return mCollider;
return collider;
}
// Alinea el circulo de colisión con la posición del objeto
void Item::shiftColliders()
{
mCollider.x = int(mPosX + (mWidth / 2));
mCollider.y = int(mPosY + (mHeight / 2));
collider.x = int(posX + (width / 2));
collider.y = int(posY + (height / 2));
}
// Informa si el objeto ha colisionado con el suelo
bool Item::floorCollision()
bool Item::isOnFloor()
{
return mFloorCollision;
return floorCollision;
}

View File

@@ -20,30 +20,35 @@
class Item
{
private:
float mPosX; // Posición X del objeto
float mPosY; // Posición Y del objeto
Uint8 mWidth; // Ancho del objeto
Uint8 mHeight; // Alto del objeto
float mVelX; // Velocidad en el eje X
float mVelY; // Velocidad en el eje Y
float mAccelX; // Aceleración en el eje X
float mAccelY; // Aceleración en el eje Y
bool mFloorCollision; // Indica si el objeto colisiona con el suelo
// Objetos
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
AnimatedSprite *sprite; // Sprite con los graficos del objeto
LTexture *texture; // Objeto con los graficos del item
AnimatedSprite *mSprite; // Sprite con los graficos del objeto
Uint8 mClass; // Especifica el tipo de objeto que es
bool mEnabled; // Especifica si el objeto está habilitado
circle_t mCollider; // Circulo de colisión del objeto
// Variables
float posX; // Posición X del objeto
float posY; // Posición Y del objeto
Uint8 width; // Ancho del objeto
Uint8 height; // Alto del objeto
float velX; // Velocidad en el eje X
float velY; // Velocidad en el eje Y
float accelX; // Aceleración en el eje X
float accelY; // Aceleración en el eje Y
bool floorCollision; // Indica si el objeto colisiona con el suelo
Uint8 type; // Especifica el tipo de objeto que es
bool enabled; // Especifica si el objeto está habilitado
circle_t collider; // Circulo de colisión del objeto
// Alinea el circulo de colisión con la posición del objeto
void shiftColliders();
// Actualiza la posición y estados del objeto
void move();
public:
Uint16 mTimeToLive; // Temporizador con el tiempo que el objeto está presente
Uint16 timeToLive; // Temporizador con el tiempo que el objeto está presente
// Constructor
Item(LTexture *texture, SDL_Renderer *renderer, Uint8 type, float x, float y);
Item(SDL_Renderer *renderer, Asset *asset, Uint8 type, float x, float y);
// Destructor
~Item();
@@ -54,11 +59,9 @@ public:
// Pinta el objeto en la pantalla
void render();
// Actualiza la posición y estados del objeto
void move();
// Pone a cero todos los valores del objeto
void erase();
void disable();
// Actualiza al objeto a su posicion, animación y controla los contadores
void update();
@@ -87,14 +90,11 @@ public:
// Obtiene el valor de la variable
bool isEnabled();
// Establece el valor de la variable
void setEnabled(bool value);
// Obtiene el circulo de colisión
circle_t &getCollider();
// Informa si el objeto ha colisionado con el suelo
bool floorCollision();
bool isOnFloor();
};
#endif