Arreglos varios al codi
This commit is contained in:
@@ -195,10 +195,6 @@ AnimatedSprite::AnimatedSprite(animatedSprite_t *animation)
|
|||||||
// Destructor
|
// Destructor
|
||||||
AnimatedSprite::~AnimatedSprite()
|
AnimatedSprite::~AnimatedSprite()
|
||||||
{
|
{
|
||||||
for (auto &a : animation)
|
|
||||||
{
|
|
||||||
a.frames.clear();
|
|
||||||
}
|
|
||||||
animation.clear();
|
animation.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,12 +37,6 @@ Asset::Asset(std::string executablePath)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
|
||||||
Asset::~Asset()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Añade un elemento a la lista
|
// Añade un elemento a la lista
|
||||||
void Asset::add(std::string file, enum assetType type, bool required, bool absolute)
|
void Asset::add(std::string file, enum assetType type, bool required, bool absolute)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ private:
|
|||||||
Asset(std::string path);
|
Asset(std::string path);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Asset();
|
~Asset() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||||
|
|||||||
@@ -11,17 +11,14 @@
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Background::Background(SDL_Renderer *renderer)
|
Background::Background(SDL_Renderer *renderer)
|
||||||
|
: renderer(renderer)
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
|
||||||
this->renderer = renderer;
|
|
||||||
asset = Asset::get();
|
|
||||||
|
|
||||||
// Carga las texturas
|
// Carga las texturas
|
||||||
buildingsTexture = new Texture(renderer, asset->get("game_buildings.png"));
|
buildingsTexture = new Texture(renderer, Asset::get()->get("game_buildings.png"));
|
||||||
topCloudsTexture = new Texture(renderer, asset->get("game_clouds1.png"));
|
topCloudsTexture = new Texture(renderer, Asset::get()->get("game_clouds1.png"));
|
||||||
bottomCloudsTexture = new Texture(renderer, asset->get("game_clouds2.png"));
|
bottomCloudsTexture = new Texture(renderer, Asset::get()->get("game_clouds2.png"));
|
||||||
grassTexture = new Texture(renderer, asset->get("game_grass.png"));
|
grassTexture = new Texture(renderer, Asset::get()->get("game_grass.png"));
|
||||||
gradientsTexture = new Texture(renderer, asset->get("game_sky_colors.png"));
|
gradientsTexture = new Texture(renderer, Asset::get()->get("game_sky_colors.png"));
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
gradientNumber = 0;
|
gradientNumber = 0;
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ class Background
|
|||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
|
||||||
|
|
||||||
Texture *buildingsTexture; // Textura con los edificios de fondo
|
Texture *buildingsTexture; // Textura con los edificios de fondo
|
||||||
Texture *topCloudsTexture; // Textura con las nubes de fondo
|
Texture *topCloudsTexture; // Textura con las nubes de fondo
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
// Constructor
|
// Constructor
|
||||||
Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector<std::string> *animation)
|
Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector<std::string> *animation)
|
||||||
{
|
{
|
||||||
sprite = new AnimatedSprite(texture, "", animation);
|
sprite = std::make_unique<AnimatedSprite>(texture, "", animation);
|
||||||
disable();
|
disable();
|
||||||
|
|
||||||
enabled = true;
|
enabled = true;
|
||||||
@@ -274,12 +274,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
|
|||||||
this->kind = kind;
|
this->kind = kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
|
||||||
Balloon::~Balloon()
|
|
||||||
{
|
|
||||||
delete sprite;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Centra el globo en la posición X
|
// Centra el globo en la posición X
|
||||||
void Balloon::allignTo(int x)
|
void Balloon::allignTo(int x)
|
||||||
{
|
{
|
||||||
@@ -333,10 +327,9 @@ void Balloon::render()
|
|||||||
|
|
||||||
if (kind == POWER_BALL && !isBeingCreated())
|
if (kind == POWER_BALL && !isBeingCreated())
|
||||||
{
|
{
|
||||||
Sprite *sp = new Sprite(sprite->getRect(), sprite->getTexture());
|
auto sp = std::make_unique<Sprite>(sprite->getRect(), sprite->getTexture());
|
||||||
sp->setSpriteClip(BALLOON_WIDTH_4, 0, BALLOON_WIDTH_4, BALLOON_WIDTH_4);
|
sp->setSpriteClip(BALLOON_WIDTH_4, 0, BALLOON_WIDTH_4, BALLOON_WIDTH_4);
|
||||||
sp->render();
|
sp->render();
|
||||||
delete sp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -601,37 +594,37 @@ void Balloon::updateAnimation()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si el globo está habilitado
|
// Comprueba si el globo está habilitado
|
||||||
bool Balloon::isEnabled()
|
bool Balloon::isEnabled() const
|
||||||
{
|
{
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
float Balloon::getPosX()
|
float Balloon::getPosX() const
|
||||||
{
|
{
|
||||||
return posX;
|
return posX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
float Balloon::getPosY()
|
float Balloon::getPosY() const
|
||||||
{
|
{
|
||||||
return posY;
|
return posY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
float Balloon::getVelY()
|
float Balloon::getVelY() const
|
||||||
{
|
{
|
||||||
return velY;
|
return velY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int Balloon::getWidth()
|
int Balloon::getWidth() const
|
||||||
{
|
{
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int Balloon::getHeight()
|
int Balloon::getHeight() const
|
||||||
{
|
{
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
@@ -649,19 +642,19 @@ void Balloon::setSpeed(float speed)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int Balloon::getKind()
|
int Balloon::getKind() const
|
||||||
{
|
{
|
||||||
return kind;
|
return kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
Uint8 Balloon::getSize()
|
Uint8 Balloon::getSize() const
|
||||||
{
|
{
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene la clase a la que pertenece el globo
|
// Obtiene la clase a la que pertenece el globo
|
||||||
Uint8 Balloon::getClass()
|
Uint8 Balloon::getClass() const
|
||||||
{
|
{
|
||||||
if ((kind >= BALLOON_1) && (kind <= BALLOON_4))
|
if ((kind >= BALLOON_1) && (kind <= BALLOON_4))
|
||||||
{
|
{
|
||||||
@@ -683,7 +676,7 @@ void Balloon::setStop(bool state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool Balloon::isStopped()
|
bool Balloon::isStopped() const
|
||||||
{
|
{
|
||||||
return stopped;
|
return stopped;
|
||||||
}
|
}
|
||||||
@@ -695,7 +688,7 @@ void Balloon::setBlink(bool value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool Balloon::isBlinking()
|
bool Balloon::isBlinking() const
|
||||||
{
|
{
|
||||||
return blinking;
|
return blinking;
|
||||||
}
|
}
|
||||||
@@ -707,7 +700,7 @@ void Balloon::setVisible(bool value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool Balloon::isVisible()
|
bool Balloon::isVisible() const
|
||||||
{
|
{
|
||||||
return visible;
|
return visible;
|
||||||
}
|
}
|
||||||
@@ -719,7 +712,7 @@ void Balloon::setInvulnerable(bool value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool Balloon::isInvulnerable()
|
bool Balloon::isInvulnerable() const
|
||||||
{
|
{
|
||||||
return invulnerable;
|
return invulnerable;
|
||||||
}
|
}
|
||||||
@@ -731,7 +724,7 @@ void Balloon::setBeingCreated(bool value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool Balloon::isBeingCreated()
|
bool Balloon::isBeingCreated() const
|
||||||
{
|
{
|
||||||
return beingCreated;
|
return beingCreated;
|
||||||
}
|
}
|
||||||
@@ -743,13 +736,13 @@ void Balloon::setStoppedTimer(Uint16 time)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
Uint16 Balloon::getStoppedTimer()
|
Uint16 Balloon::getStoppedTimer() const
|
||||||
{
|
{
|
||||||
return stoppedCounter;
|
return stoppedCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
Uint16 Balloon::getScore()
|
Uint16 Balloon::getScore() const
|
||||||
{
|
{
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
@@ -768,7 +761,7 @@ void Balloon::updateColliders()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene le valor de la variable
|
// Obtiene le valor de la variable
|
||||||
Uint8 Balloon::getMenace()
|
Uint8 Balloon::getMenace() const
|
||||||
{
|
{
|
||||||
if (isEnabled())
|
if (isEnabled())
|
||||||
{
|
{
|
||||||
@@ -781,7 +774,7 @@ Uint8 Balloon::getMenace()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene le valor de la variable
|
// Obtiene le valor de la variable
|
||||||
Uint8 Balloon::getPower()
|
Uint8 Balloon::getPower() const
|
||||||
{
|
{
|
||||||
return power;
|
return power;
|
||||||
}
|
}
|
||||||
@@ -828,13 +821,13 @@ void Balloon::updateBounce()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Indica si el globo se puede explotar
|
// Indica si el globo se puede explotar
|
||||||
bool Balloon::canBePopped()
|
bool Balloon::canBePopped() const
|
||||||
{
|
{
|
||||||
return isEnabled() && !isBeingCreated();
|
return isEnabled() && !isBeingCreated();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indica si el globo se puede destruir
|
// Indica si el globo se puede destruir
|
||||||
bool Balloon::canBeDestroyed()
|
bool Balloon::canBeDestroyed() const
|
||||||
{
|
{
|
||||||
return isEnabled();
|
return isEnabled();
|
||||||
}
|
}
|
||||||
125
source/balloon.h
125
source/balloon.h
@@ -3,75 +3,76 @@
|
|||||||
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint16, Uint32
|
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint16, Uint32
|
||||||
#include <string> // for string
|
#include <string> // for string
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
|
#include <memory>
|
||||||
#include "utils.h" // for circle_t
|
#include "utils.h" // for circle_t
|
||||||
class AnimatedSprite;
|
#include "animated_sprite.h"
|
||||||
class Texture;
|
class Texture;
|
||||||
|
|
||||||
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
|
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
|
||||||
#define MAX_BOUNCE 10
|
constexpr int MAX_BOUNCE = 10;
|
||||||
|
|
||||||
// Tipos de globo
|
// Tipos de globo
|
||||||
#define BALLOON_1 1
|
constexpr int BALLOON_1 = 1;
|
||||||
#define BALLOON_2 2
|
constexpr int BALLOON_2 = 2;
|
||||||
#define BALLOON_3 3
|
constexpr int BALLOON_3 = 3;
|
||||||
#define BALLOON_4 4
|
constexpr int BALLOON_4 = 4;
|
||||||
#define HEXAGON_1 5
|
constexpr int HEXAGON_1 = 5;
|
||||||
#define HEXAGON_2 6
|
constexpr int HEXAGON_2 = 6;
|
||||||
#define HEXAGON_3 7
|
constexpr int HEXAGON_3 = 7;
|
||||||
#define HEXAGON_4 8
|
constexpr int HEXAGON_4 = 8;
|
||||||
#define POWER_BALL 9
|
constexpr int POWER_BALL = 9;
|
||||||
|
|
||||||
// Puntos de globo
|
// Puntos de globo
|
||||||
#define BALLOON_SCORE_1 50
|
constexpr int BALLOON_SCORE_1 = 50;
|
||||||
#define BALLOON_SCORE_2 100
|
constexpr int BALLOON_SCORE_2 = 100;
|
||||||
#define BALLOON_SCORE_3 200
|
constexpr int BALLOON_SCORE_3 = 200;
|
||||||
#define BALLOON_SCORE_4 400
|
constexpr int BALLOON_SCORE_4 = 400;
|
||||||
|
|
||||||
// Tamaños de globo
|
// Tamaños de globo
|
||||||
#define BALLOON_SIZE_1 1
|
constexpr int BALLOON_SIZE_1 = 1;
|
||||||
#define BALLOON_SIZE_2 2
|
constexpr int BALLOON_SIZE_2 = 2;
|
||||||
#define BALLOON_SIZE_3 3
|
constexpr int BALLOON_SIZE_3 = 3;
|
||||||
#define BALLOON_SIZE_4 4
|
constexpr int BALLOON_SIZE_4 = 4;
|
||||||
|
|
||||||
// Clases de globo
|
// Clases de globo
|
||||||
#define BALLOON_CLASS 0
|
constexpr int BALLOON_CLASS = 0;
|
||||||
#define HEXAGON_CLASS 1
|
constexpr int HEXAGON_CLASS = 1;
|
||||||
|
|
||||||
// Velocidad del globo
|
// Velocidad del globo
|
||||||
#define BALLOON_VELX_POSITIVE 0.7f
|
constexpr float BALLOON_VELX_POSITIVE = 0.7f;
|
||||||
#define BALLOON_VELX_NEGATIVE -0.7f
|
constexpr float BALLOON_VELX_NEGATIVE = -0.7f;
|
||||||
|
|
||||||
// Indice para las animaciones de los globos
|
// Indice para las animaciones de los globos
|
||||||
#define BALLOON_MOVING_ANIMATION 0
|
constexpr int BALLOON_MOVING_ANIMATION = 0;
|
||||||
#define BALLOON_POP_ANIMATION 1
|
constexpr int BALLOON_POP_ANIMATION = 1;
|
||||||
#define BALLOON_BORN_ANIMATION 2
|
constexpr int BALLOON_BORN_ANIMATION = 2;
|
||||||
|
|
||||||
// Cantidad posible de globos
|
// Cantidad posible de globos
|
||||||
#define MAX_BALLOONS 100
|
constexpr int MAX_BALLOONS = 100;
|
||||||
|
|
||||||
// Velocidades a las que se mueven los globos
|
// Velocidades a las que se mueven los globos
|
||||||
#define BALLOON_SPEED_1 0.60f
|
constexpr float BALLOON_SPEED_1 = 0.60f;
|
||||||
#define BALLOON_SPEED_2 0.70f
|
constexpr float BALLOON_SPEED_2 = 0.70f;
|
||||||
#define BALLOON_SPEED_3 0.80f
|
constexpr float BALLOON_SPEED_3 = 0.80f;
|
||||||
#define BALLOON_SPEED_4 0.90f
|
constexpr float BALLOON_SPEED_4 = 0.90f;
|
||||||
#define BALLOON_SPEED_5 1.00f
|
constexpr float BALLOON_SPEED_5 = 1.00f;
|
||||||
|
|
||||||
// Tamaño de los globos
|
// Tamaño de los globos
|
||||||
#define BALLOON_WIDTH_1 10
|
constexpr int BALLOON_WIDTH_1 = 10;
|
||||||
#define BALLOON_WIDTH_2 16
|
constexpr int BALLOON_WIDTH_2 = 16;
|
||||||
#define BALLOON_WIDTH_3 26
|
constexpr int BALLOON_WIDTH_3 = 26;
|
||||||
#define BALLOON_WIDTH_4 46
|
constexpr int BALLOON_WIDTH_4 = 46;
|
||||||
|
|
||||||
// PowerBall
|
// PowerBall
|
||||||
#define POWERBALL_SCREENPOWER_MINIMUM 10
|
constexpr int POWERBALL_SCREENPOWER_MINIMUM = 10;
|
||||||
#define POWERBALL_COUNTER 8
|
constexpr int POWERBALL_COUNTER = 8;
|
||||||
|
|
||||||
// Clase Balloon
|
// Clase Balloon
|
||||||
class Balloon
|
class Balloon
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Estructura para las variables para el efecto de los rebotes
|
// Estructura para las variables para el efecto de los rebotes
|
||||||
struct bouncing
|
struct Bouncing
|
||||||
{
|
{
|
||||||
bool enabled; // Si el efecto está activo
|
bool enabled; // Si el efecto está activo
|
||||||
Uint8 counter; // Countador para el efecto
|
Uint8 counter; // Countador para el efecto
|
||||||
@@ -85,7 +86,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
AnimatedSprite *sprite; // Sprite del objeto globo
|
std::unique_ptr<AnimatedSprite> sprite; // Sprite del objeto globo
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
float posX; // Posición en el eje X
|
float posX; // Posición en el eje X
|
||||||
@@ -115,7 +116,7 @@ private:
|
|||||||
float speed; // Velocidad a la que se mueven los globos
|
float speed; // Velocidad a la que se mueven los globos
|
||||||
Uint8 size; // Tamaño del globo
|
Uint8 size; // Tamaño del globo
|
||||||
Uint8 power; // Cantidad de poder que alberga el globo
|
Uint8 power; // Cantidad de poder que alberga el globo
|
||||||
bouncing bouncing; // Contiene las variables para el efecto de rebote
|
Bouncing bouncing; // Contiene las variables para el efecto de rebote
|
||||||
|
|
||||||
// Alinea el circulo de colisión con la posición del objeto globo
|
// Alinea el circulo de colisión con la posición del objeto globo
|
||||||
void updateColliders();
|
void updateColliders();
|
||||||
@@ -143,7 +144,7 @@ public:
|
|||||||
Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector<std::string> *animation);
|
Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector<std::string> *animation);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Balloon();
|
~Balloon() = default;
|
||||||
|
|
||||||
// Centra el globo en la posición X
|
// Centra el globo en la posición X
|
||||||
void allignTo(int x);
|
void allignTo(int x);
|
||||||
@@ -164,22 +165,22 @@ public:
|
|||||||
void update();
|
void update();
|
||||||
|
|
||||||
// Comprueba si el globo está habilitado
|
// Comprueba si el globo está habilitado
|
||||||
bool isEnabled();
|
bool isEnabled() const;
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
float getPosX();
|
float getPosX() const;
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
float getPosY();
|
float getPosY() const;
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
float getVelY();
|
float getVelY() const;
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int getWidth();
|
int getWidth() const;
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int getHeight();
|
int getHeight() const;
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setVelY(float velY);
|
void setVelY(float velY);
|
||||||
@@ -188,62 +189,62 @@ public:
|
|||||||
void setSpeed(float speed);
|
void setSpeed(float speed);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
int getKind();
|
int getKind() const;
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
Uint8 getSize();
|
Uint8 getSize() const;
|
||||||
|
|
||||||
// Obtiene la clase a la que pertenece el globo
|
// Obtiene la clase a la que pertenece el globo
|
||||||
Uint8 getClass();
|
Uint8 getClass() const;
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setStop(bool value);
|
void setStop(bool value);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool isStopped();
|
bool isStopped() const;
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setBlink(bool value);
|
void setBlink(bool value);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool isBlinking();
|
bool isBlinking() const;
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setVisible(bool value);
|
void setVisible(bool value);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool isVisible();
|
bool isVisible() const;
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setInvulnerable(bool value);
|
void setInvulnerable(bool value);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool isInvulnerable();
|
bool isInvulnerable() const;
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
bool isBeingCreated();
|
bool isBeingCreated() const;
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setStoppedTimer(Uint16 time);
|
void setStoppedTimer(Uint16 time);
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
Uint16 getStoppedTimer();
|
Uint16 getStoppedTimer() const;
|
||||||
|
|
||||||
// Obtiene del valor de la variable
|
// Obtiene del valor de la variable
|
||||||
Uint16 getScore();
|
Uint16 getScore() const;
|
||||||
|
|
||||||
// Obtiene el circulo de colisión
|
// Obtiene el circulo de colisión
|
||||||
circle_t &getCollider();
|
circle_t &getCollider();
|
||||||
|
|
||||||
// Obtiene le valor de la variable
|
// Obtiene le valor de la variable
|
||||||
Uint8 getMenace();
|
Uint8 getMenace() const;
|
||||||
|
|
||||||
// Obtiene le valor de la variable
|
// Obtiene le valor de la variable
|
||||||
Uint8 getPower();
|
Uint8 getPower() const;
|
||||||
|
|
||||||
// Indica si el globo se puede explotar
|
// Indica si el globo se puede explotar
|
||||||
bool canBePopped();
|
bool canBePopped() const;
|
||||||
|
|
||||||
// Indica si el globo se puede destruir
|
// Indica si el globo se puede destruir
|
||||||
bool canBeDestroyed();
|
bool canBeDestroyed() const;
|
||||||
};
|
};
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
#include "define_buttons.h"
|
#include "define_buttons.h"
|
||||||
#include "lang.h" // for getText
|
#include "lang.h" // for getText
|
||||||
#include "options.h" // for options
|
#include "options.h" // for options
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
#include "section.h" // for name, name_e, options, options_e
|
#include "section.h" // for name, name_e, options, options_e
|
||||||
#include "text.h" // for Text
|
#include "text.h" // for Text
|
||||||
#include "utils.h" // for op_controller_t, options_t, param_t, paramGame_t
|
#include "utils.h" // for op_controller_t, options_t, param_t, paramGame_t
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
DefineButtons::DefineButtons(Text *text)
|
DefineButtons::DefineButtons(Text *text)
|
||||||
|
: text(text)
|
||||||
{
|
{
|
||||||
// Copia punteros a los objetos
|
// Copia punteros a los objetos
|
||||||
input = Input::get();
|
input = Input::get();
|
||||||
this->text = text;
|
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
enabled = false;
|
enabled = false;
|
||||||
@@ -54,11 +54,6 @@ DefineButtons::DefineButtons(Text *text)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
|
||||||
DefineButtons::~DefineButtons()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void DefineButtons::update()
|
void DefineButtons::update()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public:
|
|||||||
DefineButtons(Text *text);
|
DefineButtons(Text *text);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~DefineButtons();
|
~DefineButtons() = default;
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void update();
|
void update();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "enemy_formations.h"
|
#include "enemy_formations.h"
|
||||||
#include "balloon.h" // for BALLOON_VELX_NEGATIVE, BALLOON_VELX_POSITIVE
|
#include "balloon.h" // for BALLOON_VELX_NEGATIVE, BALLOON_VELX_POSITIVE
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
#include "utils.h" // for paramGame_t, param_t, zone_t, BLOCK
|
#include "utils.h" // for paramGame_t, param_t, zone_t, BLOCK
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
EnemyFormations::EnemyFormations()
|
EnemyFormations::EnemyFormations()
|
||||||
@@ -11,27 +11,22 @@ EnemyFormations::EnemyFormations()
|
|||||||
initGameStages();
|
initGameStages();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
|
||||||
EnemyFormations::~EnemyFormations()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa las formaciones enemigas
|
// Inicializa las formaciones enemigas
|
||||||
void EnemyFormations::initEnemyFormations()
|
void EnemyFormations::initEnemyFormations()
|
||||||
{
|
{
|
||||||
const int y4 = - BLOCK;
|
const int y4 = -BLOCK;
|
||||||
const int x4_0 = param.game.playArea.rect.x;
|
const int x4_0 = param.game.playArea.rect.x;
|
||||||
const int x4_100 = param.game.playArea.rect.w - BALLOON_WIDTH_4;
|
const int x4_100 = param.game.playArea.rect.w - BALLOON_WIDTH_4;
|
||||||
|
|
||||||
const int y3 = - BLOCK;
|
const int y3 = -BLOCK;
|
||||||
const int x3_0 = param.game.playArea.rect.x;
|
const int x3_0 = param.game.playArea.rect.x;
|
||||||
const int x3_100 = param.game.playArea.rect.w - BALLOON_WIDTH_3;
|
const int x3_100 = param.game.playArea.rect.w - BALLOON_WIDTH_3;
|
||||||
|
|
||||||
const int y2 = - BLOCK;
|
const int y2 = -BLOCK;
|
||||||
const int x2_0 = param.game.playArea.rect.x;
|
const int x2_0 = param.game.playArea.rect.x;
|
||||||
const int x2_100 = param.game.playArea.rect.w - BALLOON_WIDTH_2;
|
const int x2_100 = param.game.playArea.rect.w - BALLOON_WIDTH_2;
|
||||||
|
|
||||||
const int y1 = - BLOCK;
|
const int y1 = -BLOCK;
|
||||||
const int x1_0 = param.game.playArea.rect.x;
|
const int x1_0 = param.game.playArea.rect.x;
|
||||||
const int x1_50 = param.game.playArea.centerX - (BALLOON_WIDTH_1 / 2);
|
const int x1_50 = param.game.playArea.centerX - (BALLOON_WIDTH_1 / 2);
|
||||||
const int x1_100 = param.game.playArea.rect.w - BALLOON_WIDTH_1;
|
const int x1_100 = param.game.playArea.rect.w - BALLOON_WIDTH_1;
|
||||||
@@ -719,7 +714,7 @@ void EnemyFormations::initGameStages()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve una fase
|
// Devuelve una fase
|
||||||
stage_t EnemyFormations::getStage(int index)
|
stage_t EnemyFormations::getStage(int index) const
|
||||||
{
|
{
|
||||||
return stage[index];
|
return stage[index];
|
||||||
}
|
}
|
||||||
@@ -56,8 +56,8 @@ public:
|
|||||||
EnemyFormations();
|
EnemyFormations();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~EnemyFormations();
|
~EnemyFormations() = default;
|
||||||
|
|
||||||
// Devuelve una fase
|
// Devuelve una fase
|
||||||
stage_t getStage(int index);
|
stage_t getStage(int index) const;
|
||||||
};
|
};
|
||||||
@@ -12,13 +12,7 @@ Explosions::Explosions()
|
|||||||
// Destructor
|
// Destructor
|
||||||
Explosions::~Explosions()
|
Explosions::~Explosions()
|
||||||
{
|
{
|
||||||
for (auto explosion : explosions)
|
explosions.clear();
|
||||||
{
|
|
||||||
if (explosion)
|
|
||||||
{
|
|
||||||
delete explosion;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la lógica de la clase
|
// Actualiza la lógica de la clase
|
||||||
@@ -42,7 +36,7 @@ void Explosions::render()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Añade texturas al objetp
|
// Añade texturas al objeto
|
||||||
void Explosions::addTexture(int size, Texture *texture, std::vector<std::string> *animation)
|
void Explosions::addTexture(int size, Texture *texture, std::vector<std::string> *animation)
|
||||||
{
|
{
|
||||||
explosion_texture_t temp;
|
explosion_texture_t temp;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public:
|
|||||||
// Dibuja el objeto en pantalla
|
// Dibuja el objeto en pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Añade texturas al objetp
|
// Añade texturas al objeto
|
||||||
void addTexture(int size, Texture *texture, std::vector<std::string> *animation);
|
void addTexture(int size, Texture *texture, std::vector<std::string> *animation);
|
||||||
|
|
||||||
// Añade una explosión
|
// Añade una explosión
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
#include "utils.h" // for param_t, paramGame_t, paramFade_t
|
#include "utils.h" // for param_t, paramGame_t, paramFade_t
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Fade::Fade(SDL_Renderer *renderer) : renderer(renderer)
|
Fade::Fade(SDL_Renderer *renderer)
|
||||||
|
: renderer(renderer)
|
||||||
{
|
{
|
||||||
// Crea la textura donde dibujar el fade
|
// Crea la textura donde dibujar el fade
|
||||||
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||||
|
|||||||
@@ -1,41 +1,39 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include <SDL2/SDL.h> // for SDL_INIT_GAMECONTROLLER, SDL_InitSubS...
|
#include <SDL2/SDL.h> // for SDL_INIT_GAMECONTROLLER, SDL_InitSubS...
|
||||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||||
#include <SDL2/SDL_events.h> // for SDL_ENABLE
|
#include <SDL2/SDL_events.h> // for SDL_ENABLE
|
||||||
#include <SDL2/SDL_keyboard.h> // for SDL_GetKeyboardState
|
#include <SDL2/SDL_keyboard.h> // for SDL_GetKeyboardState
|
||||||
#include <iostream> // for basic_ostream, operator<<, cout, basi...
|
#include <iostream> // for basic_ostream, operator<<, cout, basi...
|
||||||
|
|
||||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||||
Input *Input::input = nullptr;
|
Input *Input::input = nullptr;
|
||||||
|
|
||||||
// [SINGLETON] Crearemos el objeto input con esta función estática
|
// [SINGLETON] Crearemos el objeto input con esta función estática
|
||||||
void Input::init(std::string file)
|
void Input::init(std::string dbPath)
|
||||||
{
|
{
|
||||||
Input::input = new Input(file);
|
Input::input = new Input(dbPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto input con esta función estática
|
// [SINGLETON] Destruiremos el objeto input con esta función estática
|
||||||
void Input::destroy()
|
void Input::destroy()
|
||||||
{
|
{
|
||||||
delete Input::input;
|
delete Input::input;
|
||||||
}
|
}
|
||||||
|
|
||||||
// [SINGLETON] Con este método obtenemos el objeto input y podemos trabajar con él
|
// [SINGLETON] Con este método obtenemos el objeto input y podemos trabajar con él
|
||||||
Input *Input::get()
|
Input *Input::get()
|
||||||
{
|
{
|
||||||
return Input::input;
|
return Input::input;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Input::Input(std::string file)
|
Input::Input(std::string dbPath)
|
||||||
|
: dbPath(dbPath)
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
verbose = false;
|
verbose = false;
|
||||||
enabled = true;
|
enabled = true;
|
||||||
|
|
||||||
// Fichero gamecontrollerdb.txt
|
|
||||||
dbPath = file;
|
|
||||||
|
|
||||||
// Busca si hay mandos conectados
|
// Busca si hay mandos conectados
|
||||||
discoverGameControllers();
|
discoverGameControllers();
|
||||||
|
|
||||||
@@ -75,7 +73,6 @@ Input::Input(std::string file)
|
|||||||
// Destructor
|
// Destructor
|
||||||
Input::~Input()
|
Input::~Input()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el estado del objeto
|
// Actualiza el estado del objeto
|
||||||
@@ -171,7 +168,7 @@ bool Input::checkInput(inputs_e input, bool repeat, int device, int index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gameControllerFound() && index < numGamepads)
|
if (gameControllerFound() && index < numGamepads)
|
||||||
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
|
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
|
||||||
{
|
{
|
||||||
successGameController = checkAxisInput(input, index);
|
successGameController = checkAxisInput(input, index);
|
||||||
|
|||||||
@@ -100,14 +100,14 @@ private:
|
|||||||
bool checkAxisInput(inputs_e input, int index = 0) const;
|
bool checkAxisInput(inputs_e input, int index = 0) const;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Input(std::string file);
|
Input(std::string dbPath);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Input();
|
~Input();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||||
static void init(std::string file);
|
static void init(std::string dbPath);
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||||
static void destroy();
|
static void destroy();
|
||||||
|
|||||||
@@ -22,7 +22,8 @@
|
|||||||
struct JA_Music_t;
|
struct JA_Music_t;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Instructions::Instructions(JA_Music_t *music) : music(music)
|
Instructions::Instructions(JA_Music_t *music)
|
||||||
|
: music(music)
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
renderer = Screen::get()->getRenderer();
|
renderer = Screen::get()->getRenderer();
|
||||||
|
|||||||
@@ -19,7 +19,8 @@
|
|||||||
struct JA_Music_t;
|
struct JA_Music_t;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Intro::Intro(JA_Music_t *music) : music(music)
|
Intro::Intro(JA_Music_t *music)
|
||||||
|
: music(music)
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
SDL_Renderer *renderer = Screen::get()->getRenderer();
|
SDL_Renderer *renderer = Screen::get()->getRenderer();
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include <stdlib.h> // for rand
|
#include <stdlib.h> // for rand
|
||||||
#include "animated_sprite.h" // for AnimatedSprite
|
#include "animated_sprite.h" // for AnimatedSprite
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
class Texture;
|
class Texture;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Item::Item(int kind, float x, float y, SDL_Rect *playArea, Texture *texture, std::vector<std::string> *animation)
|
Item::Item(int kind, float x, float y, SDL_Rect *playArea, Texture *texture, std::vector<std::string> *animation)
|
||||||
|
: kind(kind), playArea(playArea)
|
||||||
{
|
{
|
||||||
sprite = new AnimatedSprite(texture, "", animation);
|
sprite = new AnimatedSprite(texture, "", animation);
|
||||||
|
|
||||||
this->kind = kind;
|
|
||||||
this->playArea = playArea;
|
|
||||||
enabled = true;
|
enabled = true;
|
||||||
timeToLive = 600;
|
timeToLive = 600;
|
||||||
accelX = 0.0f;
|
accelX = 0.0f;
|
||||||
|
|||||||
@@ -1,21 +1,15 @@
|
|||||||
#include "manage_hiscore_table.h"
|
#include "manage_hiscore_table.h"
|
||||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||||
#include <SDL2/SDL_rwops.h> // for SDL_RWread, SDL_RWwrite, SDL_RWFromFile
|
#include <SDL2/SDL_rwops.h> // for SDL_RWread, SDL_RWwrite, SDL_RWFromFile
|
||||||
#include <stdlib.h> // for free, malloc
|
#include <stdlib.h> // for free, malloc
|
||||||
#include <algorithm> // for sort
|
#include <algorithm> // for sort
|
||||||
#include <iostream> // for basic_ostream, char_traits, operator<<
|
#include <iostream> // for basic_ostream, char_traits, operator<<
|
||||||
#include "utils.h" // for hiScoreEntry_t
|
#include "utils.h" // for hiScoreEntry_t
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
ManageHiScoreTable::ManageHiScoreTable(std::vector<hiScoreEntry_t> *table)
|
ManageHiScoreTable::ManageHiScoreTable(std::vector<hiScoreEntry_t> *table)
|
||||||
{
|
: table(table) {}
|
||||||
this->table = table;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
ManageHiScoreTable::~ManageHiScoreTable()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resetea la tabla a los valores por defecto
|
// Resetea la tabla a los valores por defecto
|
||||||
void ManageHiScoreTable::clear()
|
void ManageHiScoreTable::clear()
|
||||||
@@ -67,7 +61,7 @@ void ManageHiScoreTable::sort()
|
|||||||
bool ManageHiScoreTable::loadFromFile(std::string filePath)
|
bool ManageHiScoreTable::loadFromFile(std::string filePath)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
bool success = true;
|
bool success = true;
|
||||||
const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
|
const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
|
||||||
SDL_RWops *file = SDL_RWFromFile(filePath.c_str(), "r+b");
|
SDL_RWops *file = SDL_RWFromFile(filePath.c_str(), "r+b");
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public:
|
|||||||
ManageHiScoreTable(std::vector<hiScoreEntry_t> *table);
|
ManageHiScoreTable(std::vector<hiScoreEntry_t> *table);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~ManageHiScoreTable();
|
~ManageHiScoreTable() = default;
|
||||||
|
|
||||||
// Resetea la tabla a los valores por defecto
|
// Resetea la tabla a los valores por defecto
|
||||||
void clear();
|
void clear();
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#include "moving_sprite.h"
|
#include "moving_sprite.h"
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, Texture *texture)
|
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, Texture *texture)
|
||||||
|
: x(x), y(y)
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
this->texture = texture;
|
this->texture = texture;
|
||||||
@@ -12,8 +13,6 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vel
|
|||||||
this->h = h;
|
this->h = h;
|
||||||
|
|
||||||
// Establece la posición X,Y del sprite
|
// Establece la posición X,Y del sprite
|
||||||
this->x = x;
|
|
||||||
this->y = y;
|
|
||||||
xPrev = x;
|
xPrev = x;
|
||||||
yPrev = y;
|
yPrev = y;
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,11 @@
|
|||||||
#include <math.h> // for roundf
|
#include <math.h> // for roundf
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "asset.h" // for Asset
|
#include "asset.h" // for Asset
|
||||||
#include "lang.h" // for getText
|
#include "lang.h" // for getText
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
#include "text.h" // for Text
|
#include "text.h" // for Text
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||||
Scoreboard *Scoreboard::scoreboard = nullptr;
|
Scoreboard *Scoreboard::scoreboard = nullptr;
|
||||||
@@ -33,7 +33,8 @@ Scoreboard *Scoreboard::get()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Scoreboard::Scoreboard(SDL_Renderer *renderer) : renderer(renderer)
|
Scoreboard::Scoreboard(SDL_Renderer *renderer)
|
||||||
|
: renderer(renderer)
|
||||||
{
|
{
|
||||||
// Inicializa punteros
|
// Inicializa punteros
|
||||||
gamePowerMeterTexture = nullptr;
|
gamePowerMeterTexture = nullptr;
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ Screen *Screen::get()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer) : window(window), renderer(renderer)
|
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||||
|
: window(window), renderer(renderer)
|
||||||
{
|
{
|
||||||
// Copia punteros
|
// Copia punteros
|
||||||
input = Input::get();
|
input = Input::get();
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Sprite::Sprite(int x, int y, int w, int h, Texture *texture) : x(x), y(y), w(w), h(h), texture(texture)
|
Sprite::Sprite(int x, int y, int w, int h, Texture *texture)
|
||||||
|
: x(x), y(y), w(w), h(h), texture(texture)
|
||||||
{
|
{
|
||||||
// Establece el rectangulo de donde coger la imagen
|
// Establece el rectangulo de donde coger la imagen
|
||||||
spriteClip = {0, 0, w, h};
|
spriteClip = {0, 0, w, h};
|
||||||
@@ -11,7 +12,8 @@ Sprite::Sprite(int x, int y, int w, int h, Texture *texture) : x(x), y(y), w(w),
|
|||||||
enabled = true;
|
enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite::Sprite(SDL_Rect rect, Texture *texture): x(rect.x), y(rect.y), w(rect.w), h(rect.h), texture(texture)
|
Sprite::Sprite(SDL_Rect rect, Texture *texture)
|
||||||
|
: x(rect.x), y(rect.y), w(rect.w), h(rect.h), texture(texture)
|
||||||
{
|
{
|
||||||
// Establece el rectangulo de donde coger la imagen
|
// Establece el rectangulo de donde coger la imagen
|
||||||
spriteClip = {0, 0, w, h};
|
spriteClip = {0, 0, w, h};
|
||||||
@@ -20,12 +22,6 @@ Sprite::Sprite(SDL_Rect rect, Texture *texture): x(rect.x), y(rect.y), w(rect.w)
|
|||||||
enabled = true;
|
enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
|
||||||
Sprite::~Sprite()
|
|
||||||
{
|
|
||||||
texture = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Muestra el sprite por pantalla
|
// Muestra el sprite por pantalla
|
||||||
void Sprite::render()
|
void Sprite::render()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public:
|
|||||||
Sprite(SDL_Rect rect, Texture *texture = nullptr);
|
Sprite(SDL_Rect rect, Texture *texture = nullptr);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Sprite();
|
~Sprite() = default;
|
||||||
|
|
||||||
// Muestra el sprite por pantalla
|
// Muestra el sprite por pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|||||||
@@ -12,11 +12,8 @@
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Texture::Texture(SDL_Renderer *renderer, std::string path)
|
Texture::Texture(SDL_Renderer *renderer, std::string path)
|
||||||
|
: renderer(renderer), path(path)
|
||||||
{
|
{
|
||||||
// Copia punteros
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->path = path;
|
|
||||||
|
|
||||||
// Inicializa
|
// Inicializa
|
||||||
surface = nullptr;
|
surface = nullptr;
|
||||||
texture = nullptr;
|
texture = nullptr;
|
||||||
@@ -53,7 +50,6 @@ Texture::Texture(SDL_Renderer *renderer, std::string path)
|
|||||||
// Destructor
|
// Destructor
|
||||||
Texture::~Texture()
|
Texture::~Texture()
|
||||||
{
|
{
|
||||||
// Libera memoria
|
|
||||||
unload();
|
unload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
#include "tiled_bg.h"
|
#include "tiled_bg.h"
|
||||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||||
#include <SDL2/SDL_stdinc.h> // for SDL_sinf
|
#include <SDL2/SDL_stdinc.h> // for SDL_sinf
|
||||||
#include <stdlib.h> // for rand
|
#include <stdlib.h> // for rand
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Tiledbg::Tiledbg(std::string texturePath, SDL_Rect pos, int mode)
|
Tiledbg::Tiledbg(std::string texturePath, SDL_Rect pos, int mode)
|
||||||
|
: texturePath(texturePath), pos(pos), mode(mode)
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
renderer = Screen::get()->getRenderer();
|
renderer = Screen::get()->getRenderer();
|
||||||
this->texturePath = texturePath;
|
|
||||||
this->pos = pos;
|
|
||||||
this->mode = mode;
|
|
||||||
|
|
||||||
// Crea la textura para el mosaico de fondo
|
// Crea la textura para el mosaico de fondo
|
||||||
canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, pos.w * 2, pos.h * 2);
|
canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, pos.w * 2, pos.h * 2);
|
||||||
|
|||||||
@@ -17,7 +17,8 @@
|
|||||||
struct JA_Music_t;
|
struct JA_Music_t;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Title::Title(JA_Music_t *music) : music(music)
|
Title::Title(JA_Music_t *music)
|
||||||
|
: music(music)
|
||||||
{
|
{
|
||||||
// Copia las direcciones de los punteros y objetos
|
// Copia las direcciones de los punteros y objetos
|
||||||
input = Input::get();
|
input = Input::get();
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#include "writer.h"
|
#include "writer.h"
|
||||||
#include "text.h" // for Text
|
#include "text.h" // for Text
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Writer::Writer(Text *text) : text(text)
|
Writer::Writer(Text *text)
|
||||||
|
: text(text)
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
posX = 0;
|
posX = 0;
|
||||||
@@ -25,7 +26,7 @@ void Writer::update()
|
|||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
if (!completed)
|
if (!completed)
|
||||||
{
|
{
|
||||||
// No completado
|
// No completado
|
||||||
if (writingCounter > 0)
|
if (writingCounter > 0)
|
||||||
{
|
{
|
||||||
@@ -45,7 +46,7 @@ void Writer::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Completado
|
// Completado
|
||||||
if (enabledCounter > 0)
|
if (enabledCounter > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user