Compare commits
3 Commits
4ac7496eff
...
91b868572e
| Author | SHA1 | Date | |
|---|---|---|---|
| 91b868572e | |||
| 9c35fadd55 | |||
| 80ca04fd64 |
|
Before Width: | Height: | Size: 57 KiB |
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=60,61,62,63,64,65,66,67,68,69,70,71
|
||||||
|
[/animation]
|
||||||
BIN
data/gfx/balloon1.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
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=60,61,62,63,64,65,66,67,68,69,70,71
|
||||||
|
[/animation]
|
||||||
BIN
data/gfx/balloon2.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
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=60,61,62,63,64,65,66,67,68,69,70,71
|
||||||
|
[/animation]
|
||||||
BIN
data/gfx/balloon3.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
44
data/gfx/balloon4.ani
Normal 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
|
After Width: | Height: | Size: 13 KiB |
9
data/gfx/item_clock.ani
Normal 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
|
After Width: | Height: | Size: 334 B |
9
data/gfx/item_coffee.ani
Normal 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
|
After Width: | Height: | Size: 462 B |
9
data/gfx/item_coffee_machine.ani
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
frameWidth=23
|
||||||
|
frameHeight=29
|
||||||
|
|
||||||
|
[animation]
|
||||||
|
name=default
|
||||||
|
speed=10
|
||||||
|
loop=0
|
||||||
|
frames=0,1,2,3
|
||||||
|
[/animation]
|
||||||
BIN
data/gfx/item_coffee_machine.png
Normal file
|
After Width: | Height: | Size: 553 B |
9
data/gfx/item_points1_disk.ani
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
frameWidth=16
|
||||||
|
frameHeight=16
|
||||||
|
|
||||||
|
[animation]
|
||||||
|
name=default
|
||||||
|
speed=10
|
||||||
|
loop=0
|
||||||
|
frames=0,1
|
||||||
|
[/animation]
|
||||||
BIN
data/gfx/item_points1_disk.png
Normal file
|
After Width: | Height: | Size: 263 B |
9
data/gfx/item_points2_gavina.ani
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
frameWidth=16
|
||||||
|
frameHeight=16
|
||||||
|
|
||||||
|
[animation]
|
||||||
|
name=default
|
||||||
|
speed=10
|
||||||
|
loop=0
|
||||||
|
frames=0,1
|
||||||
|
[/animation]
|
||||||
BIN
data/gfx/item_points2_gavina.png
Normal file
|
After Width: | Height: | Size: 422 B |
9
data/gfx/item_points3_pacmar.ani
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
frameWidth=16
|
||||||
|
frameHeight=16
|
||||||
|
|
||||||
|
[animation]
|
||||||
|
name=default
|
||||||
|
speed=10
|
||||||
|
loop=0
|
||||||
|
frames=0,1
|
||||||
|
[/animation]
|
||||||
BIN
data/gfx/item_points3_pacmar.png
Normal file
|
After Width: | Height: | Size: 388 B |
@@ -2,22 +2,11 @@
|
|||||||
#include "balloon.h"
|
#include "balloon.h"
|
||||||
|
|
||||||
// Constructor
|
// 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();
|
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)
|
switch (kind)
|
||||||
{
|
{
|
||||||
case BALLOON_1:
|
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
|
// Amenaza que genera el globo
|
||||||
mMenace = 1;
|
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;
|
break;
|
||||||
|
|
||||||
case BALLOON_2:
|
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
|
// Amenaza que genera el globo
|
||||||
mMenace = 2;
|
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;
|
break;
|
||||||
|
|
||||||
case BALLOON_3:
|
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
|
// Amenaza que genera el globo
|
||||||
mMenace = 4;
|
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;
|
break;
|
||||||
|
|
||||||
case BALLOON_4:
|
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
|
// Amenaza que genera el globo
|
||||||
mMenace = 8;
|
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;
|
break;
|
||||||
|
|
||||||
case HEXAGON_1:
|
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
|
// Amenaza que genera el globo
|
||||||
mMenace = 1;
|
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;
|
break;
|
||||||
|
|
||||||
case HEXAGON_2:
|
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
|
// Amenaza que genera el globo
|
||||||
mMenace = 2;
|
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;
|
break;
|
||||||
|
|
||||||
case HEXAGON_3:
|
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
|
// Amenaza que genera el globo
|
||||||
mMenace = 4;
|
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;
|
break;
|
||||||
|
|
||||||
case HEXAGON_4:
|
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
|
// Amenaza que genera el globo
|
||||||
mMenace = 8;
|
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;
|
break;
|
||||||
|
|
||||||
case POWER_BALL:
|
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
|
// Amenaza que genera el globo
|
||||||
mMenace = 0;
|
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
|
// Añade rotación al sprite
|
||||||
mSprite->setRotate(false);
|
mSprite->setRotate(false);
|
||||||
mSprite->setRotateSpeed(1);
|
mSprite->setRotateSpeed(1);
|
||||||
mSprite->setRotateAmount(2.0);
|
mSprite->setRotateAmount(2.0);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
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.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};
|
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
|
// Alto y ancho del sprite
|
||||||
mSprite->setWidth(mWidth);
|
mSprite->setWidth(mWidth);
|
||||||
mSprite->setHeight(mHeight);
|
mSprite->setHeight(mHeight);
|
||||||
@@ -401,25 +289,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
|
|||||||
// Tipo
|
// Tipo
|
||||||
mKind = kind;
|
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
|
// Selecciona un frame para pintar
|
||||||
mSprite->setSpriteClip(mSprite->getAnimationClip(0, 0));
|
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()
|
Balloon::~Balloon()
|
||||||
{
|
{
|
||||||
delete mSprite;
|
delete mSprite;
|
||||||
mSprite = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Centra el globo en la posición X
|
// Centra el globo en la posición X
|
||||||
@@ -640,9 +508,13 @@ void Balloon::updateState()
|
|||||||
disable();
|
disable();
|
||||||
}
|
}
|
||||||
else if (mTimeToLive > 0)
|
else if (mTimeToLive > 0)
|
||||||
|
{
|
||||||
mTimeToLive--;
|
mTimeToLive--;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
disable();
|
disable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si se está creando
|
// Si se está creando
|
||||||
@@ -690,9 +562,13 @@ void Balloon::updateState()
|
|||||||
{
|
{
|
||||||
mSprite->setRotate(true);
|
mSprite->setRotate(true);
|
||||||
if (mVelX > 0.0f)
|
if (mVelX > 0.0f)
|
||||||
|
{
|
||||||
mSprite->setRotateAmount(2.0);
|
mSprite->setRotateAmount(2.0);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
mSprite->setRotateAmount(-2.0);
|
mSprite->setRotateAmount(-2.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -718,15 +594,15 @@ void Balloon::updateAnimation()
|
|||||||
// Establece el frame de animación
|
// Establece el frame de animación
|
||||||
if (isPopping())
|
if (isPopping())
|
||||||
{
|
{
|
||||||
mSprite->setCurrentAnimation(BALLOON_POP_ANIMATION);
|
mSprite->setCurrentAnimation("pop");
|
||||||
}
|
}
|
||||||
else if (isBeingCreated())
|
else if (isBeingCreated())
|
||||||
{
|
{
|
||||||
mSprite->setCurrentAnimation(BALLOON_BORN_ANIMATION);
|
mSprite->setCurrentAnimation("blue");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mSprite->setCurrentAnimation(BALLOON_MOVING_ANIMATION);
|
mSprite->setCurrentAnimation("orange");
|
||||||
}
|
}
|
||||||
|
|
||||||
mSprite->animate();
|
mSprite->animate();
|
||||||
@@ -796,11 +672,17 @@ Uint8 Balloon::getSize()
|
|||||||
Uint8 Balloon::getClass()
|
Uint8 Balloon::getClass()
|
||||||
{
|
{
|
||||||
if ((mKind >= BALLOON_1) && (mKind <= BALLOON_4))
|
if ((mKind >= BALLOON_1) && (mKind <= BALLOON_4))
|
||||||
|
{
|
||||||
return BALLOON_CLASS;
|
return BALLOON_CLASS;
|
||||||
|
}
|
||||||
else if ((mKind >= HEXAGON_1) && (mKind <= HEXAGON_4))
|
else if ((mKind >= HEXAGON_1) && (mKind <= HEXAGON_4))
|
||||||
|
{
|
||||||
return HEXAGON_CLASS;
|
return HEXAGON_CLASS;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
@@ -922,9 +804,13 @@ void Balloon::updateColliders()
|
|||||||
Uint8 Balloon::getMenace()
|
Uint8 Balloon::getMenace()
|
||||||
{
|
{
|
||||||
if (isEnabled())
|
if (isEnabled())
|
||||||
|
{
|
||||||
return mMenace;
|
return mMenace;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene le valor de la variable
|
// Obtiene le valor de la variable
|
||||||
@@ -968,6 +854,8 @@ void Balloon::updateBounce()
|
|||||||
mBouncing.despY = (mSprite->getSpriteClip().h - (mSprite->getSpriteClip().h * mBouncing.zoomH));
|
mBouncing.despY = (mSprite->getSpriteClip().h - (mSprite->getSpriteClip().h * mBouncing.zoomH));
|
||||||
mBouncing.counter++;
|
mBouncing.counter++;
|
||||||
if ((mBouncing.counter / mBouncing.speed) > (MAX_BOUNCE - 1))
|
if ((mBouncing.counter / mBouncing.speed) > (MAX_BOUNCE - 1))
|
||||||
|
{
|
||||||
bounceStop();
|
bounceStop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,7 +146,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// 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
|
// Destructor
|
||||||
~Balloon();
|
~Balloon();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
// Constructor
|
// Constructor
|
||||||
Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, LTexture *texture, SDL_Renderer *renderer)
|
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
|
// Posición inicial del objeto
|
||||||
mPosX = x;
|
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
|
// Alto y ancho del objeto
|
||||||
mWidth = 10;
|
mWidth = 10;
|
||||||
mHeight = mWidth;
|
mHeight = 10;
|
||||||
|
|
||||||
// Velocidad inicial en el eje Y
|
// Velocidad inicial en el eje Y
|
||||||
mVelY = -3;
|
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
|
// Rectangulo con los gráficos del objeto
|
||||||
if (!poweredUp)
|
if (!poweredUp)
|
||||||
|
{
|
||||||
mSprite->setSpriteClip(0 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
mSprite->setSpriteClip(0 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
mSprite->setSpriteClip((0 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
mSprite->setSpriteClip((0 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BULLET_LEFT:
|
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
|
// Rectangulo con los gráficos del objeto
|
||||||
if (!poweredUp)
|
if (!poweredUp)
|
||||||
|
{
|
||||||
mSprite->setSpriteClip(1 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
mSprite->setSpriteClip(1 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
mSprite->setSpriteClip((1 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
mSprite->setSpriteClip((1 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BULLET_RIGHT:
|
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
|
// Rectangulo con los gráficos del objeto
|
||||||
if (!poweredUp)
|
if (!poweredUp)
|
||||||
|
{
|
||||||
mSprite->setSpriteClip(2 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
mSprite->setSpriteClip(2 * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
mSprite->setSpriteClip((2 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
mSprite->setSpriteClip((2 + 3) * mWidth, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -74,7 +86,6 @@ Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, LTexture *text
|
|||||||
Bullet::~Bullet()
|
Bullet::~Bullet()
|
||||||
{
|
{
|
||||||
delete mSprite;
|
delete mSprite;
|
||||||
mSprite = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el objeto en pantalla
|
// Pinta el objeto en pantalla
|
||||||
@@ -129,9 +140,19 @@ Uint8 Bullet::move()
|
|||||||
bool Bullet::isActive()
|
bool Bullet::isActive()
|
||||||
{
|
{
|
||||||
if (mKind == NO_KIND)
|
if (mKind == NO_KIND)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Desactiva el objeto
|
||||||
|
void Bullet::deactivate()
|
||||||
|
{
|
||||||
|
mKind = NO_KIND;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ public:
|
|||||||
// Comprueba si el objeto está activo
|
// Comprueba si el objeto está activo
|
||||||
bool isActive();
|
bool isActive();
|
||||||
|
|
||||||
|
// Desactiva el objeto
|
||||||
|
void deactivate();
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int getPosX();
|
int getPosX();
|
||||||
|
|
||||||
|
|||||||
@@ -189,13 +189,32 @@ bool Director::setFileList()
|
|||||||
asset->add("data/sound/powerball.wav", t_sound);
|
asset->add("data/sound/powerball.wav", t_sound);
|
||||||
|
|
||||||
// Texturas
|
// 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/bullet.png", t_bitmap);
|
||||||
asset->add("data/gfx/game_bg.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/game_text.png", t_bitmap);
|
||||||
asset->add("data/gfx/intro.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/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_bg_tile.png", t_bitmap);
|
||||||
asset->add("data/gfx/title_coffee.png", t_bitmap);
|
asset->add("data/gfx/title_coffee.png", t_bitmap);
|
||||||
|
|||||||
303
source/game.cpp
@@ -39,7 +39,10 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
|
|||||||
players.push_back(player2);
|
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"));
|
mTextureBullet = new LTexture(mRenderer, mAsset->get("bullet.png"));
|
||||||
mTextureGameBG = new LTexture(mRenderer, mAsset->get("game_bg.png"));
|
mTextureGameBG = new LTexture(mRenderer, mAsset->get("game_bg.png"));
|
||||||
mTextureGameText = new LTexture(mRenderer, mAsset->get("game_text.png"));
|
mTextureGameText = new LTexture(mRenderer, mAsset->get("game_text.png"));
|
||||||
@@ -112,9 +115,17 @@ Game::~Game()
|
|||||||
delete smartSprite;
|
delete smartSprite;
|
||||||
};
|
};
|
||||||
|
|
||||||
mTextureBalloon->unload();
|
balloon1Texture->unload();
|
||||||
delete mTextureBalloon;
|
delete balloon1Texture;
|
||||||
mTextureBalloon = nullptr;
|
|
||||||
|
balloon2Texture->unload();
|
||||||
|
delete balloon2Texture;
|
||||||
|
|
||||||
|
balloon3Texture->unload();
|
||||||
|
delete balloon3Texture;
|
||||||
|
|
||||||
|
balloon4Texture->unload();
|
||||||
|
delete balloon4Texture;
|
||||||
|
|
||||||
mTextureBullet->unload();
|
mTextureBullet->unload();
|
||||||
delete mTextureBullet;
|
delete mTextureBullet;
|
||||||
@@ -337,33 +348,33 @@ void Game::init()
|
|||||||
mFade->init(0x27, 0x27, 0x36);
|
mFade->init(0x27, 0x27, 0x36);
|
||||||
|
|
||||||
// Inicializa el objeto con el menu de pausa
|
// Inicializa el objeto con el menu de pausa
|
||||||
//mMenuPause->setName("PAUSE");
|
// mMenuPause->setName("PAUSE");
|
||||||
//mMenuPause->setPos(0, 12 * BLOCK);
|
// mMenuPause->setPos(0, 12 * BLOCK);
|
||||||
//mMenuPause->setBackgroundType(MENU_BACKGROUND_SOLID);
|
// mMenuPause->setBackgroundType(MENU_BACKGROUND_SOLID);
|
||||||
//mMenuPause->addItem(mLang->getText(46), 2);
|
// mMenuPause->addItem(mLang->getText(46), 2);
|
||||||
//mMenuPause->addItem(mLang->getText(47), 0);
|
// mMenuPause->addItem(mLang->getText(47), 0);
|
||||||
//mMenuPause->setDefaultActionWhenCancel(0);
|
// mMenuPause->setDefaultActionWhenCancel(0);
|
||||||
//mMenuPause->setBackgroundColor({0x29, 0x39, 0x41}, 240);
|
// mMenuPause->setBackgroundColor({0x29, 0x39, 0x41}, 240);
|
||||||
//mMenuPause->setSelectorColor({0xFF, 0x7A, 0x00}, 255);
|
// mMenuPause->setSelectorColor({0xFF, 0x7A, 0x00}, 255);
|
||||||
//mMenuPause->setSelectorTextColor({0xFF, 0xFF, 0xFF});
|
// mMenuPause->setSelectorTextColor({0xFF, 0xFF, 0xFF});
|
||||||
//mMenuPause->centerMenuOnX(SCREEN_CENTER_X);
|
// mMenuPause->centerMenuOnX(SCREEN_CENTER_X);
|
||||||
//mMenuPause->centerMenuElementsOnX();
|
// mMenuPause->centerMenuElementsOnX();
|
||||||
|
|
||||||
// Inicializa el objeto con el menu de la pantalla de game over
|
// Inicializa el objeto con el menu de la pantalla de game over
|
||||||
//mMenuGameOver->setName("GAME OVER");
|
// mMenuGameOver->setName("GAME OVER");
|
||||||
//mMenuGameOver->setPos(0, PLAY_AREA_CENTER_Y + BLOCK * 4);
|
// mMenuGameOver->setPos(0, PLAY_AREA_CENTER_Y + BLOCK * 4);
|
||||||
//mMenuGameOver->setBackgroundType(MENU_BACKGROUND_TRANSPARENT);
|
// mMenuGameOver->setBackgroundType(MENU_BACKGROUND_TRANSPARENT);
|
||||||
//mMenuGameOver->addItem(mLang->getText(48), 2);
|
// mMenuGameOver->addItem(mLang->getText(48), 2);
|
||||||
//mMenuGameOver->addItem(mLang->getText(49));
|
// mMenuGameOver->addItem(mLang->getText(49));
|
||||||
//mMenuGameOver->setDefaultActionWhenCancel(1);
|
// mMenuGameOver->setDefaultActionWhenCancel(1);
|
||||||
//mMenuGameOver->setBackgroundColor({0, 0, 0}, 255);
|
// mMenuGameOver->setBackgroundColor({0, 0, 0}, 255);
|
||||||
//mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 255);
|
// mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 255);
|
||||||
//mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 0);
|
// mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 0);
|
||||||
//mMenuGameOver->setSelectorTextColor({0xFF, 0xFF, 0xFF});
|
// mMenuGameOver->setSelectorTextColor({0xFF, 0xFF, 0xFF});
|
||||||
//mMenuGameOver->setSelectorTextColor({0xFF, 0xF1, 0x76});
|
// mMenuGameOver->setSelectorTextColor({0xFF, 0xF1, 0x76});
|
||||||
//mMenuGameOver->setSelectorTextColor({0xFF, 0x7A, 0x00});
|
// mMenuGameOver->setSelectorTextColor({0xFF, 0x7A, 0x00});
|
||||||
//mMenuGameOver->centerMenuOnX(SCREEN_CENTER_X);
|
// mMenuGameOver->centerMenuOnX(SCREEN_CENTER_X);
|
||||||
//mMenuGameOver->centerMenuElementsOnX();
|
// mMenuGameOver->centerMenuElementsOnX();
|
||||||
|
|
||||||
// Sprites
|
// Sprites
|
||||||
mClouds1a->setSpriteClip(256, 0, 256, 52);
|
mClouds1a->setSpriteClip(256, 0, 256, 52);
|
||||||
@@ -1386,15 +1397,16 @@ void Game::deployEnemyFormation()
|
|||||||
if (mDebug.enabled)
|
if (mDebug.enabled)
|
||||||
set = mDebug.enemySet;
|
set = mDebug.enemySet;
|
||||||
|
|
||||||
Uint8 numEnemies = mStage[mCurrentStage].enemyPool->set[set]->numberOfEnemies;
|
const Uint8 numEnemies = mStage[mCurrentStage].enemyPool->set[set]->numberOfEnemies;
|
||||||
for (int i = 0; i < numEnemies; i++)
|
for (int i = 0; i < numEnemies; ++i)
|
||||||
|
{
|
||||||
createNewBalloon(mStage[mCurrentStage].enemyPool->set[set]->init[i].x,
|
createNewBalloon(mStage[mCurrentStage].enemyPool->set[set]->init[i].x,
|
||||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].y,
|
mStage[mCurrentStage].enemyPool->set[set]->init[i].y,
|
||||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].kind,
|
mStage[mCurrentStage].enemyPool->set[set]->init[i].kind,
|
||||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].velX,
|
mStage[mCurrentStage].enemyPool->set[set]->init[i].velX,
|
||||||
mEnemySpeed,
|
mEnemySpeed,
|
||||||
mStage[mCurrentStage].enemyPool->set[set]->init[i].creationCounter,
|
mStage[mCurrentStage].enemyPool->set[set]->init[i].creationCounter);
|
||||||
mTextureBalloon);
|
}
|
||||||
|
|
||||||
mEnemyDeployCounter = 300;
|
mEnemyDeployCounter = 300;
|
||||||
}
|
}
|
||||||
@@ -1754,11 +1766,12 @@ void Game::renderBalloons()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea un globo nuevo en el vector de globos
|
// 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);
|
const std::string file = balloonAnimation(kind);
|
||||||
//balloons.push_back(b);
|
Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, balloonTexture(kind), file, mRenderer);
|
||||||
//return (Uint8)(balloons.size() - 1);
|
balloons.push_back(b);
|
||||||
|
return (Uint8)(balloons.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea una PowerBall
|
// Crea una PowerBall
|
||||||
@@ -1773,7 +1786,7 @@ void Game::createPowerBall()
|
|||||||
const int x[3] = {left, center, right};
|
const int x[3] = {left, center, right};
|
||||||
const int posX = x[rand() % 3];
|
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);
|
balloons.push_back(b);
|
||||||
|
|
||||||
mPowerBallEnabled = true;
|
mPowerBallEnabled = true;
|
||||||
@@ -1897,28 +1910,27 @@ void Game::popBalloon(Balloon *balloon)
|
|||||||
|
|
||||||
// En cualquier otro caso, crea dos globos de un tipo inferior
|
// En cualquier otro caso, crea dos globos de un tipo inferior
|
||||||
default:
|
default:
|
||||||
Balloon *b1 = new Balloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_NEGATIVE, mEnemySpeed, 0, mTextureBalloon, mRenderer);
|
// Balloon *b1 = new Balloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_NEGATIVE, mEnemySpeed, 0, mRenderer);
|
||||||
balloons.push_back(b1);
|
const int index = createNewBalloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_NEGATIVE, mEnemySpeed, 0);
|
||||||
b1->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
balloons.at(index)->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
||||||
if (b1->getClass() == BALLOON_CLASS)
|
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);
|
const int index2 = createNewBalloon(0, balloon->getPosY(), balloon->getKind() - 1, BALLOON_VELX_POSITIVE, mEnemySpeed, 0);
|
||||||
balloons.push_back(b2);
|
balloons.at(index2)->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
||||||
b2->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
|
if (balloons.at(index2)->getClass() == BALLOON_CLASS)
|
||||||
if (b2->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
|
// Elimina el globo
|
||||||
@@ -2059,6 +2071,74 @@ Uint8 Game::countBalloons()
|
|||||||
return num;
|
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
|
// Comprueba la colisión entre el jugador y los globos activos
|
||||||
bool Game::checkPlayerBalloonCollision(Player *player)
|
bool Game::checkPlayerBalloonCollision(Player *player)
|
||||||
{
|
{
|
||||||
@@ -2134,7 +2214,7 @@ void Game::checkPlayerItemCollision(Player *player)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
item->erase();
|
item->disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2153,8 +2233,8 @@ void Game::checkBulletBalloonCollision()
|
|||||||
{
|
{
|
||||||
// Otorga los puntos correspondientes al globo al jugador que disparó la bala
|
// Otorga los puntos correspondientes al globo al jugador que disparó la bala
|
||||||
int index = bullet->getOwner();
|
int index = bullet->getOwner();
|
||||||
players[index]->incScoreMultiplier();
|
players.at(index)->incScoreMultiplier();
|
||||||
players[index]->addScore(Uint32(balloon->getScore() * players[index]->getScoreMultiplier() * mDifficultyScoreMultiplier));
|
players.at(index)->addScore(Uint32(balloon->getScore() * players.at(index)->getScoreMultiplier() * mDifficultyScoreMultiplier));
|
||||||
updateHiScore();
|
updateHiScore();
|
||||||
|
|
||||||
// Explota el globo
|
// Explota el globo
|
||||||
@@ -2166,8 +2246,8 @@ void Game::checkBulletBalloonCollision()
|
|||||||
JA_PlaySound(mSoundBalloon);
|
JA_PlaySound(mSoundBalloon);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destruye la bala
|
// Desactiva la bala
|
||||||
delete bullet;
|
bullet->deactivate();
|
||||||
|
|
||||||
// Suelta el item en caso de que salga uno
|
// Suelta el item en caso de que salga uno
|
||||||
const Uint8 droppeditem = dropItem();
|
const Uint8 droppeditem = dropItem();
|
||||||
@@ -2175,12 +2255,12 @@ void Game::checkBulletBalloonCollision()
|
|||||||
{
|
{
|
||||||
if (droppeditem != ITEM_COFFEE_MACHINE)
|
if (droppeditem != ITEM_COFFEE_MACHINE)
|
||||||
{
|
{
|
||||||
createItem(mTextureItems, mRenderer, balloon->getPosX(), balloon->getPosY(), droppeditem);
|
createItem(balloon->getPosX(), balloon->getPosY(), droppeditem);
|
||||||
JA_PlaySound(mSoundItemDrop);
|
JA_PlaySound(mSoundItemDrop);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
createItem(mTextureItems, mRenderer, players[index]->getPosX(), 0, droppeditem);
|
createItem(players.at(index)->getPosX(), 0, droppeditem);
|
||||||
mCoffeeMachineEnabled = true;
|
mCoffeeMachineEnabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2200,7 +2280,7 @@ void Game::moveBullets()
|
|||||||
{
|
{
|
||||||
if (bullet->move() == BULLET_MOVE_OUT)
|
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);
|
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
|
// Actualiza los items
|
||||||
void Game::updateItems()
|
void Game::updateItems()
|
||||||
{
|
{
|
||||||
for (auto item : items)
|
for (auto item : items)
|
||||||
{
|
{
|
||||||
item->update();
|
item->update();
|
||||||
if (item->floorCollision())
|
if (item->isOnFloor())
|
||||||
{
|
{
|
||||||
JA_PlaySound(mSoundCollision);
|
JA_PlaySound(mSoundCollision);
|
||||||
mEffect.shake = true;
|
mEffect.shake = true;
|
||||||
@@ -2317,20 +2413,36 @@ Uint8 Game::dropItem()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea un objeto item
|
// 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);
|
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
|
// Crea un objeto SmartSprite para mostrar la puntuación al coger un objeto
|
||||||
void Game::createItemScoreSprite(int x, int y, SmartSprite *sprite)
|
void Game::createItemScoreSprite(int x, int y, SmartSprite *sprite)
|
||||||
{
|
{
|
||||||
SmartSprite *ss = new SmartSprite(nullptr, mRenderer);
|
SmartSprite *ss = new SmartSprite(nullptr, mRenderer);
|
||||||
smartSprites.push_back(ss);
|
smartSprites.push_back(ss);
|
||||||
|
|
||||||
// Crea una copia del objeto
|
// Crea una copia del objeto
|
||||||
*ss = *sprite;
|
*ss = *sprite;
|
||||||
ss->setPosX(x);
|
ss->setPosX(x);
|
||||||
ss->setPosY(y);
|
ss->setPosY(y);
|
||||||
ss->setDestX(x);
|
ss->setDestX(x);
|
||||||
@@ -2398,7 +2510,7 @@ void Game::throwPlayer(int x, int y, Player *player)
|
|||||||
{
|
{
|
||||||
const int sentit = ((rand() % 2) ? 1 : -1);
|
const int sentit = ((rand() % 2) ? 1 : -1);
|
||||||
|
|
||||||
//player->deathIndex = getSmartSpriteFreeIndex();
|
// player->deathIndex = getSmartSpriteFreeIndex();
|
||||||
|
|
||||||
SmartSprite *ss = new SmartSprite(nullptr, mRenderer);
|
SmartSprite *ss = new SmartSprite(nullptr, mRenderer);
|
||||||
smartSprites.push_back(ss);
|
smartSprites.push_back(ss);
|
||||||
@@ -2422,7 +2534,7 @@ void Game::throwPlayer(int x, int y, Player *player)
|
|||||||
// Actualiza los SmartSprites
|
// Actualiza los SmartSprites
|
||||||
void Game::updateSmartSprites()
|
void Game::updateSmartSprites()
|
||||||
{
|
{
|
||||||
for (auto ss:smartSprites)
|
for (auto ss : smartSprites)
|
||||||
{
|
{
|
||||||
ss->update();
|
ss->update();
|
||||||
}
|
}
|
||||||
@@ -2431,7 +2543,7 @@ void Game::updateSmartSprites()
|
|||||||
// Pinta los SmartSprites activos
|
// Pinta los SmartSprites activos
|
||||||
void Game::renderSmartSprites()
|
void Game::renderSmartSprites()
|
||||||
{
|
{
|
||||||
for (auto ss:smartSprites)
|
for (auto ss : smartSprites)
|
||||||
{
|
{
|
||||||
ss->render();
|
ss->render();
|
||||||
}
|
}
|
||||||
@@ -2474,7 +2586,7 @@ void Game::killPlayer(Player *player)
|
|||||||
void Game::evaluateAndSetMenace()
|
void Game::evaluateAndSetMenace()
|
||||||
{
|
{
|
||||||
mMenaceCurrent = 0;
|
mMenaceCurrent = 0;
|
||||||
for (auto balloon:balloons)
|
for (auto balloon : balloons)
|
||||||
{
|
{
|
||||||
if (balloon->isEnabled())
|
if (balloon->isEnabled())
|
||||||
{
|
{
|
||||||
@@ -2591,6 +2703,11 @@ void Game::updatePlayField()
|
|||||||
|
|
||||||
// Actualiza el tramo final de juego, una vez completado
|
// Actualiza el tramo final de juego, una vez completado
|
||||||
updateGameCompleted();
|
updateGameCompleted();
|
||||||
|
|
||||||
|
// Vacia los vectores
|
||||||
|
freeBullets();
|
||||||
|
freeBalloons();
|
||||||
|
freeItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el fondo
|
// Actualiza el fondo
|
||||||
@@ -2671,12 +2788,12 @@ void Game::renderPlayField()
|
|||||||
renderSmartSprites();
|
renderSmartSprites();
|
||||||
renderScoreBoard();
|
renderScoreBoard();
|
||||||
|
|
||||||
for (auto player:players)
|
for (auto player : players)
|
||||||
{
|
{
|
||||||
player->render();
|
player->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mDeathCounter <= 150) && !players[0]->isAlive())
|
if ((mDeathCounter <= 150) && !players.at(0)->isAlive())
|
||||||
{
|
{
|
||||||
renderDeathFade(150 - mDeathCounter);
|
renderDeathFade(150 - mDeathCounter);
|
||||||
}
|
}
|
||||||
@@ -2687,6 +2804,8 @@ void Game::renderPlayField()
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderFlashEffect();
|
renderFlashEffect();
|
||||||
|
|
||||||
|
mText->write(0, 0, std::to_string(balloons.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestiona el nivel de amenaza
|
// Gestiona el nivel de amenaza
|
||||||
@@ -2725,45 +2844,45 @@ void Game::checkGameInput()
|
|||||||
const int index = 0;
|
const int index = 0;
|
||||||
if (mDemo.dataFile[mDemo.counter].left == 1)
|
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)
|
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)
|
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 (mDemo.dataFile[mDemo.counter].fire == 1)
|
||||||
{
|
{
|
||||||
if (players[index]->canFire())
|
if (players.at(index)->canFire())
|
||||||
{
|
{
|
||||||
players[index]->setInput(INPUT_BUTTON_2);
|
players.at(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);
|
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[index]->setFireCooldown(10);
|
players.at(index)->setFireCooldown(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mDemo.dataFile[mDemo.counter].fireLeft == 1)
|
if (mDemo.dataFile[mDemo.counter].fireLeft == 1)
|
||||||
{
|
{
|
||||||
if (players[index]->canFire())
|
if (players.at(index)->canFire())
|
||||||
{
|
{
|
||||||
players[index]->setInput(INPUT_BUTTON_1);
|
players.at(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);
|
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[index]->setFireCooldown(10);
|
players.at(index)->setFireCooldown(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mDemo.dataFile[mDemo.counter].fireRight == 1)
|
if (mDemo.dataFile[mDemo.counter].fireRight == 1)
|
||||||
{
|
{
|
||||||
if (players[index]->canFire())
|
if (players.at(index)->canFire())
|
||||||
{
|
{
|
||||||
players[index]->setInput(INPUT_BUTTON_3);
|
players.at(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);
|
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[index]->setFireCooldown(10);
|
players.at(index)->setFireCooldown(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2787,7 +2906,7 @@ void Game::checkGameInput()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto player:players)
|
for (auto player : players)
|
||||||
{
|
{
|
||||||
if (player->isAlive())
|
if (player->isAlive())
|
||||||
{
|
{
|
||||||
@@ -3016,7 +3135,7 @@ void Game::shakeScreen()
|
|||||||
renderBalloons();
|
renderBalloons();
|
||||||
renderBullets();
|
renderBullets();
|
||||||
renderItems();
|
renderItems();
|
||||||
for (auto player:players)
|
for (auto player : players)
|
||||||
{
|
{
|
||||||
player->render();
|
player->render();
|
||||||
}
|
}
|
||||||
@@ -3056,7 +3175,7 @@ section_t Game::run()
|
|||||||
// Reproduce la música
|
// Reproduce la música
|
||||||
if (!mGameCompleted)
|
if (!mGameCompleted)
|
||||||
{
|
{
|
||||||
if (players[0]->isAlive())
|
if (players.at(0)->isAlive())
|
||||||
{
|
{
|
||||||
JA_PlayMusic(mMusicPlaying);
|
JA_PlayMusic(mMusicPlaying);
|
||||||
}
|
}
|
||||||
@@ -3340,7 +3459,7 @@ int Game::calculateScreenPower()
|
|||||||
{
|
{
|
||||||
int power = 0;
|
int power = 0;
|
||||||
|
|
||||||
for (auto balloon:balloons)
|
for (auto balloon : balloons)
|
||||||
{
|
{
|
||||||
if (balloon->isEnabled())
|
if (balloon->isEnabled())
|
||||||
{
|
{
|
||||||
@@ -3431,7 +3550,7 @@ void Game::updateHelper()
|
|||||||
// Solo ofrece ayuda cuando la amenaza es elevada
|
// Solo ofrece ayuda cuando la amenaza es elevada
|
||||||
if (mMenaceCurrent > 15)
|
if (mMenaceCurrent > 15)
|
||||||
{
|
{
|
||||||
for (auto player:players)
|
for (auto player : players)
|
||||||
{
|
{
|
||||||
if (player->getCoffees() == 0)
|
if (player->getCoffees() == 0)
|
||||||
{
|
{
|
||||||
@@ -3463,7 +3582,7 @@ void Game::updateHelper()
|
|||||||
bool Game::allPlayersAreDead()
|
bool Game::allPlayersAreDead()
|
||||||
{
|
{
|
||||||
bool success = true;
|
bool success = true;
|
||||||
for (auto player:players)
|
for (auto player : players)
|
||||||
{
|
{
|
||||||
success &= (!player->isAlive());
|
success &= (!player->isAlive());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,11 +141,14 @@ private:
|
|||||||
std::vector<Item *> items; // Vector con los items
|
std::vector<Item *> items; // Vector con los items
|
||||||
std::vector<SmartSprite *> smartSprites; // Vector con los smartsprites
|
std::vector<SmartSprite *> smartSprites; // Vector con los smartsprites
|
||||||
|
|
||||||
LTexture *mTextureBalloon; // Textura para los enemigos
|
LTexture *balloon1Texture; // Textura para los enemigos
|
||||||
LTexture *mTextureBullet; // Textura para las balas
|
LTexture *balloon2Texture; // Textura para los enemigos
|
||||||
LTexture *mTextureGameBG; // Textura para el fondo del juego
|
LTexture *balloon3Texture; // Textura para los enemigos
|
||||||
LTexture *mTextureGameText; // Textura para los sprites con textos
|
LTexture *balloon4Texture; // Textura para los enemigos
|
||||||
LTexture *mTextureItems; // Textura para los items
|
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 *mText; // Fuente para los textos del juego
|
||||||
Text *mTextBig; // Fuente de texto grande
|
Text *mTextBig; // Fuente de texto grande
|
||||||
@@ -303,7 +306,7 @@ private:
|
|||||||
void renderBalloons();
|
void renderBalloons();
|
||||||
|
|
||||||
// Crea un globo nuevo en el vector de globos
|
// 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
|
// Crea una PowerBall
|
||||||
void createPowerBall();
|
void createPowerBall();
|
||||||
@@ -341,6 +344,15 @@ private:
|
|||||||
// Obtiene el numero de globos activos
|
// Obtiene el numero de globos activos
|
||||||
Uint8 countBalloons();
|
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
|
// Comprueba la colisión entre el jugador y los globos activos
|
||||||
bool checkPlayerBalloonCollision(Player *player);
|
bool checkPlayerBalloonCollision(Player *player);
|
||||||
|
|
||||||
@@ -359,6 +371,9 @@ private:
|
|||||||
// Crea un objeto bala
|
// Crea un objeto bala
|
||||||
void createBullet(int x, int y, Uint8 kind, bool poweredUp, int owner);
|
void createBullet(int x, int y, Uint8 kind, bool poweredUp, int owner);
|
||||||
|
|
||||||
|
// Vacia el vector de balas
|
||||||
|
void freeBullets();
|
||||||
|
|
||||||
// Actualiza los items
|
// Actualiza los items
|
||||||
void updateItems();
|
void updateItems();
|
||||||
|
|
||||||
@@ -369,7 +384,10 @@ private:
|
|||||||
Uint8 dropItem();
|
Uint8 dropItem();
|
||||||
|
|
||||||
// Crea un objeto item
|
// 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
|
// Crea un objeto SmartSprite
|
||||||
void createItemScoreSprite(int x, int y, SmartSprite *sprite);
|
void createItemScoreSprite(int x, int y, SmartSprite *sprite);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *mAsset
|
|||||||
|
|
||||||
// Reserva memoria para los punteros
|
// Reserva memoria para los punteros
|
||||||
mEventHandler = new SDL_Event();
|
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);
|
mSprite = new Sprite(0, 0, GAME_WIDTH, GAME_HEIGHT, mItemTexture, mRenderer);
|
||||||
mText = new Text(mAsset->get("smb2.png"), mAsset->get("smb2.txt"), 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
|
// Destructor
|
||||||
Instructions::~Instructions()
|
Instructions::~Instructions()
|
||||||
{
|
{
|
||||||
mRenderer = nullptr;
|
|
||||||
mScreen = nullptr;
|
|
||||||
mAsset = nullptr;
|
|
||||||
mLang = nullptr;
|
|
||||||
|
|
||||||
mItemTexture->unload();
|
mItemTexture->unload();
|
||||||
delete mItemTexture;
|
delete mItemTexture;
|
||||||
mItemTexture = nullptr;
|
|
||||||
|
|
||||||
delete mSprite;
|
delete mSprite;
|
||||||
mSprite = nullptr;
|
|
||||||
|
|
||||||
delete mEventHandler;
|
delete mEventHandler;
|
||||||
mEventHandler = nullptr;
|
|
||||||
|
|
||||||
delete mText;
|
delete mText;
|
||||||
mText = nullptr;
|
|
||||||
|
|
||||||
SDL_DestroyTexture(mBackbuffer);
|
SDL_DestroyTexture(mBackbuffer);
|
||||||
mBackbuffer = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa las variables necesarias para la sección 'Instructions'
|
// Inicializa las variables necesarias para la sección 'Instructions'
|
||||||
@@ -87,7 +75,9 @@ void Instructions::run(Uint8 mode)
|
|||||||
mSection.subsection = TITLE_SECTION_1;
|
mSection.subsection = TITLE_SECTION_1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
mManualQuit = true;
|
mManualQuit = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,9 +87,8 @@ void Instructions::run(Uint8 mode)
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
mTicks = SDL_GetTicks();
|
mTicks = SDL_GetTicks();
|
||||||
|
|
||||||
// Modo automático
|
|
||||||
if (mode == INSTRUCTIONS_MODE_AUTO)
|
if (mode == INSTRUCTIONS_MODE_AUTO)
|
||||||
{
|
{ // Modo automático
|
||||||
mCounter++;
|
mCounter++;
|
||||||
|
|
||||||
if (mCounter == INSTRUCTIONS_COUNTER)
|
if (mCounter == INSTRUCTIONS_COUNTER)
|
||||||
@@ -108,9 +97,8 @@ void Instructions::run(Uint8 mode)
|
|||||||
mSection.subsection = TITLE_SECTION_1;
|
mSection.subsection = TITLE_SECTION_1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Modo manual
|
|
||||||
else
|
else
|
||||||
{
|
{ // Modo manual
|
||||||
++mCounter %= 60000;
|
++mCounter %= 60000;
|
||||||
|
|
||||||
if (mManualQuit)
|
if (mManualQuit)
|
||||||
@@ -153,7 +141,9 @@ void Instructions::run(Uint8 mode)
|
|||||||
mText->writeShadowed(84, 156, mLang->getText(21), shdwTxtColor);
|
mText->writeShadowed(84, 156, mLang->getText(21), shdwTxtColor);
|
||||||
|
|
||||||
if ((mode == INSTRUCTIONS_MODE_MANUAL) && (mCounter % 50 > 14))
|
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);
|
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, GAME_HEIGHT - 12, mLang->getText(22), 1, orangeColor, 1, shdwTxtColor);
|
||||||
|
}
|
||||||
|
|
||||||
// Disquito
|
// Disquito
|
||||||
mSprite->setPos(destRect1);
|
mSprite->setPos(destRect1);
|
||||||
@@ -201,9 +191,13 @@ void Instructions::run(Uint8 mode)
|
|||||||
|
|
||||||
// Establece la ventana del backbuffer
|
// Establece la ventana del backbuffer
|
||||||
if (mode == INSTRUCTIONS_MODE_AUTO)
|
if (mode == INSTRUCTIONS_MODE_AUTO)
|
||||||
|
{
|
||||||
window.y = std::max(8, GAME_HEIGHT - mCounter + 100);
|
window.y = std::max(8, GAME_HEIGHT - mCounter + 100);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
window.y = 0;
|
window.y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Copia el backbuffer al renderizador
|
// Copia el backbuffer al renderizador
|
||||||
SDL_RenderCopy(mRenderer, mBackbuffer, nullptr, &window);
|
SDL_RenderCopy(mRenderer, mBackbuffer, nullptr, &window);
|
||||||
|
|||||||
235
source/item.cpp
@@ -2,120 +2,107 @@
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
|
||||||
// Constructor
|
// 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);
|
std::string filePNG;
|
||||||
|
std::string fileANI;
|
||||||
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);
|
|
||||||
|
|
||||||
switch (type)
|
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:
|
case ITEM_POINTS_1_DISK:
|
||||||
mSprite->setAnimationFrames(0, 0, 16 * 0, 16 * 0, mWidth, mHeight);
|
filePNG = asset->get("item_points1_disk.png");
|
||||||
mSprite->setAnimationFrames(0, 1, 16 * 0, 16 * 1, mWidth, mHeight);
|
fileANI = asset->get("item_points1_disk.ani");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_POINTS_2_GAVINA:
|
case ITEM_POINTS_2_GAVINA:
|
||||||
mSprite->setAnimationFrames(0, 0, 16 * 1, 16 * 0, mWidth, mHeight);
|
filePNG = asset->get("item_points2_gavina.png");
|
||||||
mSprite->setAnimationFrames(0, 1, 16 * 1, 16 * 1, mWidth, mHeight);
|
fileANI = asset->get("item_points2_gavina.ani");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_POINTS_3_PACMAR:
|
case ITEM_POINTS_3_PACMAR:
|
||||||
mSprite->setAnimationFrames(0, 0, 16 * 2, 16 * 0, mWidth, mHeight);
|
filePNG = asset->get("item_points3_pacmar.png");
|
||||||
mSprite->setAnimationFrames(0, 1, 16 * 2, 16 * 1, mWidth, mHeight);
|
fileANI = asset->get("item_points3_pacmar.ani");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_CLOCK:
|
case ITEM_CLOCK:
|
||||||
mSprite->setAnimationFrames(0, 0, 16 * 3, 16 * 0, mWidth, mHeight);
|
filePNG = asset->get("item_clock.png");
|
||||||
mSprite->setAnimationFrames(0, 1, 16 * 3, 16 * 1, mWidth, mHeight);
|
fileANI = asset->get("item_clock.ani");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_COFFEE:
|
case ITEM_COFFEE:
|
||||||
mSprite->setAnimationFrames(0, 0, 16 * 5, 16 * 0, mWidth, mHeight);
|
filePNG = asset->get("item_coffee.png");
|
||||||
mSprite->setAnimationFrames(0, 1, 16 * 5, 16 * 1, mWidth, mHeight);
|
fileANI = asset->get("item_coffee.ani");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_COFFEE_MACHINE:
|
case ITEM_COFFEE_MACHINE:
|
||||||
mWidth = 32;
|
filePNG = asset->get("item_coffee_machine.png");
|
||||||
mHeight = 32;
|
fileANI = asset->get("item_coffee_machine.ani");
|
||||||
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();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
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
|
// Destructor
|
||||||
Item::~Item()
|
Item::~Item()
|
||||||
{
|
{
|
||||||
delete mSprite;
|
delete texture;
|
||||||
mSprite = nullptr;
|
delete sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Centra el objeto en la posición X
|
// Centra el objeto en la posición X
|
||||||
void Item::allignTo(int 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
|
// Posición X,Y del sprite
|
||||||
mSprite->setPosX(int(mPosX));
|
sprite->setPosX(int(posX));
|
||||||
mSprite->setPosY(int(mPosY));
|
sprite->setPosY(int(posY));
|
||||||
|
|
||||||
// Alinea el circulo de colisión con el objeto
|
// Alinea el circulo de colisión con el objeto
|
||||||
shiftColliders();
|
shiftColliders();
|
||||||
@@ -124,15 +111,15 @@ void Item::allignTo(int x)
|
|||||||
// Pinta el objeto en la pantalla
|
// Pinta el objeto en la pantalla
|
||||||
void Item::render()
|
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
|
// Actualiza la posición y estados del objeto
|
||||||
void Item::move()
|
void Item::move()
|
||||||
{
|
{
|
||||||
mFloorCollision = false;
|
floorCollision = false;
|
||||||
|
|
||||||
// Calcula la nueva posición
|
// Calcula la nueva posición
|
||||||
mPosX += mVelX;
|
posX += velX;
|
||||||
mPosY += mVelY;
|
posY += velY;
|
||||||
|
|
||||||
// Aplica las aceleraciones a la velocidad
|
// Aplica las aceleraciones a la velocidad
|
||||||
mVelX += mAccelX;
|
velX += accelX;
|
||||||
mVelY += mAccelY;
|
velY += accelY;
|
||||||
|
|
||||||
// Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido
|
// 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
|
// Corregir posición
|
||||||
mPosX -= mVelX;
|
posX -= velX;
|
||||||
|
|
||||||
// Invertir sentido
|
// Invertir sentido
|
||||||
mVelX = -mVelX;
|
velX = -velX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si se sale por arriba rebota (excepto la maquina de café)
|
// 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
|
// Corrige
|
||||||
mPosY = PLAY_AREA_TOP;
|
posY = PLAY_AREA_TOP;
|
||||||
|
|
||||||
// Invierte el sentido
|
// Invierte el sentido
|
||||||
mVelY = -mVelY;
|
velY = -velY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si el objeto se sale por la parte inferior
|
// Si el objeto se sale por la parte inferior
|
||||||
if (mPosY + mHeight > PLAY_AREA_BOTTOM)
|
if (posY + height > PLAY_AREA_BOTTOM)
|
||||||
{
|
{
|
||||||
// Corrige
|
// Corrige
|
||||||
mPosY -= mVelY;
|
posY -= velY;
|
||||||
|
|
||||||
// Detiene el objeto
|
// Detiene el objeto
|
||||||
mVelY = 0;
|
velY = 0;
|
||||||
mVelX = 0;
|
velX = 0;
|
||||||
mAccelX = 0;
|
accelX = 0;
|
||||||
mAccelY = 0;
|
accelY = 0;
|
||||||
mPosY = PLAY_AREA_BOTTOM - mHeight;
|
posY = PLAY_AREA_BOTTOM - height;
|
||||||
if (mClass == ITEM_COFFEE_MACHINE)
|
if (type == ITEM_COFFEE_MACHINE)
|
||||||
mFloorCollision = true;
|
{
|
||||||
|
floorCollision = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la posición del sprite
|
// Actualiza la posición del sprite
|
||||||
mSprite->setPosX(int(mPosX));
|
sprite->setPosX(int(posX));
|
||||||
mSprite->setPosY(int(mPosY));
|
sprite->setPosY(int(posY));
|
||||||
|
shiftColliders();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pone a cero todos los valores del objeto
|
// 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
|
// Actualiza el objeto a su posicion, animación y controla los contadores
|
||||||
void Item::update()
|
void Item::update()
|
||||||
{
|
{
|
||||||
if (mEnabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
move();
|
move();
|
||||||
shiftColliders();
|
sprite->animate();
|
||||||
mSprite->animate();
|
|
||||||
updateTimeToLive();
|
updateTimeToLive();
|
||||||
checkTimeToLive();
|
checkTimeToLive();
|
||||||
}
|
}
|
||||||
@@ -213,76 +202,70 @@ void Item::update()
|
|||||||
// Actualiza el contador
|
// Actualiza el contador
|
||||||
void Item::updateTimeToLive()
|
void Item::updateTimeToLive()
|
||||||
{
|
{
|
||||||
if (mTimeToLive > 0)
|
if (timeToLive > 0)
|
||||||
{
|
{
|
||||||
mTimeToLive--;
|
timeToLive--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si el objeto sigue vivo
|
// Comprueba si el objeto sigue vivo
|
||||||
void Item::checkTimeToLive()
|
void Item::checkTimeToLive()
|
||||||
{
|
{
|
||||||
if (mTimeToLive == 0)
|
if (timeToLive == 0)
|
||||||
erase();
|
disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
float Item::getPosX()
|
float Item::getPosX()
|
||||||
{
|
{
|
||||||
return mPosX;
|
return posX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
float Item::getPosY()
|
float Item::getPosY()
|
||||||
{
|
{
|
||||||
return mPosY;
|
return posY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int Item::getWidth()
|
int Item::getWidth()
|
||||||
{
|
{
|
||||||
return mWidth;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int Item::getHeight()
|
int Item::getHeight()
|
||||||
{
|
{
|
||||||
return mHeight;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int Item::getClass()
|
int Item::getClass()
|
||||||
{
|
{
|
||||||
return mClass;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
bool Item::isEnabled()
|
bool Item::isEnabled()
|
||||||
{
|
{
|
||||||
return mEnabled;
|
return enabled;
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void Item::setEnabled(bool value)
|
|
||||||
{
|
|
||||||
mEnabled = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el circulo de colisión
|
// Obtiene el circulo de colisión
|
||||||
circle_t &Item::getCollider()
|
circle_t &Item::getCollider()
|
||||||
{
|
{
|
||||||
return mCollider;
|
return collider;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alinea el circulo de colisión con la posición del objeto
|
// Alinea el circulo de colisión con la posición del objeto
|
||||||
void Item::shiftColliders()
|
void Item::shiftColliders()
|
||||||
{
|
{
|
||||||
mCollider.x = int(mPosX + (mWidth / 2));
|
collider.x = int(posX + (width / 2));
|
||||||
mCollider.y = int(mPosY + (mHeight / 2));
|
collider.y = int(posY + (height / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Informa si el objeto ha colisionado con el suelo
|
// Informa si el objeto ha colisionado con el suelo
|
||||||
bool Item::floorCollision()
|
bool Item::isOnFloor()
|
||||||
{
|
{
|
||||||
return mFloorCollision;
|
return floorCollision;
|
||||||
}
|
}
|
||||||
@@ -20,30 +20,35 @@
|
|||||||
class Item
|
class Item
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
float mPosX; // Posición X del objeto
|
// Objetos
|
||||||
float mPosY; // Posición Y del objeto
|
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||||
Uint8 mWidth; // Ancho del objeto
|
AnimatedSprite *sprite; // Sprite con los graficos del objeto
|
||||||
Uint8 mHeight; // Alto del objeto
|
LTexture *texture; // Objeto con los graficos del item
|
||||||
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
|
|
||||||
|
|
||||||
AnimatedSprite *mSprite; // Sprite con los graficos del objeto
|
// Variables
|
||||||
|
float posX; // Posición X del objeto
|
||||||
Uint8 mClass; // Especifica el tipo de objeto que es
|
float posY; // Posición Y del objeto
|
||||||
bool mEnabled; // Especifica si el objeto está habilitado
|
Uint8 width; // Ancho del objeto
|
||||||
circle_t mCollider; // Circulo de colisión 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
|
// Alinea el circulo de colisión con la posición del objeto
|
||||||
void shiftColliders();
|
void shiftColliders();
|
||||||
|
|
||||||
|
// Actualiza la posición y estados del objeto
|
||||||
|
void move();
|
||||||
public:
|
public:
|
||||||
Uint16 mTimeToLive; // Temporizador con el tiempo que el objeto está presente
|
Uint16 timeToLive; // Temporizador con el tiempo que el objeto está presente
|
||||||
|
|
||||||
// Constructor
|
// 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
|
// Destructor
|
||||||
~Item();
|
~Item();
|
||||||
@@ -54,11 +59,9 @@ public:
|
|||||||
// Pinta el objeto en la pantalla
|
// Pinta el objeto en la pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Actualiza la posición y estados del objeto
|
|
||||||
void move();
|
|
||||||
|
|
||||||
// Pone a cero todos los valores del objeto
|
// Pone a cero todos los valores del objeto
|
||||||
void erase();
|
void disable();
|
||||||
|
|
||||||
// Actualiza al objeto a su posicion, animación y controla los contadores
|
// Actualiza al objeto a su posicion, animación y controla los contadores
|
||||||
void update();
|
void update();
|
||||||
@@ -87,14 +90,11 @@ public:
|
|||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
bool isEnabled();
|
bool isEnabled();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setEnabled(bool value);
|
|
||||||
|
|
||||||
// Obtiene el circulo de colisión
|
// Obtiene el circulo de colisión
|
||||||
circle_t &getCollider();
|
circle_t &getCollider();
|
||||||
|
|
||||||
// Informa si el objeto ha colisionado con el suelo
|
// Informa si el objeto ha colisionado con el suelo
|
||||||
bool floorCollision();
|
bool isOnFloor();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||