diff --git a/data/gfx/balloon1.ani b/data/gfx/balloon1.ani index 3fbe8c1..21c1d83 100644 --- a/data/gfx/balloon1.ani +++ b/data/gfx/balloon1.ani @@ -1,37 +1,16 @@ -frameWidth=8 -frameHeight=8 +frameWidth=10 +frameHeight=10 [animation] -name=orange +name=normal speed=10 loop=0 frames=0,1,2,3,4,5,6,7,8,9 [/animation] [animation] -name=blue +name=stopped speed=20 loop=0 -frames=12,13,14,15,16,17,18,19,20,21 -[/animation] - -[animation] -name=green -speed=10 -loop=0 -frames=24,25,26,27,28,29,30,31,32,33 -[/animation] - -[animation] -name=red -speed=20 -loop=0 -frames=36,37,38,39,40,41,42,43,44,45 -[/animation] - -[animation] -name=pop -speed=5 -loop=-1 -frames=48,49,50,51,52,53,54,55,56,57,58,59 +frames=0,1,2,3,4,5,6,7,8,9 [/animation] \ No newline at end of file diff --git a/data/gfx/balloon1.gif b/data/gfx/balloon1.gif new file mode 100644 index 0000000..173179c Binary files /dev/null and b/data/gfx/balloon1.gif differ diff --git a/data/gfx/balloon1.png b/data/gfx/balloon1.png deleted file mode 100644 index 8487e7f..0000000 Binary files a/data/gfx/balloon1.png and /dev/null differ diff --git a/data/gfx/balloon1_explosion.ani b/data/gfx/balloon1_explosion.ani new file mode 100644 index 0000000..30cb568 --- /dev/null +++ b/data/gfx/balloon1_explosion.ani @@ -0,0 +1,9 @@ +frameWidth=10 +frameHeight=10 + +[animation] +name=default +speed=5 +loop=-1 +frames=0,1,2,3,4,5,6,7,8,9 +[/animation] \ No newline at end of file diff --git a/data/gfx/balloon1_explosion.png b/data/gfx/balloon1_explosion.png new file mode 100644 index 0000000..30871f0 Binary files /dev/null and b/data/gfx/balloon1_explosion.png differ diff --git a/data/gfx/balloon2.ani b/data/gfx/balloon2.ani index bbc4d86..7b24f55 100644 --- a/data/gfx/balloon2.ani +++ b/data/gfx/balloon2.ani @@ -1,37 +1,16 @@ -frameWidth=13 -frameHeight=13 +frameWidth=16 +frameHeight=16 [animation] -name=orange +name=normal speed=10 loop=0 frames=0,1,2,3,4,5,6,7,8,9 [/animation] [animation] -name=blue +name=stopped speed=20 loop=0 -frames=12,13,14,15,16,17,18,19,20,21 -[/animation] - -[animation] -name=green -speed=10 -loop=0 -frames=24,25,26,27,28,29,30,31,32,33 -[/animation] - -[animation] -name=red -speed=20 -loop=0 -frames=36,37,38,39,40,41,42,43,44,45 -[/animation] - -[animation] -name=pop -speed=5 -loop=-1 -frames=48,49,50,51,52,53,54,55,56,57,58,59 +frames=0,1,2,3,4,5,6,7,8,9 [/animation] \ No newline at end of file diff --git a/data/gfx/balloon2.gif b/data/gfx/balloon2.gif new file mode 100644 index 0000000..bd56e96 Binary files /dev/null and b/data/gfx/balloon2.gif differ diff --git a/data/gfx/balloon2.png b/data/gfx/balloon2.png deleted file mode 100644 index efca82c..0000000 Binary files a/data/gfx/balloon2.png and /dev/null differ diff --git a/data/gfx/balloon2_explosion.ani b/data/gfx/balloon2_explosion.ani new file mode 100644 index 0000000..fa783f0 --- /dev/null +++ b/data/gfx/balloon2_explosion.ani @@ -0,0 +1,9 @@ +frameWidth=16 +frameHeight=16 + +[animation] +name=default +speed=5 +loop=-1 +frames=0,1,2,3,4,5,6,7,8,9 +[/animation] \ No newline at end of file diff --git a/data/gfx/balloon2_explosion.png b/data/gfx/balloon2_explosion.png new file mode 100644 index 0000000..87083d7 Binary files /dev/null and b/data/gfx/balloon2_explosion.png differ diff --git a/data/gfx/balloon3.ani b/data/gfx/balloon3.ani index e1fd440..ee716a3 100644 --- a/data/gfx/balloon3.ani +++ b/data/gfx/balloon3.ani @@ -1,37 +1,16 @@ -frameWidth=21 -frameHeight=21 +frameWidth=26 +frameHeight=26 [animation] -name=orange +name=normal speed=10 loop=0 frames=0,1,2,3,4,5,6,7,8,9 [/animation] [animation] -name=blue +name=stopped speed=20 loop=0 -frames=12,13,14,15,16,17,18,19,20,21 -[/animation] - -[animation] -name=green -speed=10 -loop=0 -frames=24,25,26,27,28,29,30,31,32,33 -[/animation] - -[animation] -name=red -speed=20 -loop=0 -frames=36,37,38,39,40,41,42,43,44,45 -[/animation] - -[animation] -name=pop -speed=5 -loop=-1 -frames=48,49,50,51,52,53,54,55,56,57,58,59 +frames=0,1,2,3,4,5,6,7,8,9 [/animation] \ No newline at end of file diff --git a/data/gfx/balloon3.gif b/data/gfx/balloon3.gif new file mode 100644 index 0000000..0ba4add Binary files /dev/null and b/data/gfx/balloon3.gif differ diff --git a/data/gfx/balloon3.png b/data/gfx/balloon3.png deleted file mode 100644 index 82991dd..0000000 Binary files a/data/gfx/balloon3.png and /dev/null differ diff --git a/data/gfx/balloon3_explosion.ani b/data/gfx/balloon3_explosion.ani new file mode 100644 index 0000000..957e88d --- /dev/null +++ b/data/gfx/balloon3_explosion.ani @@ -0,0 +1,9 @@ +frameWidth=26 +frameHeight=26 + +[animation] +name=default +speed=5 +loop=-1 +frames=0,1,2,3,4,5,6,7,8,9 +[/animation] \ No newline at end of file diff --git a/data/gfx/balloon3_explosion.png b/data/gfx/balloon3_explosion.png new file mode 100644 index 0000000..552a668 Binary files /dev/null and b/data/gfx/balloon3_explosion.png differ diff --git a/data/gfx/balloon4.ani b/data/gfx/balloon4.ani index db7e703..3ebc4d0 100644 --- a/data/gfx/balloon4.ani +++ b/data/gfx/balloon4.ani @@ -1,44 +1,16 @@ -frameWidth=37 -frameHeight=37 +frameWidth=46 +frameHeight=46 [animation] -name=orange +name=normal speed=10 loop=0 frames=0,1,2,3,4,5,6,7,8,9 [/animation] [animation] -name=blue +name=stopped 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=10 -loop=0 -frames=10 -[/animation] - -[animation] -name=pop -speed=5 -loop=-1 -frames=48,49,50,51,52,53,54,55,56,57,58,59 +frames=0,1,2,3,4,5,6,7,8,9 [/animation] \ No newline at end of file diff --git a/data/gfx/balloon4.gif b/data/gfx/balloon4.gif new file mode 100644 index 0000000..a3de374 Binary files /dev/null and b/data/gfx/balloon4.gif differ diff --git a/data/gfx/balloon4.png b/data/gfx/balloon4.png deleted file mode 100644 index 45ec694..0000000 Binary files a/data/gfx/balloon4.png and /dev/null differ diff --git a/data/gfx/balloon4_explosion.ani b/data/gfx/balloon4_explosion.ani new file mode 100644 index 0000000..db5758f --- /dev/null +++ b/data/gfx/balloon4_explosion.ani @@ -0,0 +1,9 @@ +frameWidth=46 +frameHeight=46 + +[animation] +name=default +speed=5 +loop=-1 +frames=0,1,2,3,4,5,6,7,8,9 +[/animation] \ No newline at end of file diff --git a/data/gfx/balloon4_explosion.png b/data/gfx/balloon4_explosion.png new file mode 100644 index 0000000..7fa64fe Binary files /dev/null and b/data/gfx/balloon4_explosion.png differ diff --git a/data/gfx/balloon_blue_pal.gif b/data/gfx/balloon_blue_pal.gif new file mode 100644 index 0000000..8fefa46 Binary files /dev/null and b/data/gfx/balloon_blue_pal.gif differ diff --git a/data/gfx/balloon_green_pal.gif b/data/gfx/balloon_green_pal.gif new file mode 100644 index 0000000..909653a Binary files /dev/null and b/data/gfx/balloon_green_pal.gif differ diff --git a/data/gfx/balloon_yellow_pal.gif b/data/gfx/balloon_yellow_pal.gif new file mode 100644 index 0000000..9b7840c Binary files /dev/null and b/data/gfx/balloon_yellow_pal.gif differ diff --git a/data/gfx/powerball.png b/data/gfx/powerball.png new file mode 100644 index 0000000..1b9933c Binary files /dev/null and b/data/gfx/powerball.png differ diff --git a/source/background.cpp b/source/background.cpp index 367ec95..b7fc1a5 100644 --- a/source/background.cpp +++ b/source/background.cpp @@ -39,15 +39,15 @@ Background::Background(SDL_Renderer *renderer, Screen *screen, Asset *asset, par const int clouds2y = base - 101; const float clouds1speed = 0.1f; const float clouds2speed = 0.05f; - clouds1A = new MovingSprite(0, clouds1y, rect.w, clouds1Texture->getHeight(), -clouds1speed, 0.0f, 0.0f, 0.0f, clouds1Texture, renderer); - clouds1B = new MovingSprite(rect.w, clouds1y, rect.w, clouds1Texture->getHeight(), -clouds1speed, 0.0f, 0.0f, 0.0f, clouds1Texture, renderer); + clouds1A = new MovingSprite(0, clouds1y, rect.w, clouds1Texture->getHeight(), -clouds1speed, 0.0f, 0.0f, 0.0f, clouds1Texture); + clouds1B = new MovingSprite(rect.w, clouds1y, rect.w, clouds1Texture->getHeight(), -clouds1speed, 0.0f, 0.0f, 0.0f, clouds1Texture); - clouds2A = new MovingSprite(0, clouds2y, rect.w, clouds2Texture->getHeight(), -clouds2speed, 0.0f, 0.0f, 0.0f, clouds2Texture, renderer); - clouds2B = new MovingSprite(rect.w, clouds2y, rect.w, clouds2Texture->getHeight(), -clouds2speed, 0.0f, 0.0f, 0.0f, clouds2Texture, renderer); + clouds2A = new MovingSprite(0, clouds2y, rect.w, clouds2Texture->getHeight(), -clouds2speed, 0.0f, 0.0f, 0.0f, clouds2Texture); + clouds2B = new MovingSprite(rect.w, clouds2y, rect.w, clouds2Texture->getHeight(), -clouds2speed, 0.0f, 0.0f, 0.0f, clouds2Texture); - buildingsSprite = new Sprite(0, 0, buildingsTexture->getWidth(), buildingsTexture->getHeight(), buildingsTexture, renderer); - gradientSprite = new Sprite(0, 0, rect.w, rect.h, gradientsTexture, renderer); - grassSprite = new Sprite(0, 0, grassTexture->getWidth(), grassTexture->getHeight() / 2, grassTexture, renderer); + buildingsSprite = new Sprite(0, 0, buildingsTexture->getWidth(), buildingsTexture->getHeight(), buildingsTexture); + gradientSprite = new Sprite(0, 0, rect.w, rect.h, gradientsTexture); + grassSprite = new Sprite(0, 0, grassTexture->getWidth(), grassTexture->getHeight() / 2, grassTexture); // Inicializa objetos clouds1A->setSpriteClip(0, 0, clouds1Texture->getWidth(), clouds1Texture->getHeight()); diff --git a/source/balloon.cpp b/source/balloon.cpp index 4bab7b2..99d4508 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -4,7 +4,7 @@ // Constructor Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector *animation, SDL_Renderer *renderer) { - sprite = new AnimatedSprite(texture, renderer, "", animation); + sprite = new AnimatedSprite(texture, "", animation); disable(); enabled = true; @@ -210,14 +210,7 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c // Añade rotación al sprite sprite->setRotate(false); sprite->setRotateSpeed(0); - if (velX > 0.0f) - { - sprite->setRotateAmount(2.0); - } - else - { - sprite->setRotateAmount(-2.0); - } + velX > 0.0f ? sprite->setRotateAmount(2.0) : sprite->setRotateAmount(-2.0); break; @@ -289,9 +282,13 @@ void Balloon::allignTo(int x) posX = float(x - (width / 2)); if (posX < PLAY_AREA_LEFT) + { posX = PLAY_AREA_LEFT + 1; + } else if ((posX + width) > PLAY_AREA_RIGHT) + { posX = float(PLAY_AREA_RIGHT - width - 1); + } // Posición X,Y del sprite sprite->setPosX(getPosX()); @@ -304,7 +301,7 @@ void Balloon::allignTo(int x) // Pinta el globo en la pantalla void Balloon::render() { - if ((visible) && (enabled)) + if (visible && enabled) { if (bouncing.enabled) { @@ -325,7 +322,7 @@ void Balloon::render() sprite->render(); if (kind == POWER_BALL) { - Sprite *sp = new Sprite(sprite->getRect(), sprite->getTexture(), sprite->getRenderer()); + Sprite *sp = new Sprite(sprite->getRect(), sprite->getTexture()); sp->setSpriteClip(407, 0, 37, 37); sp->render(); delete sp; @@ -338,7 +335,7 @@ void Balloon::render() if (kind == POWER_BALL and !popping) { - Sprite *sp = new Sprite(sprite->getRect(), sprite->getTexture(), sprite->getRenderer()); + Sprite *sp = new Sprite(sprite->getRect(), sprite->getTexture()); sp->setSpriteClip(407, 0, 37, 37); sp->render(); delete sp; @@ -579,16 +576,16 @@ void Balloon::updateState() { stoppedCounter--; } - // Quitarles el estado "detenido" si no estan explosionando + // Si el contador ha llegado a cero else if (!isPopping()) - { + { // Quitarles el estado "detenido" si no estan explosionando + setStop(false); + // Si es una powerball vuelve a rodar if (kind == POWER_BALL) { sprite->setRotate(true); } - - setStop(false); } } } @@ -864,4 +861,16 @@ void Balloon::updateBounce() bounceStop(); } } +} + +// Indica si el globo se puede explotar +bool Balloon::canBePopped() +{ + return isEnabled() && !isPopping() && !isBeingCreated(); +} + +// Indica si el globo se puede destruir +bool Balloon::canBeDestroyed() +{ + return isEnabled() && !isPopping(); } \ No newline at end of file diff --git a/source/balloon.h b/source/balloon.h index 38cfa87..5a94f6f 100644 --- a/source/balloon.h +++ b/source/balloon.h @@ -56,10 +56,10 @@ #define BALLOON_SPEED_5 1.00f // Tamaño de los globos -#define BALLOON_WIDTH_1 8 -#define BALLOON_WIDTH_2 13 -#define BALLOON_WIDTH_3 21 -#define BALLOON_WIDTH_4 37 +#define BALLOON_WIDTH_1 10 +#define BALLOON_WIDTH_2 16 +#define BALLOON_WIDTH_3 26 +#define BALLOON_WIDTH_4 46 // PowerBall #define POWERBALL_SCREENPOWER_MINIMUM 10 @@ -246,4 +246,10 @@ public: // Obtiene le valor de la variable Uint8 getPower(); + + // Indica si el globo se puede explotar + bool canBePopped(); + + // Indica si el globo se puede destruir + bool canBeDestroyed(); }; \ No newline at end of file diff --git a/source/bullet.cpp b/source/bullet.cpp index deaab39..1a3de1a 100644 --- a/source/bullet.cpp +++ b/source/bullet.cpp @@ -2,9 +2,9 @@ #include "bullet.h" // Constructor -Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, Texture *texture, SDL_Renderer *renderer) +Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, Texture *texture) { - sprite = new Sprite({x, y, 10, 10}, texture, renderer); + sprite = new Sprite({x, y, 10, 10}, texture); // Posición inicial del objeto posX = x; diff --git a/source/bullet.h b/source/bullet.h index 36054b5..d27923f 100644 --- a/source/bullet.h +++ b/source/bullet.h @@ -36,7 +36,7 @@ private: public: // Constructor - Bullet(int x, int y, int kind, bool poweredUp, int owner, Texture *texture, SDL_Renderer *renderer); + Bullet(int x, int y, int kind, bool poweredUp, int owner, Texture *texture); // Destructor ~Bullet(); diff --git a/source/common/animatedsprite.cpp b/source/common/animatedsprite.cpp index 6501bd3..f624286 100644 --- a/source/common/animatedsprite.cpp +++ b/source/common/animatedsprite.cpp @@ -146,11 +146,10 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b } // Constructor -AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::string file, std::vector *buffer) +AnimatedSprite::AnimatedSprite(Texture *texture, std::string file, std::vector *buffer) { // Copia los punteros setTexture(texture); - setRenderer(renderer); // Carga las animaciones if (file != "") @@ -174,11 +173,10 @@ AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::st } // Constructor -AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation) +AnimatedSprite::AnimatedSprite(animatedSprite_t *animation) { // Copia los punteros setTexture(animation->texture); - setRenderer(renderer); // Inicializa variables currentAnimation = 0; diff --git a/source/common/animatedsprite.h b/source/common/animatedsprite.h index f225f87..8e834da 100644 --- a/source/common/animatedsprite.h +++ b/source/common/animatedsprite.h @@ -37,8 +37,8 @@ private: public: // Constructor - AnimatedSprite(Texture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = "", std::vector *buffer = nullptr); - AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation); + AnimatedSprite(Texture *texture = nullptr, std::string file = "", std::vector *buffer = nullptr); + AnimatedSprite(animatedSprite_t *animation); // Destructor ~AnimatedSprite(); diff --git a/source/common/movingsprite.cpp b/source/common/movingsprite.cpp index 8b48765..5c505dd 100644 --- a/source/common/movingsprite.cpp +++ b/source/common/movingsprite.cpp @@ -1,11 +1,10 @@ #include "movingsprite.h" // Constructor -MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, Texture *texture, SDL_Renderer *renderer) +MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, Texture *texture) { // Copia los punteros this->texture = texture; - this->renderer = renderer; // Establece el alto y el ancho del sprite this->w = w; @@ -96,7 +95,7 @@ void MovingSprite::render() { if (enabled) { - texture->render(renderer, (int)x, (int)y, &spriteClip, zoomW, zoomH, angle, center, currentFlip); + texture->render((int)x, (int)y, &spriteClip, zoomW, zoomH, angle, center, currentFlip); } } diff --git a/source/common/movingsprite.h b/source/common/movingsprite.h index 9a460c7..567eb68 100644 --- a/source/common/movingsprite.h +++ b/source/common/movingsprite.h @@ -32,7 +32,7 @@ protected: public: // Constructor - MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, Texture *texture = nullptr, SDL_Renderer *renderer = nullptr); + MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, Texture *texture = nullptr); // Mueve el sprite void move(); diff --git a/source/common/smartsprite.cpp b/source/common/smartsprite.cpp index 5edea95..cb7e4d8 100644 --- a/source/common/smartsprite.cpp +++ b/source/common/smartsprite.cpp @@ -1,11 +1,10 @@ #include "smartsprite.h" // Constructor -SmartSprite::SmartSprite(Texture *texture, SDL_Renderer *renderer) +SmartSprite::SmartSprite(Texture *texture) { // Copia punteros setTexture(texture); - setRenderer(renderer); // Inicializa el objeto init(); diff --git a/source/common/smartsprite.h b/source/common/smartsprite.h index 1f469af..305fa0d 100644 --- a/source/common/smartsprite.h +++ b/source/common/smartsprite.h @@ -25,7 +25,7 @@ private: public: // Constructor - SmartSprite(Texture *texture, SDL_Renderer *renderer); + SmartSprite(Texture *texture); // Inicializa el objeto void init(); diff --git a/source/common/sprite.cpp b/source/common/sprite.cpp index bbb722c..866a0f5 100644 --- a/source/common/sprite.cpp +++ b/source/common/sprite.cpp @@ -1,7 +1,7 @@ #include "sprite.h" // Constructor -Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *renderer) +Sprite::Sprite(int x, int y, int w, int h, Texture *texture) { // Establece la posición X,Y del sprite this->x = x; @@ -11,9 +11,6 @@ Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *rende this->w = w; this->h = h; - // Establece el puntero al renderizador de la ventana - this->renderer = renderer; - // Establece la textura donde están los gráficos para el sprite this->texture = texture; @@ -24,7 +21,7 @@ Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *rende enabled = true; } -Sprite::Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer) +Sprite::Sprite(SDL_Rect rect, Texture *texture) { // Establece la posición X,Y del sprite x = rect.x; @@ -34,9 +31,6 @@ Sprite::Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer) w = rect.w; h = rect.h; - // Establece el puntero al renderizador de la ventana - this->renderer = renderer; - // Establece la textura donde están los gráficos para el sprite this->texture = texture; @@ -51,7 +45,6 @@ Sprite::Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer) Sprite::~Sprite() { texture = nullptr; - renderer = nullptr; } // Muestra el sprite por pantalla @@ -59,7 +52,7 @@ void Sprite::render() { if (enabled) { - texture->render(renderer, x, y, &spriteClip); + texture->render(x, y, &spriteClip); } } @@ -88,10 +81,10 @@ int Sprite::getHeight() } // Establece la posición del objeto -void Sprite::setPos(SDL_Rect rect) +void Sprite::setPos(SDL_Point p) { - this->x = rect.x; - this->y = rect.y; + this->x = p.x; + this->y = p.y; } // Establece el valor de la variable @@ -148,18 +141,6 @@ void Sprite::setTexture(Texture *texture) this->texture = texture; } -// Obten el valor de la variable -SDL_Renderer *Sprite::getRenderer() -{ - return renderer; -} - -// Establece el valor de la variable -void Sprite::setRenderer(SDL_Renderer *renderer) -{ - this->renderer = renderer; -} - // Establece el valor de la variable void Sprite::setEnabled(bool value) { diff --git a/source/common/sprite.h b/source/common/sprite.h index 7be4e12..27b057f 100644 --- a/source/common/sprite.h +++ b/source/common/sprite.h @@ -12,7 +12,6 @@ protected: int w; // Ancho del sprite int h; // Alto del sprite - SDL_Renderer *renderer; // Puntero al renderizador de la ventana Texture *texture; // Textura donde estan todos los dibujos del sprite SDL_Rect spriteClip; // Rectangulo de origen de la textura que se dibujará en pantalla @@ -20,8 +19,8 @@ protected: public: // Constructor - Sprite(int x = 0, int y = 0, int w = 0, int h = 0, Texture *texture = nullptr, SDL_Renderer *renderer = nullptr); - Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer); + Sprite(int x = 0, int y = 0, int w = 0, int h = 0, Texture *texture = nullptr); + Sprite(SDL_Rect rect, Texture *texture); // Destructor ~Sprite(); @@ -42,7 +41,7 @@ public: int getHeight(); // Establece la posición del objeto - void setPos(SDL_Rect rect); + void setPos(SDL_Point p); // Establece el valor de la variable void setPosX(int x); @@ -77,12 +76,6 @@ public: // Establece el valor de la variable void setTexture(Texture *texture); - // Obten el valor de la variable - SDL_Renderer *getRenderer(); - - // Establece el valor de la variable - void setRenderer(SDL_Renderer *renderer); - // Establece el valor de la variable void setEnabled(bool value); diff --git a/source/common/text.cpp b/source/common/text.cpp index e273d96..ae67c2d 100644 --- a/source/common/text.cpp +++ b/source/common/text.cpp @@ -94,7 +94,7 @@ Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer) // Crea los objetos texture = new Texture(renderer, bitmapFile); - sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer); + sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture); // Inicializa variables fixedWidth = false; @@ -118,7 +118,7 @@ Text::Text(std::string textFile, Texture *texture, SDL_Renderer *renderer) // Crea los objetos this->texture = nullptr; - sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer); + sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture); // Inicializa variables fixedWidth = false; @@ -139,7 +139,7 @@ Text::Text(textFile_t *textFile, Texture *texture, SDL_Renderer *renderer) // Crea los objetos this->texture = nullptr; - sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer); + sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture); // Inicializa variables fixedWidth = false; diff --git a/source/common/texture.cpp b/source/common/texture.cpp index 5229523..e40d56f 100644 --- a/source/common/texture.cpp +++ b/source/common/texture.cpp @@ -29,7 +29,7 @@ Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose) // .png if (extension == "png") { - loadFromFile(path, renderer, verbose); + loadFromFile(path, verbose); } // .gif @@ -38,7 +38,7 @@ Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose) surface = loadSurface(path.c_str()); addPalette(path.c_str()); setPaletteColor(0, 0, 0x00000000); - createBlank(renderer, width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING); + createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING); SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); flipSurface(); } @@ -53,7 +53,7 @@ Texture::~Texture() } // Carga una imagen desde un fichero -bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer, bool verbose) +bool Texture::loadFromFile(std::string path, bool verbose) { const std::string filename = path.substr(path.find_last_of("\\/") + 1); int req_format = STBI_rgb_alpha; @@ -131,7 +131,7 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer, bool verbos } // Crea una textura en blanco -bool Texture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_PixelFormatEnum format, SDL_TextureAccess access) +bool Texture::createBlank(int width, int height, SDL_PixelFormatEnum format, SDL_TextureAccess access) { // Crea una textura sin inicializar texture = SDL_CreateTexture(renderer, format, access, width, height); @@ -187,7 +187,7 @@ void Texture::setAlpha(Uint8 alpha) } // Renderiza la textura en un punto específico -void Texture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip) +void Texture::render(int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip) { // Establece el destino de renderizado en la pantalla SDL_Rect renderQuad = {x, y, width, height}; @@ -373,4 +373,10 @@ void Texture::setPalette(int palette) paletteIndex = palette; flipSurface(); } +} + +// Obtiene el renderizador +SDL_Renderer *Texture::getRenderer() +{ + return renderer; } \ No newline at end of file diff --git a/source/common/texture.h b/source/common/texture.h index 7dcae0b..9c15b16 100644 --- a/source/common/texture.h +++ b/source/common/texture.h @@ -52,10 +52,10 @@ public: ~Texture(); // Carga una imagen desde un fichero - bool loadFromFile(std::string path, SDL_Renderer *renderer, bool verbose = false); + bool loadFromFile(std::string path, bool verbose = false); // Crea una textura en blanco - bool createBlank(SDL_Renderer *renderer, int width, int height, SDL_PixelFormatEnum format = SDL_PIXELFORMAT_RGBA8888, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING); + bool createBlank(int width, int height, SDL_PixelFormatEnum format = SDL_PIXELFORMAT_RGBA8888, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING); // Libera la memoria de la textura void unload(); @@ -70,7 +70,7 @@ public: void setAlpha(Uint8 alpha); // Renderiza la textura en un punto específico - void render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip = nullptr, float zoomW = 1, float zoomH = 1, double angle = 0.0, SDL_Point *center = nullptr, SDL_RendererFlip flip = SDL_FLIP_NONE); + void render(int x, int y, SDL_Rect *clip = nullptr, float zoomW = 1, float zoomH = 1, double angle = 0.0, SDL_Point *center = nullptr, SDL_RendererFlip flip = SDL_FLIP_NONE); // Establece la textura como objetivo de renderizado void setAsRenderTarget(SDL_Renderer *renderer); @@ -95,4 +95,7 @@ public: // Cambia la paleta de la textura void setPalette(int palette); + + // Obtiene el renderizador + SDL_Renderer *getRenderer(); }; \ No newline at end of file diff --git a/source/define_buttons.cpp b/source/define_buttons.cpp index 5c4b4a0..ba804db 100644 --- a/source/define_buttons.cpp +++ b/source/define_buttons.cpp @@ -1,10 +1,9 @@ #include "define_buttons.h" // Constructor -DefineButtons::DefineButtons(SDL_Renderer *renderer, Input *input, Text *text, param_t *param, options_t *options, section_t *section) +DefineButtons::DefineButtons(Input *input, Text *text, param_t *param, options_t *options, section_t *section) { // Copia punteros a los objetos - this->renderer = renderer; this->input = input; this->text = text; this->param = param; diff --git a/source/define_buttons.h b/source/define_buttons.h index 9e76ac5..4bd18ae 100644 --- a/source/define_buttons.h +++ b/source/define_buttons.h @@ -17,7 +17,6 @@ class DefineButtons { private: // Objetos - SDL_Renderer *renderer; // El renderizador de la ventana Input *input; // Objeto pata gestionar la entrada Text *text; // Objeto para escribir texto @@ -47,7 +46,7 @@ private: public: // Constructor - DefineButtons(SDL_Renderer *renderer, Input *input, Text *text, param_t *param, options_t *options, section_t *section); + DefineButtons(Input *input, Text *text, param_t *param, options_t *options, section_t *section); // Destructor ~DefineButtons(); diff --git a/source/director.cpp b/source/director.cpp index 0773d05..35a1cfa 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -320,14 +320,27 @@ bool Director::setFileList() asset->add(prefix + "/data/shaders/crtpi.glsl", t_data); // Texturas - asset->add(prefix + "/data/gfx/balloon1.png", t_bitmap); + asset->add(prefix + "/data/gfx/balloon1.gif", t_bitmap); asset->add(prefix + "/data/gfx/balloon1.ani", t_data); - asset->add(prefix + "/data/gfx/balloon2.png", t_bitmap); + asset->add(prefix + "/data/gfx/balloon2.gif", t_bitmap); asset->add(prefix + "/data/gfx/balloon2.ani", t_data); - asset->add(prefix + "/data/gfx/balloon3.png", t_bitmap); + asset->add(prefix + "/data/gfx/balloon3.gif", t_bitmap); asset->add(prefix + "/data/gfx/balloon3.ani", t_data); - asset->add(prefix + "/data/gfx/balloon4.png", t_bitmap); + asset->add(prefix + "/data/gfx/balloon4.gif", t_bitmap); asset->add(prefix + "/data/gfx/balloon4.ani", t_data); + asset->add(prefix + "/data/gfx/balloon1_explosion.png", t_bitmap); + asset->add(prefix + "/data/gfx/balloon1_explosion.ani", t_data); + asset->add(prefix + "/data/gfx/balloon2_explosion.png", t_bitmap); + asset->add(prefix + "/data/gfx/balloon2_explosion.ani", t_data); + asset->add(prefix + "/data/gfx/balloon3_explosion.png", t_bitmap); + asset->add(prefix + "/data/gfx/balloon3_explosion.ani", t_data); + asset->add(prefix + "/data/gfx/balloon4_explosion.png", t_bitmap); + asset->add(prefix + "/data/gfx/balloon4_explosion.ani", t_data); + asset->add(prefix + "/data/gfx/balloon_blue_pal.gif", t_bitmap); + asset->add(prefix + "/data/gfx/balloon_yellow_pal.gif", t_bitmap); + asset->add(prefix + "/data/gfx/balloon_green_pal.gif", t_bitmap); + asset->add(prefix + "/data/gfx/powerball.png", t_bitmap); + asset->add(prefix + "/data/gfx/bullet.png", t_bitmap); asset->add(prefix + "/data/gfx/game_buildings.png", t_bitmap); diff --git a/source/explosions.cpp b/source/explosions.cpp new file mode 100644 index 0000000..244605f --- /dev/null +++ b/source/explosions.cpp @@ -0,0 +1,39 @@ +#include "explosions.h" + +// Constructor +Explosions::Explosions() +{ + textures.clear(); + explosions.clear(); +} + +// Destructor +Explosions::~Explosions() +{ + for (auto explosion : explosions) + { + } +} + +// Actualiza la lógica de la clase +void Explosions::update() +{ +} + +// Dibuja el objeto en pantalla +void Explosions::render() +{ +} + +// Añade texturas al objetp +void Explosions::addTexture(Texture *texture) +{ + textures.push_back(texture); +} + +// Añade una explosión +void Explosions::add(int x, int y, int size) +{ + AnimatedSprite *sprite = new AnimatedSprite(textures[0]); + sprite->setPos({x,y}); +} \ No newline at end of file diff --git a/source/explosions.h b/source/explosions.h new file mode 100644 index 0000000..2d80c20 --- /dev/null +++ b/source/explosions.h @@ -0,0 +1,48 @@ +#pragma once + +#include +#include "common/texture.h" +#include "common/animatedsprite.h" +#include + +struct explosion_t +{ + AnimatedSprite *sprite; // Sprite para dibujar la explosión + bool ended; // Indica si la explosión ha terminado +}; + +struct explision_texture_t +{ + Texture *texture; // Textura para la explosión + int size; // Tamaño de la explosión +}; + +// Clase explosions +class Explosions +{ +private: + // Objetos y punteros + + // Variables + std::vector textures; // Vector con las texturas a utilizar + std::vector explosions; // Lista con todas las explosiones + +public: + // Constructor + Explosions(); + + // Destructor + ~Explosions(); + + // Actualiza la lógica de la clase + void update(); + + // Dibuja el objeto en pantalla + void render(); + + // Añade texturas al objetp + void addTexture(Texture *texture); + + // Añade una explosión + void add(int x, int y, int size); +}; \ No newline at end of file diff --git a/source/game.cpp b/source/game.cpp index e6889a0..49206f2 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -27,15 +27,7 @@ Game::Game(int playerID, int currentStage, SDL_Renderer *renderer, Screen *scree eventHandler = new SDL_Event(); scoreboard = new Scoreboard(renderer, screen, asset, lang, options); background = new Background(renderer, screen, asset, param); - - // Inicializa vectores - playerAnimations.clear(); - balloonAnimations.clear(); - itemAnimations.clear(); - player1Textures.clear(); - player2Textures.clear(); - itemTextures.clear(); - balloonTextures.clear(); + explosions = new Explosions(); // Carga los recursos loadMedia(); @@ -50,15 +42,12 @@ Game::Game(int playerID, int currentStage, SDL_Renderer *renderer, Screen *scree loadDemoFile(asset->get("demo2.bin"), &this->demo.dataFile[index2]); } - // Establece la máxima puntuación desde fichero o desde las puntuaciones online + // Carga las puntuaciones desde el fichero y establece la máxima puntuación setHiScore(); - n1000Sprite = new SmartSprite(gameTextTexture, renderer); - n2500Sprite = new SmartSprite(gameTextTexture, renderer); - n5000Sprite = new SmartSprite(gameTextTexture, renderer); - - gameOverSprite = new Sprite(16, 80, 128, 96, gameOverTexture, renderer); - gameOverEndSprite = new Sprite(PLAY_AREA_CENTER_X - gameOverEndTexture->getWidth() / 2, 80, 128, 96, gameOverEndTexture, renderer); + n1000Sprite = new SmartSprite(gameTextTexture); + n2500Sprite = new SmartSprite(gameTextTexture); + n5000Sprite = new SmartSprite(gameTextTexture); canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, playArea.w, playArea.h); SDL_SetTextureBlendMode(canvas, SDL_BLENDMODE_BLEND); @@ -74,130 +63,24 @@ Game::~Game() saveDemoFile(); #endif - if (!demo.enabled) - { - hiScoreEntry_t entry = {"Sergio", players[0]->getScore()}; - ManageHiScoreTable *m = new ManageHiScoreTable(&options->game.hiScoreTable); - m->add(entry); - delete m; - } - // Elimina todos los objetos contenidos en vectores deleteAllVectorObjects(); - bulletTexture->unload(); - delete bulletTexture; - - gameTextTexture->unload(); - delete gameTextTexture; - - gameOverTexture->unload(); - delete gameOverTexture; - - gameOverEndTexture->unload(); - delete gameOverEndTexture; - - // Animaciones - for (auto animation : playerAnimations) - { - if (animation) - { - delete animation; - } - } - playerAnimations.clear(); - - for (auto animation : balloonAnimations) - { - if (animation) - { - delete animation; - } - } - balloonAnimations.clear(); - - for (auto animation : itemAnimations) - { - if (animation) - { - delete animation; - } - } - itemAnimations.clear(); - - // Texturas - for (auto texture : player1Textures) - { - if (texture) - { - texture->unload(); - delete texture; - } - } - player1Textures.clear(); - - for (auto texture : player2Textures) - { - if (texture) - { - texture->unload(); - delete texture; - } - } - player2Textures.clear(); - - for (auto texture : itemTextures) - { - if (texture) - { - texture->unload(); - delete texture; - } - } - itemTextures.clear(); - - for (auto texture : balloonTextures) - { - if (texture) - { - texture->unload(); - delete texture; - } - } - balloonTextures.clear(); + // Libera los recursos + unloadMedia(); delete scoreboard; delete background; + delete explosions; - delete text; - delete textBig; - delete textNokia2; - delete textNokiaBig2; delete fade; delete eventHandler; + delete n1000Sprite; delete n2500Sprite; delete n5000Sprite; - delete gameOverSprite; - delete gameOverEndSprite; SDL_DestroyTexture(canvas); - - JA_DeleteSound(balloonSound); - JA_DeleteSound(bulletSound); - JA_DeleteSound(playerCollisionSound); - JA_DeleteSound(hiScoreSound); - JA_DeleteSound(itemDropSound); - JA_DeleteSound(itemPickUpSound); - JA_DeleteSound(coffeeOutSound); - JA_DeleteSound(stageChangeSound); - JA_DeleteSound(bubble1Sound); - JA_DeleteSound(bubble2Sound); - JA_DeleteSound(bubble3Sound); - JA_DeleteSound(bubble4Sound); - JA_DeleteSound(clockSound); - JA_DeleteSound(powerBallSound); - JA_DeleteSound(coffeeMachineSound); } // Inicializa las variables necesarias para la sección 'Game' @@ -217,10 +100,10 @@ void Game::init(int playerID) players.clear(); // Crea los dos jugadores - Player *player1 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 30, renderer, playerTextures[0], playerAnimations); + Player *player1 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 30, playerTextures[0], playerAnimations); players.push_back(player1); - Player *player2 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 30, renderer, playerTextures[1], playerAnimations); + Player *player2 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 30, playerTextures[1], playerAnimations); players.push_back(player2); // Habilita el jugador seleccionado. playerID es player 1 o player 2 @@ -432,6 +315,15 @@ void Game::loadMedia() << "** LOADING RESOURCES FOR GAME SECTION" << std::endl; } + playerAnimations.clear(); + balloonAnimations.clear(); + itemAnimations.clear(); + player1Textures.clear(); + player2Textures.clear(); + itemTextures.clear(); + balloonTextures.clear(); + explosionsTextures.clear(); + // Texturas bulletTexture = new Texture(renderer, asset->get("bullet.png")); gameTextTexture = new Texture(renderer, asset->get("game_text.png")); @@ -439,18 +331,43 @@ void Game::loadMedia() gameOverEndTexture = new Texture(renderer, asset->get("menu_game_over_end.png")); // Texturas - Globos - Texture *balloon1Texture = new Texture(renderer, asset->get("balloon1.png")); + Texture *balloon1Texture = new Texture(renderer, asset->get("balloon1.gif")); + balloon1Texture->addPalette(asset->get("balloon_blue_pal.gif")); + balloon1Texture->addPalette(asset->get("balloon_yellow_pal.gif")); + balloon1Texture->addPalette(asset->get("balloon_green_pal.gif")); balloonTextures.push_back(balloon1Texture); - Texture *balloon2Texture = new Texture(renderer, asset->get("balloon2.png")); + Texture *balloon2Texture = new Texture(renderer, asset->get("balloon2.gif")); + balloon2Texture->addPalette(asset->get("balloon_blue_pal.gif")); + balloon2Texture->addPalette(asset->get("balloon_yellow_pal.gif")); + balloon2Texture->addPalette(asset->get("balloon_green_pal.gif")); balloonTextures.push_back(balloon2Texture); - Texture *balloon3Texture = new Texture(renderer, asset->get("balloon3.png")); + Texture *balloon3Texture = new Texture(renderer, asset->get("balloon3.gif")); + balloon3Texture->addPalette(asset->get("balloon_blue_pal.gif")); + balloon3Texture->addPalette(asset->get("balloon_yellow_pal.gif")); + balloon3Texture->addPalette(asset->get("balloon_green_pal.gif")); balloonTextures.push_back(balloon3Texture); - Texture *balloon4Texture = new Texture(renderer, asset->get("balloon4.png")); + Texture *balloon4Texture = new Texture(renderer, asset->get("balloon4.gif")); + balloon4Texture->addPalette(asset->get("balloon_blue_pal.gif")); + balloon4Texture->addPalette(asset->get("balloon_yellow_pal.gif")); + balloon4Texture->addPalette(asset->get("balloon_green_pal.gif")); balloonTextures.push_back(balloon4Texture); + // Texturas - Explosiones + Texture *explosion1Texture = new Texture(renderer, asset->get("balloon1_explosion.png")); + explosionsTextures.push_back(explosion1Texture); + + Texture *explosion2Texture = new Texture(renderer, asset->get("balloon1_explosion.png")); + explosionsTextures.push_back(explosion2Texture); + + Texture *explosion3Texture = new Texture(renderer, asset->get("balloon1_explosion.png")); + explosionsTextures.push_back(explosion3Texture); + + Texture *explosion4Texture = new Texture(renderer, asset->get("balloon1_explosion.png")); + explosionsTextures.push_back(explosion4Texture); + // Texturas - Items Texture *item1 = new Texture(renderer, asset->get("item_points1_disk.png")); itemTextures.push_back(item1); @@ -520,6 +437,23 @@ void Game::loadMedia() loadAnimations(asset->get("balloon4.ani"), balloon4Animation); balloonAnimations.push_back(balloon4Animation); + // Animaciones -- Explosiones + std::vector *explosions1Animation = new std::vector; + loadAnimations(asset->get("balloon1_explosion.ani"), explosions1Animation); + explosionsAnimations.push_back(explosions1Animation); + + std::vector *explosions2Animation = new std::vector; + loadAnimations(asset->get("balloon2_explosion.ani"), explosions2Animation); + explosionsAnimations.push_back(explosions2Animation); + + std::vector *explosions3Animation = new std::vector; + loadAnimations(asset->get("balloon3_explosion.ani"), explosions3Animation); + explosionsAnimations.push_back(explosions3Animation); + + std::vector *explosions4Animation = new std::vector; + loadAnimations(asset->get("balloon4_explosion.ani"), explosions4Animation); + explosionsAnimations.push_back(explosions4Animation); + // Animaciones -- Items std::vector *item1Animation = new std::vector; loadAnimations(asset->get("item_points1_disk.ani"), item1Animation); @@ -575,6 +509,121 @@ void Game::loadMedia() } } +// Libera los recursos previamente cargados +void Game::unloadMedia() +{ + // Texturas + delete bulletTexture; + delete gameTextTexture; + delete gameOverTexture; + delete gameOverEndTexture; + + for (auto texture : player1Textures) + { + if (texture) + { + delete texture; + } + } + player1Textures.clear(); + + for (auto texture : player2Textures) + { + if (texture) + { + delete texture; + } + } + player2Textures.clear(); + + for (auto texture : itemTextures) + { + if (texture) + { + delete texture; + } + } + itemTextures.clear(); + + for (auto texture : balloonTextures) + { + if (texture) + { + delete texture; + } + } + balloonTextures.clear(); + + for (auto texture : explosionsTextures) + { + if (texture) + { + delete texture; + } + } + explosionsTextures.clear(); + + // Animaciones + for (auto animation : playerAnimations) + { + if (animation) + { + delete animation; + } + } + playerAnimations.clear(); + + for (auto animation : balloonAnimations) + { + if (animation) + { + delete animation; + } + } + balloonAnimations.clear(); + + for (auto animation : explosionsAnimations) + { + if (animation) + { + delete animation; + } + } + explosionsAnimations.clear(); + + for (auto animation : itemAnimations) + { + if (animation) + { + delete animation; + } + } + itemAnimations.clear(); + + // Text + delete text; + delete textBig; + delete textNokia2; + delete textNokiaBig2; + + // Sonidos + JA_DeleteSound(balloonSound); + JA_DeleteSound(bulletSound); + JA_DeleteSound(playerCollisionSound); + JA_DeleteSound(hiScoreSound); + JA_DeleteSound(itemDropSound); + JA_DeleteSound(itemPickUpSound); + JA_DeleteSound(coffeeOutSound); + JA_DeleteSound(stageChangeSound); + JA_DeleteSound(bubble1Sound); + JA_DeleteSound(bubble2Sound); + JA_DeleteSound(bubble3Sound); + JA_DeleteSound(bubble4Sound); + JA_DeleteSound(clockSound); + JA_DeleteSound(powerBallSound); + JA_DeleteSound(coffeeMachineSound); +} + // Carga el fichero de puntos bool Game::loadScoreFile() { @@ -733,6 +782,10 @@ bool Game::loadDemoFile(std::string f, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA]) // Guarda el fichero de puntos bool Game::saveScoreFile() { + // Almacena la máxima puntuación en el fichero junto con un checksum + scoreDataFile[0] = hiScore; + scoreDataFile[1] = hiScore % 43; + bool success = true; const std::string p = asset->get("score.bin"); const std::string filename = p.substr(p.find_last_of("\\/") + 1); @@ -1564,12 +1617,6 @@ void Game::increaseStageCurrentPower(int power) stage[currentStage].currentPower += power; } -// Establece el valor de la variable -void Game::setHiScore(Uint32 score) -{ - hiScore = score; -} - // Actualiza el valor de hiScore en caso necesario void Game::updateHiScore() { @@ -1580,10 +1627,6 @@ void Game::updateHiScore() // Actualiza la máxima puntuación hiScore = player->getScore(); - // Almacena la máxima puntuación en el fichero junto con un checksum - scoreDataFile[0] = hiScore; - scoreDataFile[1] = hiScore % 43; - // Si se supera la máxima puntuación emite sonido if (hiScoreAchieved == false) { @@ -1932,38 +1975,32 @@ void Game::popBalloon(Balloon *balloon) evaluateAndSetMenace(); } -// Explosiona un globo. Lo destruye +// Explosiona un globo. Lo destruye = no crea otros globos void Game::destroyBalloon(Balloon *balloon) { int score = 0; - int power = 0; // Calcula la puntuación y el poder que generaria el globo en caso de romperlo a él y a sus hijos switch (balloon->getSize()) { case BALLOON_SIZE_4: score = BALLOON_SCORE_4 + (2 * BALLOON_SCORE_3) + (4 * BALLOON_SCORE_2) + (8 * BALLOON_SCORE_1); - power = 15; break; case BALLOON_SIZE_3: score = BALLOON_SCORE_3 + (2 * BALLOON_SCORE_2) + (4 * BALLOON_SCORE_1); - power = 7; break; case BALLOON_SIZE_2: score = BALLOON_SCORE_2 + (2 * BALLOON_SCORE_1); - power = 3; break; case BALLOON_SIZE_1: score = BALLOON_SCORE_1; - power = 1; break; default: score = 0; - power = 0; break; } @@ -1975,6 +2012,7 @@ void Game::destroyBalloon(Balloon *balloon) updateHiScore(); // Aumenta el poder de la fase + const int power = balloon->getPower(); increaseStageCurrentPower(power); balloonsPopped += power; @@ -1990,7 +2028,7 @@ void Game::popAllBalloons() { for (auto balloon : balloons) { - if ((balloon->isEnabled()) && (!balloon->isPopping()) && (!balloon->isBeingCreated())) + if (balloon->canBePopped()) { popBalloon(balloon); } @@ -2004,7 +2042,7 @@ void Game::destroyAllBalloons() { for (auto balloon : balloons) { - if ((balloon->isEnabled()) && (!balloon->isPopping())) + if (balloon->canBeDestroyed()) { destroyBalloon(balloon); } @@ -2061,7 +2099,7 @@ int Game::countBalloons() return num; } -// Vacia el vector de globos +// Vacia del vector de globos los globos que ya no sirven void Game::freeBalloons() { if (balloons.empty() == false) @@ -2243,7 +2281,7 @@ void Game::renderBullets() // Crea un objeto bala void Game::createBullet(int x, int y, int kind, bool poweredUp, int owner) { - Bullet *b = new Bullet(x, y, kind, poweredUp, owner, bulletTexture, renderer); + Bullet *b = new Bullet(x, y, kind, poweredUp, owner, bulletTexture); bullets.push_back(b); } @@ -2368,7 +2406,7 @@ int Game::dropItem() // Crea un objeto item void Game::createItem(int kind, float x, float y) { - Item *item = new Item(kind, x, y, itemTextures[kind - 1], itemAnimations[kind - 1], renderer); + Item *item = new Item(kind, x, y, itemTextures[kind - 1], itemAnimations[kind - 1]); items.push_back(item); } @@ -2391,7 +2429,7 @@ void Game::freeItems() // 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, renderer); + SmartSprite *ss = new SmartSprite(nullptr); smartSprites.push_back(ss); // Crea una copia del objeto @@ -2423,7 +2461,7 @@ void Game::freeSmartSprites() // Crea un SmartSprite para arrojar el item café al recibir un impacto void Game::throwCoffee(int x, int y) { - SmartSprite *ss = new SmartSprite(itemTextures[4], renderer); + SmartSprite *ss = new SmartSprite(itemTextures[4]); smartSprites.push_back(ss); ss->setPosX(x - 8); @@ -2487,6 +2525,10 @@ void Game::killPlayer(Player *player) JA_PlaySound(coffeeOutSound); player->setAlive(false); allPlayersAreDead() ? JA_StopMusic() : JA_ResumeMusic(); + if (!demo.enabled) + { + addScoreToScoreBoard("Sergio", player->getScore()); + } } } @@ -2638,6 +2680,8 @@ void Game::update() // Mueve los globos updateBalloons(); + explosions->update(); + // Mueve las balas moveBullets(); @@ -2731,6 +2775,7 @@ void Game::fillCanvas() background->render(); renderItems(); renderSmartSprites(); + explosions->render(); renderBalloons(); renderBullets(); renderMessages(); @@ -2783,7 +2828,7 @@ void Game::updateMenace() if (menaceCurrent < menaceThreshold) { // Crea una formación de enemigos - deployEnemyFormation(); + // deployEnemyFormation(); // Recalcula el nivel de amenaza con el nuevo globo evaluateAndSetMenace(); @@ -3397,7 +3442,7 @@ void Game::reloadTextures() background->reloadTextures(); } -// Establece la máxima puntuación desde fichero o desde las puntuaciones online +// Carga las puntuaciones desde el fichero y establece la máxima puntuación void Game::setHiScore() { // Carga el fichero de puntos @@ -3432,4 +3477,13 @@ void Game::pause(bool value) { paused = value; screen->attenuate(paused); +} + +// Añade una puntuación a la tabla de records +void Game::addScoreToScoreBoard(std::string name, int score) +{ + hiScoreEntry_t entry = {name, score}; + ManageHiScoreTable *m = new ManageHiScoreTable(&options->game.hiScoreTable); + m->add(entry); + delete m; } \ No newline at end of file diff --git a/source/game.h b/source/game.h index 043d975..dbb3191 100644 --- a/source/game.h +++ b/source/game.h @@ -20,6 +20,7 @@ #include "background.h" #include "lang.h" #include "manage_hiscore_table.h" +#include "explosions.h" #include // Cantidad de elementos a escribir en los ficheros de datos @@ -114,6 +115,7 @@ private: section_t *section; // Seccion actual dentro del juego Scoreboard *scoreboard; // Objeto para dibujar el marcador Background *background; // Objeto para dibujar el fondo del juego + Explosions *explosions; // Objeto para dibujar explosiones SDL_Texture *canvas; // Textura para dibujar la zona de juego std::vector players; // Vector con los jugadores @@ -125,6 +127,7 @@ private: Texture *bulletTexture; // Textura para las balas std::vector itemTextures; // Vector con las texturas de los items std::vector balloonTextures; // Vector con las texturas de los globos + std::vector explosionsTextures; // Vector con las texturas de las explosiones std::vector player1Textures; // Vector con las texturas del jugador std::vector player2Textures; // Vector con las texturas del jugador std::vector> playerTextures; // Vector con todas las texturas de los jugadores; @@ -133,9 +136,10 @@ private: Texture *gameOverTexture; // Textura para la pantalla de game over Texture *gameOverEndTexture; // Textura para la pantalla de game over de acabar el juego - std::vector *> itemAnimations; // Vector con las animaciones de los items - std::vector *> playerAnimations; // Vector con las animaciones del jugador - std::vector *> balloonAnimations; // Vector con las animaciones de los globos + std::vector *> itemAnimations; // Vector con las animaciones de los items + std::vector *> playerAnimations; // Vector con las animaciones del jugador + std::vector *> balloonAnimations; // Vector con las animaciones de los globos + std::vector *> explosionsAnimations; // Vector con las animaciones de las explosiones Text *text; // Fuente para los textos del juego Text *textBig; // Fuente de texto grande @@ -149,9 +153,6 @@ private: SmartSprite *n2500Sprite; // Sprite con el texto 2.500 SmartSprite *n5000Sprite; // Sprite con el texto 5.000 - Sprite *gameOverSprite; // Sprite para dibujar los graficos del game over - Sprite *gameOverEndSprite; // Sprite para dibujar los graficos del game over de acabar el juego - JA_Sound_t *balloonSound; // Sonido para la explosión del globo JA_Sound_t *bulletSound; // Sonido para los disparos JA_Sound_t *playerCollisionSound; // Sonido para la colisión del jugador con un enemigo @@ -226,6 +227,9 @@ private: // Carga los recursos necesarios para la sección 'Game' void loadMedia(); + // Libera los recursos previamente cargados + void unloadMedia(); + // Carga el fichero de puntos bool loadScoreFile(); @@ -253,9 +257,6 @@ private: // Aumenta el poder de la fase void increaseStageCurrentPower(int power); - // Establece el valor de la variable - void setHiScore(Uint32 score); - // Actualiza el valor de HiScore en caso necesario void updateHiScore(); @@ -448,7 +449,7 @@ private: // Recarga las texturas void reloadTextures(); - // Establece la máxima puntuación desde fichero o desde las puntuaciones online + // Carga las puntuaciones desde el fichero y establece la máxima puntuación void setHiScore(); // Actualiza el marcador @@ -466,6 +467,9 @@ private: // Comprueba si la música ha de estar sonando void checkMusicStatus(); + // Añade una puntuación a la tabla de records + void addScoreToScoreBoard(std::string name, int score); + public: // Constructor Game(int playerID, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, param_t *param, options_t *options, section_t *section, JA_Music_t *music); diff --git a/source/game_logo.cpp b/source/game_logo.cpp index 3244b96..47f9df0 100644 --- a/source/game_logo.cpp +++ b/source/game_logo.cpp @@ -17,11 +17,11 @@ GameLogo::GameLogo(SDL_Renderer *renderer, Screen *screen, Asset *asset, param_t crisisTexture = new Texture(renderer, asset->get("title_crisis.png")); arcadeEditionTexture = new Texture(renderer, asset->get("title_arcade_edition.png")); - coffeeBitmap = new SmartSprite(coffeeTexture, renderer); - crisisBitmap = new SmartSprite(crisisTexture, renderer); - arcadeEditionBitmap = new Sprite((param->gameWidth - arcadeEditionTexture->getWidth()) / 2, param->arcadeEdition, arcadeEditionTexture->getWidth(), arcadeEditionTexture->getHeight(), arcadeEditionTexture, renderer); - dustBitmapL = new AnimatedSprite(dustTexture, renderer, asset->get("title_dust.ani")); - dustBitmapR = new AnimatedSprite(dustTexture, renderer, asset->get("title_dust.ani")); + coffeeBitmap = new SmartSprite(coffeeTexture); + crisisBitmap = new SmartSprite(crisisTexture); + arcadeEditionBitmap = new Sprite((param->gameWidth - arcadeEditionTexture->getWidth()) / 2, param->arcadeEdition, arcadeEditionTexture->getWidth(), arcadeEditionTexture->getHeight(), arcadeEditionTexture); + dustBitmapL = new AnimatedSprite(dustTexture, asset->get("title_dust.ani")); + dustBitmapR = new AnimatedSprite(dustTexture, asset->get("title_dust.ani")); // Sonidos crashSound = JA_LoadSound(asset->get("title.wav").c_str()); diff --git a/source/instructions.cpp b/source/instructions.cpp index 4ec962d..9f24e31 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -98,8 +98,8 @@ void Instructions::iniSprites() // Inicializa los sprites for (int i = 0; i < (int)itemTextures.size(); ++i) { - Sprite *sprite = new Sprite(0, 0, param->itemSize, param->itemSize, itemTextures[i], renderer); - sprite->setPos({spritePos.x, spritePos.y + ((param->itemSize + itemSpace) * i), param->itemSize, param->itemSize}); + Sprite *sprite = new Sprite(0, 0, param->itemSize, param->itemSize, itemTextures[i]); + sprite->setPos({spritePos.x, spritePos.y + ((param->itemSize + itemSpace) * i)}); sprites.push_back(sprite); } } diff --git a/source/intro.cpp b/source/intro.cpp index a996068..cc3d959 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -29,7 +29,7 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, const int totalBitmaps = 6; for (int i = 0; i < totalBitmaps; ++i) { - SmartSprite *ss = new SmartSprite(texture, renderer); + SmartSprite *ss = new SmartSprite(texture); ss->setWidth(128); ss->setHeight(96); ss->setEnabledCounter(20); diff --git a/source/item.cpp b/source/item.cpp index 834837d..8e3329e 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -2,9 +2,9 @@ #include "item.h" // Constructor -Item::Item(int kind, float x, float y, Texture *texture, std::vector *animation, SDL_Renderer *renderer) +Item::Item(int kind, float x, float y, Texture *texture, std::vector *animation) { - sprite = new AnimatedSprite(texture, renderer, "", animation); + sprite = new AnimatedSprite(texture, "", animation); this->kind = kind; enabled = true; diff --git a/source/item.h b/source/item.h index e8704e2..e77b296 100644 --- a/source/item.h +++ b/source/item.h @@ -43,7 +43,7 @@ public: Uint16 timeToLive; // Temporizador con el tiempo que el objeto está presente // Constructor - Item(int kind, float x, float y, Texture *texture, std::vector *animation, SDL_Renderer *renderer); + Item(int kind, float x, float y, Texture *texture, std::vector *animation); // Destructor ~Item(); diff --git a/source/logo.cpp b/source/logo.cpp index 3ceb412..5ea6633 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -16,7 +16,7 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, p eventHandler = new SDL_Event(); jailTexture = new Texture(renderer, asset->get("logo_jailgames.png")); sinceTexture = new Texture(renderer, asset->get("logo_since_1998.png")); - sinceSprite = new Sprite((param->gameWidth - sinceTexture->getWidth()) / 2, 83 + jailTexture->getHeight() + 5, sinceTexture->getWidth(), sinceTexture->getHeight(), sinceTexture, renderer); + sinceSprite = new Sprite((param->gameWidth - sinceTexture->getWidth()) / 2, 83 + jailTexture->getHeight() + 5, sinceTexture->getWidth(), sinceTexture->getHeight(), sinceTexture); sinceSprite->setSpriteClip(0, 0, sinceTexture->getWidth(), sinceTexture->getHeight()); sinceTexture->setColor(0, 0, 0); @@ -36,7 +36,7 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, p // Crea los sprites de cada linea for (int i = 0; i < jailTexture->getHeight(); ++i) { - Sprite *temp = new Sprite(0, i, jailTexture->getWidth(), 1, jailTexture, renderer); + Sprite *temp = new Sprite(0, i, jailTexture->getWidth(), 1, jailTexture); temp->setSpriteClip(0, i, jailTexture->getWidth(), 1); const int posX = (i % 2 == 0) ? param->gameWidth + (i * 3) : -jailTexture->getWidth() - (i * 3); temp->setPosX(posX); diff --git a/source/player.cpp b/source/player.cpp index 0fac4dc..043b2d3 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -2,14 +2,11 @@ #include "player.h" // Constructor -Player::Player(float x, int y, SDL_Renderer *renderer, std::vector texture, std::vector *> animations) +Player::Player(float x, int y, std::vector texture, std::vector *> animations) { - // Copia los punteros - this->renderer = renderer; - // Reserva memoria para los objetos - playerSprite = new AnimatedSprite(texture[0], renderer, "", animations[0]); - powerSprite = new AnimatedSprite(texture[1], renderer, "", animations[1]); + playerSprite = new AnimatedSprite(texture[0], "", animations[0]); + powerSprite = new AnimatedSprite(texture[1], "", animations[1]); powerSprite->getTexture()->setAlpha(224); // Establece la posición inicial del jugador diff --git a/source/player.h b/source/player.h index 497b04f..93c2230 100644 --- a/source/player.h +++ b/source/player.h @@ -26,7 +26,6 @@ class Player { private: // Objetos y punteros - SDL_Renderer *renderer; // El renderizador de la ventana AnimatedSprite *playerSprite; // Sprite para dibujar el jugador AnimatedSprite *powerSprite; // Sprite para dibujar el aura del jugador con el poder a tope @@ -72,7 +71,7 @@ private: public: // Constructor - Player(float x, int y, SDL_Renderer *renderer, std::vector texture, std::vector *> animations); + Player(float x, int y, std::vector texture, std::vector *> animations); // Destructor ~Player(); diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index 29a6cfa..21ea5df 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -31,7 +31,7 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lan // Crea objetos gamePowerMeterTexture = new Texture(renderer, asset->get("game_power_meter.png")); - powerMeterSprite = new Sprite(offsetPowerMeter.x - 20, offsetPowerMeter.y, 40, 7, gamePowerMeterTexture, renderer); + powerMeterSprite = new Sprite(offsetPowerMeter.x - 20, offsetPowerMeter.y, 40, 7, gamePowerMeterTexture); textScoreBoard = new Text(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer); // Crea la textura para dibujar el marcador diff --git a/source/tiledbg.cpp b/source/tiledbg.cpp index cf32853..3265038 100644 --- a/source/tiledbg.cpp +++ b/source/tiledbg.cpp @@ -56,7 +56,7 @@ void Tiledbg::fillTexture() { // Crea los objetos para pintar en la textura de fondo Texture *bgTileTexture = new Texture(renderer, asset->get("title_bg_tile.png")); - Sprite *tile = new Sprite({0, 0, tileWidth, tileHeight}, bgTileTexture, renderer); + Sprite *tile = new Sprite({0, 0, tileWidth, tileHeight}, bgTileTexture); // Prepara para dibujar sobre la textura SDL_Texture *temp = SDL_GetRenderTarget(renderer); diff --git a/source/title.cpp b/source/title.cpp index ab58b06..917e821 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -24,14 +24,14 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, text2 = new Text(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer); miniLogoTexture = new Texture(renderer, asset->get("logo_jailgames_mini.png")); - miniLogoSprite = new Sprite(GAMECANVAS_CENTER_X - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture, renderer); + miniLogoSprite = new Sprite(GAMECANVAS_CENTER_X - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture); tiledbg = new Tiledbg(renderer, screen, asset, {0, 0, param->gameWidth, param->gameHeight}, TILED_MODE_RANDOM); gameLogo = new GameLogo(renderer, screen, asset, param, GAMECANVAS_CENTER_X, param->titleCC); gameLogo->enable(); - defineButtons = new DefineButtons(renderer, input, text2, param, options, section); + defineButtons = new DefineButtons(input, text2, param, options, section); // Inicializa los valores init();