From bd3aa0bb0675b51254fe439003274f023aa1226f Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 8 Oct 2024 22:38:58 +0200 Subject: [PATCH] Arreglos varios al codi --- source/animated_sprite.cpp | 4 - source/asset.cpp | 6 -- source/asset.h | 2 +- source/background.cpp | 15 ++-- source/background.h | 1 - source/balloon.cpp | 51 ++++++------- source/balloon.h | 125 ++++++++++++++++---------------- source/define_buttons.cpp | 19 ++--- source/define_buttons.h | 2 +- source/enemy_formations.cpp | 21 ++---- source/enemy_formations.h | 4 +- source/explosions.cpp | 10 +-- source/explosions.h | 2 +- source/fade.cpp | 3 +- source/input.cpp | 27 +++---- source/input.h | 4 +- source/instructions.cpp | 3 +- source/intro.cpp | 3 +- source/item.cpp | 9 +-- source/manage_hiscore_table.cpp | 22 ++---- source/manage_hiscore_table.h | 2 +- source/moving_sprite.cpp | 5 +- source/scoreboard.cpp | 13 ++-- source/screen.cpp | 3 +- source/sprite.cpp | 12 +-- source/sprite.h | 2 +- source/texture.cpp | 6 +- source/tiled_bg.cpp | 16 ++-- source/title.cpp | 3 +- source/writer.cpp | 9 ++- 30 files changed, 177 insertions(+), 227 deletions(-) diff --git a/source/animated_sprite.cpp b/source/animated_sprite.cpp index 0e0d997..6658f03 100644 --- a/source/animated_sprite.cpp +++ b/source/animated_sprite.cpp @@ -195,10 +195,6 @@ AnimatedSprite::AnimatedSprite(animatedSprite_t *animation) // Destructor AnimatedSprite::~AnimatedSprite() { - for (auto &a : animation) - { - a.frames.clear(); - } animation.clear(); } diff --git a/source/asset.cpp b/source/asset.cpp index de3d60a..f9b0042 100644 --- a/source/asset.cpp +++ b/source/asset.cpp @@ -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) { diff --git a/source/asset.h b/source/asset.h index bc2e2e1..c2bfb21 100644 --- a/source/asset.h +++ b/source/asset.h @@ -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 diff --git a/source/background.cpp b/source/background.cpp index 32a7a28..063453d 100644 --- a/source/background.cpp +++ b/source/background.cpp @@ -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; diff --git a/source/background.h b/source/background.h index c1cf402..ff6df73 100644 --- a/source/background.h +++ b/source/background.h @@ -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 diff --git a/source/balloon.cpp b/source/balloon.cpp index 5696097..195dffa 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -9,7 +9,7 @@ // Constructor Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector *animation) { - sprite = new AnimatedSprite(texture, "", animation); + sprite = std::make_unique(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->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(); } \ No newline at end of file diff --git a/source/balloon.h b/source/balloon.h index a81ab6a..67d64c0 100644 --- a/source/balloon.h +++ b/source/balloon.h @@ -3,75 +3,76 @@ #include // for Uint8, Uint16, Uint32 #include // for string #include // for vector +#include #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 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 *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; }; \ No newline at end of file diff --git a/source/define_buttons.cpp b/source/define_buttons.cpp index 1a85975..26d6cb7 100644 --- a/source/define_buttons.cpp +++ b/source/define_buttons.cpp @@ -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() { diff --git a/source/define_buttons.h b/source/define_buttons.h index c02999e..0312481 100644 --- a/source/define_buttons.h +++ b/source/define_buttons.h @@ -48,7 +48,7 @@ public: DefineButtons(Text *text); // Destructor - ~DefineButtons(); + ~DefineButtons() = default; // Actualiza las variables del objeto void update(); diff --git a/source/enemy_formations.cpp b/source/enemy_formations.cpp index 052f104..bd71709 100644 --- a/source/enemy_formations.cpp +++ b/source/enemy_formations.cpp @@ -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]; } \ No newline at end of file diff --git a/source/enemy_formations.h b/source/enemy_formations.h index bbbff60..704ae6a 100644 --- a/source/enemy_formations.h +++ b/source/enemy_formations.h @@ -56,8 +56,8 @@ public: EnemyFormations(); // Destructor - ~EnemyFormations(); + ~EnemyFormations() = default; // Devuelve una fase - stage_t getStage(int index); + stage_t getStage(int index) const; }; \ No newline at end of file diff --git a/source/explosions.cpp b/source/explosions.cpp index c70f826..a66ad9d 100644 --- a/source/explosions.cpp +++ b/source/explosions.cpp @@ -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 *animation) { explosion_texture_t temp; diff --git a/source/explosions.h b/source/explosions.h index ad843ff..46fc8cb 100644 --- a/source/explosions.h +++ b/source/explosions.h @@ -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 *animation); // Añade una explosión diff --git a/source/fade.cpp b/source/fade.cpp index 46bad2a..a1eef3e 100644 --- a/source/fade.cpp +++ b/source/fade.cpp @@ -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); diff --git a/source/input.cpp b/source/input.cpp index e723da9..7f0d5c5 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -1,41 +1,39 @@ #include "input.h" -#include // for SDL_INIT_GAMECONTROLLER, SDL_InitSubS... -#include // for SDL_GetError -#include // for SDL_ENABLE -#include // for SDL_GetKeyboardState -#include // for basic_ostream, operator<<, cout, basi... +#include // for SDL_INIT_GAMECONTROLLER, SDL_InitSubS... +#include // for SDL_GetError +#include // for SDL_ENABLE +#include // for SDL_GetKeyboardState +#include // 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); diff --git a/source/input.h b/source/input.h index d2d64bf..bb64189 100644 --- a/source/input.h +++ b/source/input.h @@ -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(); diff --git a/source/instructions.cpp b/source/instructions.cpp index 4970bfb..8e4bfac 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -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(); diff --git a/source/intro.cpp b/source/intro.cpp index 0490781..967ed99 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -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(); diff --git a/source/item.cpp b/source/item.cpp index e1d0386..ea5be7a 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -1,16 +1,15 @@ #include "item.h" -#include // for rand -#include "animated_sprite.h" // for AnimatedSprite -#include "param.h" // for param +#include // 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 *animation) + : kind(kind), playArea(playArea) { sprite = new AnimatedSprite(texture, "", animation); - this->kind = kind; - this->playArea = playArea; enabled = true; timeToLive = 600; accelX = 0.0f; diff --git a/source/manage_hiscore_table.cpp b/source/manage_hiscore_table.cpp index 5f3070c..00088bf 100644 --- a/source/manage_hiscore_table.cpp +++ b/source/manage_hiscore_table.cpp @@ -1,21 +1,15 @@ #include "manage_hiscore_table.h" -#include // for SDL_GetError -#include // for SDL_RWread, SDL_RWwrite, SDL_RWFromFile -#include // for free, malloc -#include // for sort -#include // for basic_ostream, char_traits, operator<< -#include "utils.h" // for hiScoreEntry_t +#include // for SDL_GetError +#include // for SDL_RWread, SDL_RWwrite, SDL_RWFromFile +#include // for free, malloc +#include // for sort +#include // for basic_ostream, char_traits, operator<< +#include "utils.h" // for hiScoreEntry_t // Constructor ManageHiScoreTable::ManageHiScoreTable(std::vector *table) -{ - this->table = table; -} + : table(table) {} -// Destructor -ManageHiScoreTable::~ManageHiScoreTable() -{ -} // Resetea la tabla a los valores por defecto void ManageHiScoreTable::clear() @@ -67,7 +61,7 @@ void ManageHiScoreTable::sort() bool ManageHiScoreTable::loadFromFile(std::string filePath) { clear(); - + bool success = true; const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1); SDL_RWops *file = SDL_RWFromFile(filePath.c_str(), "r+b"); diff --git a/source/manage_hiscore_table.h b/source/manage_hiscore_table.h index bc778cc..b365268 100644 --- a/source/manage_hiscore_table.h +++ b/source/manage_hiscore_table.h @@ -27,7 +27,7 @@ public: ManageHiScoreTable(std::vector *table); // Destructor - ~ManageHiScoreTable(); + ~ManageHiScoreTable() = default; // Resetea la tabla a los valores por defecto void clear(); diff --git a/source/moving_sprite.cpp b/source/moving_sprite.cpp index a838598..43438e5 100644 --- a/source/moving_sprite.cpp +++ b/source/moving_sprite.cpp @@ -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; diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index cf31388..2f52637 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -5,11 +5,11 @@ #include // for roundf #include #include -#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; diff --git a/source/screen.cpp b/source/screen.cpp index a327217..efbd726 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -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(); diff --git a/source/sprite.cpp b/source/sprite.cpp index 9f79a7c..b17d700 100644 --- a/source/sprite.cpp +++ b/source/sprite.cpp @@ -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() { diff --git a/source/sprite.h b/source/sprite.h index 4a5f036..a36db38 100644 --- a/source/sprite.h +++ b/source/sprite.h @@ -23,7 +23,7 @@ public: Sprite(SDL_Rect rect, Texture *texture = nullptr); // Destructor - ~Sprite(); + ~Sprite() = default; // Muestra el sprite por pantalla void render(); diff --git a/source/texture.cpp b/source/texture.cpp index 0204bae..f836268 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -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(); } diff --git a/source/tiled_bg.cpp b/source/tiled_bg.cpp index 1e1d853..1c8a3de 100644 --- a/source/tiled_bg.cpp +++ b/source/tiled_bg.cpp @@ -1,19 +1,17 @@ #include "tiled_bg.h" -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for SDL_sinf -#include // for rand -#include "screen.h" // for Screen -#include "sprite.h" // for Sprite -#include "texture.h" // for Texture +#include // for SDL_PIXELFORMAT_RGBA8888 +#include // for SDL_sinf +#include // 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); diff --git a/source/title.cpp b/source/title.cpp index 653a389..e2eca2e 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -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(); diff --git a/source/writer.cpp b/source/writer.cpp index ffbd81c..eda8491 100644 --- a/source/writer.cpp +++ b/source/writer.cpp @@ -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; @@ -25,7 +26,7 @@ void Writer::update() if (enabled) { if (!completed) - { + { // No completado if (writingCounter > 0) { @@ -45,7 +46,7 @@ void Writer::update() } else - { + { // Completado if (enabledCounter > 0) {