Arreglos varios al codi

This commit is contained in:
2024-10-08 22:38:58 +02:00
parent 3e3d764b25
commit bd3aa0bb06
30 changed files with 177 additions and 227 deletions

View File

@@ -195,10 +195,6 @@ AnimatedSprite::AnimatedSprite(animatedSprite_t *animation)
// Destructor
AnimatedSprite::~AnimatedSprite()
{
for (auto &a : animation)
{
a.frames.clear();
}
animation.clear();
}

View File

@@ -37,12 +37,6 @@ Asset::Asset(std::string executablePath)
#endif
}
// Destructor
Asset::~Asset()
{
}
// Añade un elemento a la lista
void Asset::add(std::string file, enum assetType type, bool required, bool absolute)
{

View File

@@ -49,7 +49,7 @@ private:
Asset(std::string path);
// Destructor
~Asset();
~Asset() = default;
public:
// [SINGLETON] Crearemos el objeto screen con esta función estática

View File

@@ -11,17 +11,14 @@
// Constructor
Background::Background(SDL_Renderer *renderer)
: renderer(renderer)
{
// Copia los punteros
this->renderer = renderer;
asset = Asset::get();
// Carga las texturas
buildingsTexture = new Texture(renderer, asset->get("game_buildings.png"));
topCloudsTexture = new Texture(renderer, asset->get("game_clouds1.png"));
bottomCloudsTexture = new Texture(renderer, asset->get("game_clouds2.png"));
grassTexture = new Texture(renderer, asset->get("game_grass.png"));
gradientsTexture = new Texture(renderer, asset->get("game_sky_colors.png"));
buildingsTexture = new Texture(renderer, Asset::get()->get("game_buildings.png"));
topCloudsTexture = new Texture(renderer, Asset::get()->get("game_clouds1.png"));
bottomCloudsTexture = new Texture(renderer, Asset::get()->get("game_clouds2.png"));
grassTexture = new Texture(renderer, Asset::get()->get("game_grass.png"));
gradientsTexture = new Texture(renderer, Asset::get()->get("game_sky_colors.png"));
// Inicializa variables
gradientNumber = 0;

View File

@@ -51,7 +51,6 @@ class Background
private:
// Objetos y punteros
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 *topCloudsTexture; // Textura con las nubes de fondo

View File

@@ -9,7 +9,7 @@
// Constructor
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();
enabled = true;
@@ -274,12 +274,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
this->kind = kind;
}
// Destructor
Balloon::~Balloon()
{
delete sprite;
}
// Centra el globo en la posición X
void Balloon::allignTo(int x)
{
@@ -333,10 +327,9 @@ void Balloon::render()
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->render();
delete sp;
}
}
}
@@ -601,37 +594,37 @@ void Balloon::updateAnimation()
}
// Comprueba si el globo está habilitado
bool Balloon::isEnabled()
bool Balloon::isEnabled() const
{
return enabled;
}
// Obtiene del valor de la variable
float Balloon::getPosX()
float Balloon::getPosX() const
{
return posX;
}
// Obtiene del valor de la variable
float Balloon::getPosY()
float Balloon::getPosY() const
{
return posY;
}
// Obtiene del valor de la variable
float Balloon::getVelY()
float Balloon::getVelY() const
{
return velY;
}
// Obtiene del valor de la variable
int Balloon::getWidth()
int Balloon::getWidth() const
{
return width;
}
// Obtiene del valor de la variable
int Balloon::getHeight()
int Balloon::getHeight() const
{
return height;
}
@@ -649,19 +642,19 @@ void Balloon::setSpeed(float speed)
}
// Obtiene del valor de la variable
int Balloon::getKind()
int Balloon::getKind() const
{
return kind;
}
// Obtiene del valor de la variable
Uint8 Balloon::getSize()
Uint8 Balloon::getSize() const
{
return size;
}
// Obtiene la clase a la que pertenece el globo
Uint8 Balloon::getClass()
Uint8 Balloon::getClass() const
{
if ((kind >= BALLOON_1) && (kind <= BALLOON_4))
{
@@ -683,7 +676,7 @@ void Balloon::setStop(bool state)
}
// Obtiene del valor de la variable
bool Balloon::isStopped()
bool Balloon::isStopped() const
{
return stopped;
}
@@ -695,7 +688,7 @@ void Balloon::setBlink(bool value)
}
// Obtiene del valor de la variable
bool Balloon::isBlinking()
bool Balloon::isBlinking() const
{
return blinking;
}
@@ -707,7 +700,7 @@ void Balloon::setVisible(bool value)
}
// Obtiene del valor de la variable
bool Balloon::isVisible()
bool Balloon::isVisible() const
{
return visible;
}
@@ -719,7 +712,7 @@ void Balloon::setInvulnerable(bool value)
}
// Obtiene del valor de la variable
bool Balloon::isInvulnerable()
bool Balloon::isInvulnerable() const
{
return invulnerable;
}
@@ -731,7 +724,7 @@ void Balloon::setBeingCreated(bool value)
}
// Obtiene del valor de la variable
bool Balloon::isBeingCreated()
bool Balloon::isBeingCreated() const
{
return beingCreated;
}
@@ -743,13 +736,13 @@ void Balloon::setStoppedTimer(Uint16 time)
}
// Obtiene del valor de la variable
Uint16 Balloon::getStoppedTimer()
Uint16 Balloon::getStoppedTimer() const
{
return stoppedCounter;
}
// Obtiene del valor de la variable
Uint16 Balloon::getScore()
Uint16 Balloon::getScore() const
{
return score;
}
@@ -768,7 +761,7 @@ void Balloon::updateColliders()
}
// Obtiene le valor de la variable
Uint8 Balloon::getMenace()
Uint8 Balloon::getMenace() const
{
if (isEnabled())
{
@@ -781,7 +774,7 @@ Uint8 Balloon::getMenace()
}
// Obtiene le valor de la variable
Uint8 Balloon::getPower()
Uint8 Balloon::getPower() const
{
return power;
}
@@ -828,13 +821,13 @@ void Balloon::updateBounce()
}
// Indica si el globo se puede explotar
bool Balloon::canBePopped()
bool Balloon::canBePopped() const
{
return isEnabled() && !isBeingCreated();
}
// Indica si el globo se puede destruir
bool Balloon::canBeDestroyed()
bool Balloon::canBeDestroyed() const
{
return isEnabled();
}

View File

@@ -3,75 +3,76 @@
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint16, Uint32
#include <string> // for string
#include <vector> // for vector
#include <memory>
#include "utils.h" // for circle_t
class AnimatedSprite;
#include "animated_sprite.h"
class Texture;
// 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
#define BALLOON_1 1
#define BALLOON_2 2
#define BALLOON_3 3
#define BALLOON_4 4
#define HEXAGON_1 5
#define HEXAGON_2 6
#define HEXAGON_3 7
#define HEXAGON_4 8
#define POWER_BALL 9
constexpr int BALLOON_1 = 1;
constexpr int BALLOON_2 = 2;
constexpr int BALLOON_3 = 3;
constexpr int BALLOON_4 = 4;
constexpr int HEXAGON_1 = 5;
constexpr int HEXAGON_2 = 6;
constexpr int HEXAGON_3 = 7;
constexpr int HEXAGON_4 = 8;
constexpr int POWER_BALL = 9;
// Puntos de globo
#define BALLOON_SCORE_1 50
#define BALLOON_SCORE_2 100
#define BALLOON_SCORE_3 200
#define BALLOON_SCORE_4 400
constexpr int BALLOON_SCORE_1 = 50;
constexpr int BALLOON_SCORE_2 = 100;
constexpr int BALLOON_SCORE_3 = 200;
constexpr int BALLOON_SCORE_4 = 400;
// Tamaños de globo
#define BALLOON_SIZE_1 1
#define BALLOON_SIZE_2 2
#define BALLOON_SIZE_3 3
#define BALLOON_SIZE_4 4
constexpr int BALLOON_SIZE_1 = 1;
constexpr int BALLOON_SIZE_2 = 2;
constexpr int BALLOON_SIZE_3 = 3;
constexpr int BALLOON_SIZE_4 = 4;
// Clases de globo
#define BALLOON_CLASS 0
#define HEXAGON_CLASS 1
constexpr int BALLOON_CLASS = 0;
constexpr int HEXAGON_CLASS = 1;
// Velocidad del globo
#define BALLOON_VELX_POSITIVE 0.7f
#define BALLOON_VELX_NEGATIVE -0.7f
constexpr float BALLOON_VELX_POSITIVE = 0.7f;
constexpr float BALLOON_VELX_NEGATIVE = -0.7f;
// Indice para las animaciones de los globos
#define BALLOON_MOVING_ANIMATION 0
#define BALLOON_POP_ANIMATION 1
#define BALLOON_BORN_ANIMATION 2
constexpr int BALLOON_MOVING_ANIMATION = 0;
constexpr int BALLOON_POP_ANIMATION = 1;
constexpr int BALLOON_BORN_ANIMATION = 2;
// Cantidad posible de globos
#define MAX_BALLOONS 100
constexpr int MAX_BALLOONS = 100;
// Velocidades a las que se mueven los globos
#define BALLOON_SPEED_1 0.60f
#define BALLOON_SPEED_2 0.70f
#define BALLOON_SPEED_3 0.80f
#define BALLOON_SPEED_4 0.90f
#define BALLOON_SPEED_5 1.00f
constexpr float BALLOON_SPEED_1 = 0.60f;
constexpr float BALLOON_SPEED_2 = 0.70f;
constexpr float BALLOON_SPEED_3 = 0.80f;
constexpr float BALLOON_SPEED_4 = 0.90f;
constexpr float BALLOON_SPEED_5 = 1.00f;
// Tamaño de los globos
#define BALLOON_WIDTH_1 10
#define BALLOON_WIDTH_2 16
#define BALLOON_WIDTH_3 26
#define BALLOON_WIDTH_4 46
constexpr int BALLOON_WIDTH_1 = 10;
constexpr int BALLOON_WIDTH_2 = 16;
constexpr int BALLOON_WIDTH_3 = 26;
constexpr int BALLOON_WIDTH_4 = 46;
// PowerBall
#define POWERBALL_SCREENPOWER_MINIMUM 10
#define POWERBALL_COUNTER 8
constexpr int POWERBALL_SCREENPOWER_MINIMUM = 10;
constexpr int POWERBALL_COUNTER = 8;
// Clase Balloon
class Balloon
{
private:
// Estructura para las variables para el efecto de los rebotes
struct bouncing
struct Bouncing
{
bool enabled; // Si el efecto está activo
Uint8 counter; // Countador para el efecto
@@ -85,7 +86,7 @@ private:
};
// Objetos y punteros
AnimatedSprite *sprite; // Sprite del objeto globo
std::unique_ptr<AnimatedSprite> sprite; // Sprite del objeto globo
// Variables
float posX; // Posición en el eje X
@@ -115,7 +116,7 @@ private:
float speed; // Velocidad a la que se mueven los globos
Uint8 size; // Tamaño del 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
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);
// Destructor
~Balloon();
~Balloon() = default;
// Centra el globo en la posición X
void allignTo(int x);
@@ -164,22 +165,22 @@ public:
void update();
// Comprueba si el globo está habilitado
bool isEnabled();
bool isEnabled() const;
// Obtiene del valor de la variable
float getPosX();
float getPosX() const;
// Obtiene del valor de la variable
float getPosY();
float getPosY() const;
// Obtiene del valor de la variable
float getVelY();
float getVelY() const;
// Obtiene del valor de la variable
int getWidth();
int getWidth() const;
// Obtiene del valor de la variable
int getHeight();
int getHeight() const;
// Establece el valor de la variable
void setVelY(float velY);
@@ -188,62 +189,62 @@ public:
void setSpeed(float speed);
// Obtiene del valor de la variable
int getKind();
int getKind() const;
// Obtiene del valor de la variable
Uint8 getSize();
Uint8 getSize() const;
// Obtiene la clase a la que pertenece el globo
Uint8 getClass();
Uint8 getClass() const;
// Establece el valor de la variable
void setStop(bool value);
// Obtiene del valor de la variable
bool isStopped();
bool isStopped() const;
// Establece el valor de la variable
void setBlink(bool value);
// Obtiene del valor de la variable
bool isBlinking();
bool isBlinking() const;
// Establece el valor de la variable
void setVisible(bool value);
// Obtiene del valor de la variable
bool isVisible();
bool isVisible() const;
// Establece el valor de la variable
void setInvulnerable(bool value);
// Obtiene del valor de la variable
bool isInvulnerable();
bool isInvulnerable() const;
// Obtiene del valor de la variable
bool isBeingCreated();
bool isBeingCreated() const;
// Establece el valor de la variable
void setStoppedTimer(Uint16 time);
// Obtiene del valor de la variable
Uint16 getStoppedTimer();
Uint16 getStoppedTimer() const;
// Obtiene del valor de la variable
Uint16 getScore();
Uint16 getScore() const;
// Obtiene el circulo de colisión
circle_t &getCollider();
// Obtiene le valor de la variable
Uint8 getMenace();
Uint8 getMenace() const;
// Obtiene le valor de la variable
Uint8 getPower();
Uint8 getPower() const;
// Indica si el globo se puede explotar
bool canBePopped();
bool canBePopped() const;
// Indica si el globo se puede destruir
bool canBeDestroyed();
bool canBeDestroyed() const;
};

View File

@@ -1,17 +1,17 @@
#include "define_buttons.h"
#include "lang.h" // for getText
#include "options.h" // for options
#include "param.h" // for param
#include "section.h" // for name, name_e, options, options_e
#include "text.h" // for Text
#include "utils.h" // for op_controller_t, options_t, param_t, paramGame_t
#include "lang.h" // for getText
#include "options.h" // for options
#include "param.h" // for param
#include "section.h" // for name, name_e, options, options_e
#include "text.h" // for Text
#include "utils.h" // for op_controller_t, options_t, param_t, paramGame_t
// Constructor
DefineButtons::DefineButtons(Text *text)
: text(text)
{
// Copia punteros a los objetos
input = Input::get();
this->text = text;
// Inicializa variables
enabled = false;
@@ -54,11 +54,6 @@ DefineButtons::DefineButtons(Text *text)
}
}
// Destructor
DefineButtons::~DefineButtons()
{
}
// Actualiza las variables del objeto
void DefineButtons::update()
{

View File

@@ -48,7 +48,7 @@ public:
DefineButtons(Text *text);
// Destructor
~DefineButtons();
~DefineButtons() = default;
// Actualiza las variables del objeto
void update();

View File

@@ -1,7 +1,7 @@
#include "enemy_formations.h"
#include "balloon.h" // for BALLOON_VELX_NEGATIVE, BALLOON_VELX_POSITIVE
#include "param.h" // for param
#include "utils.h" // for paramGame_t, param_t, zone_t, BLOCK
#include "balloon.h" // for BALLOON_VELX_NEGATIVE, BALLOON_VELX_POSITIVE
#include "param.h" // for param
#include "utils.h" // for paramGame_t, param_t, zone_t, BLOCK
// Constructor
EnemyFormations::EnemyFormations()
@@ -11,27 +11,22 @@ EnemyFormations::EnemyFormations()
initGameStages();
}
// Destructor
EnemyFormations::~EnemyFormations()
{
}
// Inicializa las formaciones enemigas
void EnemyFormations::initEnemyFormations()
{
const int y4 = - BLOCK;
const int y4 = -BLOCK;
const int x4_0 = param.game.playArea.rect.x;
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_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_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_50 = param.game.playArea.centerX - (BALLOON_WIDTH_1 / 2);
const int x1_100 = param.game.playArea.rect.w - BALLOON_WIDTH_1;
@@ -719,7 +714,7 @@ void EnemyFormations::initGameStages()
}
// Devuelve una fase
stage_t EnemyFormations::getStage(int index)
stage_t EnemyFormations::getStage(int index) const
{
return stage[index];
}

View File

@@ -56,8 +56,8 @@ public:
EnemyFormations();
// Destructor
~EnemyFormations();
~EnemyFormations() = default;
// Devuelve una fase
stage_t getStage(int index);
stage_t getStage(int index) const;
};

View File

@@ -12,13 +12,7 @@ Explosions::Explosions()
// Destructor
Explosions::~Explosions()
{
for (auto explosion : explosions)
{
if (explosion)
{
delete explosion;
}
}
explosions.clear();
}
// 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)
{
explosion_texture_t temp;

View File

@@ -39,7 +39,7 @@ public:
// Dibuja el objeto en pantalla
void render();
// Añade texturas al objetp
// Añade texturas al objeto
void addTexture(int size, Texture *texture, std::vector<std::string> *animation);
// Añade una explosión

View File

@@ -7,7 +7,8 @@
#include "utils.h" // for param_t, paramGame_t, paramFade_t
// Constructor
Fade::Fade(SDL_Renderer *renderer) : renderer(renderer)
Fade::Fade(SDL_Renderer *renderer)
: renderer(renderer)
{
// Crea la textura donde dibujar el fade
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);

View File

@@ -1,41 +1,39 @@
#include "input.h"
#include <SDL2/SDL.h> // for SDL_INIT_GAMECONTROLLER, SDL_InitSubS...
#include <SDL2/SDL_error.h> // for SDL_GetError
#include <SDL2/SDL_events.h> // for SDL_ENABLE
#include <SDL2/SDL_keyboard.h> // for SDL_GetKeyboardState
#include <iostream> // for basic_ostream, operator<<, cout, basi...
#include <SDL2/SDL.h> // for SDL_INIT_GAMECONTROLLER, SDL_InitSubS...
#include <SDL2/SDL_error.h> // for SDL_GetError
#include <SDL2/SDL_events.h> // for SDL_ENABLE
#include <SDL2/SDL_keyboard.h> // for SDL_GetKeyboardState
#include <iostream> // for basic_ostream, operator<<, cout, basi...
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
Input *Input::input = nullptr;
// [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
void Input::destroy()
{
delete Input::input;
delete Input::input;
}
// [SINGLETON] Con este método obtenemos el objeto input y podemos trabajar con él
Input *Input::get()
{
return Input::input;
return Input::input;
}
// Constructor
Input::Input(std::string file)
Input::Input(std::string dbPath)
: dbPath(dbPath)
{
// Inicializa variables
verbose = false;
enabled = true;
// Fichero gamecontrollerdb.txt
dbPath = file;
// Busca si hay mandos conectados
discoverGameControllers();
@@ -75,7 +73,6 @@ Input::Input(std::string file)
// Destructor
Input::~Input()
{
}
// 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))
{
successGameController = checkAxisInput(input, index);

View File

@@ -100,14 +100,14 @@ private:
bool checkAxisInput(inputs_e input, int index = 0) const;
// Constructor
Input(std::string file);
Input(std::string dbPath);
// Destructor
~Input();
public:
// [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
static void destroy();

View File

@@ -22,7 +22,8 @@
struct JA_Music_t;
// Constructor
Instructions::Instructions(JA_Music_t *music) : music(music)
Instructions::Instructions(JA_Music_t *music)
: music(music)
{
// Copia los punteros
renderer = Screen::get()->getRenderer();

View File

@@ -19,7 +19,8 @@
struct JA_Music_t;
// Constructor
Intro::Intro(JA_Music_t *music) : music(music)
Intro::Intro(JA_Music_t *music)
: music(music)
{
// Copia los punteros
SDL_Renderer *renderer = Screen::get()->getRenderer();

View File

@@ -1,16 +1,15 @@
#include "item.h"
#include <stdlib.h> // for rand
#include "animated_sprite.h" // for AnimatedSprite
#include "param.h" // for param
#include <stdlib.h> // for rand
#include "animated_sprite.h" // for AnimatedSprite
#include "param.h" // for param
class Texture;
// Constructor
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);
this->kind = kind;
this->playArea = playArea;
enabled = true;
timeToLive = 600;
accelX = 0.0f;

View File

@@ -1,21 +1,15 @@
#include "manage_hiscore_table.h"
#include <SDL2/SDL_error.h> // for SDL_GetError
#include <SDL2/SDL_rwops.h> // for SDL_RWread, SDL_RWwrite, SDL_RWFromFile
#include <stdlib.h> // for free, malloc
#include <algorithm> // for sort
#include <iostream> // for basic_ostream, char_traits, operator<<
#include "utils.h" // for hiScoreEntry_t
#include <SDL2/SDL_error.h> // for SDL_GetError
#include <SDL2/SDL_rwops.h> // for SDL_RWread, SDL_RWwrite, SDL_RWFromFile
#include <stdlib.h> // for free, malloc
#include <algorithm> // for sort
#include <iostream> // for basic_ostream, char_traits, operator<<
#include "utils.h" // for hiScoreEntry_t
// Constructor
ManageHiScoreTable::ManageHiScoreTable(std::vector<hiScoreEntry_t> *table)
{
this->table = table;
}
: table(table) {}
// Destructor
ManageHiScoreTable::~ManageHiScoreTable()
{
}
// Resetea la tabla a los valores por defecto
void ManageHiScoreTable::clear()

View File

@@ -27,7 +27,7 @@ public:
ManageHiScoreTable(std::vector<hiScoreEntry_t> *table);
// Destructor
~ManageHiScoreTable();
~ManageHiScoreTable() = default;
// Resetea la tabla a los valores por defecto
void clear();

View File

@@ -1,8 +1,9 @@
#include "moving_sprite.h"
#include "texture.h" // for Texture
#include "texture.h" // for Texture
// Constructor
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
this->texture = texture;
@@ -12,8 +13,6 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vel
this->h = h;
// Establece la posición X,Y del sprite
this->x = x;
this->y = y;
xPrev = x;
yPrev = y;

View File

@@ -5,11 +5,11 @@
#include <math.h> // for roundf
#include <iomanip>
#include <sstream>
#include "asset.h" // for Asset
#include "lang.h" // for getText
#include "sprite.h" // for Sprite
#include "text.h" // for Text
#include "texture.h" // for Texture
#include "asset.h" // for Asset
#include "lang.h" // for getText
#include "sprite.h" // for Sprite
#include "text.h" // for Text
#include "texture.h" // for Texture
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
Scoreboard *Scoreboard::scoreboard = nullptr;
@@ -33,7 +33,8 @@ Scoreboard *Scoreboard::get()
}
// Constructor
Scoreboard::Scoreboard(SDL_Renderer *renderer) : renderer(renderer)
Scoreboard::Scoreboard(SDL_Renderer *renderer)
: renderer(renderer)
{
// Inicializa punteros
gamePowerMeterTexture = nullptr;

View File

@@ -43,7 +43,8 @@ Screen *Screen::get()
}
// 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
input = Input::get();

View File

@@ -2,7 +2,8 @@
#include "texture.h" // for Texture
// 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
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;
}
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
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;
}
// Destructor
Sprite::~Sprite()
{
texture = nullptr;
}
// Muestra el sprite por pantalla
void Sprite::render()
{

View File

@@ -23,7 +23,7 @@ public:
Sprite(SDL_Rect rect, Texture *texture = nullptr);
// Destructor
~Sprite();
~Sprite() = default;
// Muestra el sprite por pantalla
void render();

View File

@@ -12,11 +12,8 @@
// Constructor
Texture::Texture(SDL_Renderer *renderer, std::string path)
: renderer(renderer), path(path)
{
// Copia punteros
this->renderer = renderer;
this->path = path;
// Inicializa
surface = nullptr;
texture = nullptr;
@@ -53,7 +50,6 @@ Texture::Texture(SDL_Renderer *renderer, std::string path)
// Destructor
Texture::~Texture()
{
// Libera memoria
unload();
}

View File

@@ -1,19 +1,17 @@
#include "tiled_bg.h"
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_stdinc.h> // for SDL_sinf
#include <stdlib.h> // for rand
#include "screen.h" // for Screen
#include "sprite.h" // for Sprite
#include "texture.h" // for Texture
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_stdinc.h> // for SDL_sinf
#include <stdlib.h> // for rand
#include "screen.h" // for Screen
#include "sprite.h" // for Sprite
#include "texture.h" // for Texture
// Constructor
Tiledbg::Tiledbg(std::string texturePath, SDL_Rect pos, int mode)
: texturePath(texturePath), pos(pos), mode(mode)
{
// Copia los punteros
renderer = Screen::get()->getRenderer();
this->texturePath = texturePath;
this->pos = pos;
this->mode = mode;
// Crea la textura para el mosaico de fondo
canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, pos.w * 2, pos.h * 2);

View File

@@ -17,7 +17,8 @@
struct JA_Music_t;
// 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
input = Input::get();

View File

@@ -1,8 +1,9 @@
#include "writer.h"
#include "text.h" // for Text
#include "text.h" // for Text
// Constructor
Writer::Writer(Text *text) : text(text)
Writer::Writer(Text *text)
: text(text)
{
// Inicializa variables
posX = 0;