diff --git a/linux_utils/cppcheck_run.sh b/linux_utils/cppcheck_run.sh index 606ed3d..59c8ec8 100644 --- a/linux_utils/cppcheck_run.sh +++ b/linux_utils/cppcheck_run.sh @@ -4,11 +4,17 @@ #cppcheck --force --enable=warning,style,performance --std=c++20 \ # --suppressions-list=/home/sergio/gitea/coffee_crisis_arcade_edition/linux-utils/cppcheck_suppressions \ # /home/sergio/gitea/coffee_crisis_arcade_edition/source/ \ -# 2>/home/sergio/cppcheck-result-warning-style-performance +# 2>/home/sergio/cppcheck-result-warning-style-performance.txt # all -cppcheck --force --enable=all -I /usr/include --std=c++20 \ ---suppress=missingIncludeSystem \ ---suppressions-list=/home/sergio/gitea/coffee_crisis_arcade_edition/linux-utils/cppcheck_suppressions \ -/home/sergio/gitea/coffee_crisis_arcade_edition/source/ \ -2>/home/sergio/cppcheck-result-all \ No newline at end of file +#cppcheck --force --enable=all -I /usr/include --std=c++20 \ +#--suppress=missingIncludeSystem \ +#--suppressions-list=/home/sergio/gitea/coffee_crisis_arcade_edition/linux-utils/cppcheck_suppressions \ +#/home/sergio/gitea/coffee_crisis_arcade_edition/source/ \ +#2>/home/sergio/cppcheck-result-all.txt + +# unusedFunction +cppcheck --enable=style --std=c++20 \ +--suppressions-list=./cppcheck_suppressions \ +../source/ \ +2>/home/sergio/cppcheck-result-all.txt \ No newline at end of file diff --git a/linux_utils/cppcheck_suppressions b/linux_utils/cppcheck_suppressions index 7dbaf91..55ab5a8 100644 --- a/linux_utils/cppcheck_suppressions +++ b/linux_utils/cppcheck_suppressions @@ -1,4 +1,8 @@ *:/home/sergio/gitea/coffee_crisis_arcade_edition/source/stb* *:/home/sergio/gitea/coffee_crisis_arcade_edition/source/gif.c *:/home/sergio/gitea/coffee_crisis_arcade_edition/source/jail* +*:/usr/include/* +*:../source/stb* +*:../source/gif.c +*:../source/jail* *:/usr/include/* \ No newline at end of file diff --git a/source/animated_sprite.cpp b/source/animated_sprite.cpp index e172259..9025906 100644 --- a/source/animated_sprite.cpp +++ b/source/animated_sprite.cpp @@ -106,42 +106,12 @@ void AnimatedSprite::animate() } } -// Establece la velocidad de una animación -void AnimatedSprite::setAnimationSpeed(int index, int speed) -{ - animations_[index].counter = speed; -} - -// Establece si la animación se reproduce en bucle -void AnimatedSprite::setAnimationLoop(int index, int loop) -{ - animations_[index].loop = loop; -} - -// OLD - Establece el valor de la variable -void AnimatedSprite::setAnimationCompleted(int index, bool value) -{ - animations_[index].completed = value; -} - // Comprueba si ha terminado la animación bool AnimatedSprite::animationIsCompleted() { return animations_[current_animation_].completed; } -// Devuelve el rectangulo de una animación y frame concreto -SDL_Rect AnimatedSprite::getAnimationClip(const std::string &name, Uint8 index) -{ - return animations_[getIndex(name)].frames[index]; -} - -// Devuelve el rectangulo de una animación y frame concreto -SDL_Rect AnimatedSprite::getAnimationClip(int indexA, Uint8 indexF) -{ - return animations_[indexA].frames[indexF]; -} - // Establece la animacion actual void AnimatedSprite::setCurrentAnimation(const std::string &name) { diff --git a/source/animated_sprite.h b/source/animated_sprite.h index 40c691b..bead0c0 100644 --- a/source/animated_sprite.h +++ b/source/animated_sprite.h @@ -52,24 +52,9 @@ public: // Actualiza las variables del objeto void update() override; - // Establece la velocidad de una animación - void setAnimationSpeed(int index, int speed); - - // Establece el frame al que vuelve la animación al finalizar - //void setAnimationLoop(const std::string &name, int loop); - void setAnimationLoop(int index, int loop); - - // Establece el valor de la variable - //void setAnimationCompleted(const std::string &name, bool value); - void setAnimationCompleted(int index, bool value); - // Comprueba si ha terminado la animación bool animationIsCompleted(); - // Devuelve el rectangulo de una animación y frame concreto - SDL_Rect getAnimationClip(const std::string &name = "default", Uint8 index = 0); - SDL_Rect getAnimationClip(int indexA = 0, Uint8 indexF = 0); - // Obtiene el indice de la animación a partir del nombre int getIndex(const std::string &name); diff --git a/source/background.cpp b/source/background.cpp index b088f00..fd10974 100644 --- a/source/background.cpp +++ b/source/background.cpp @@ -248,18 +248,6 @@ void Background::setPos(SDL_Rect pos) src_rect_.h = pos.h; } -// Ajusta el valor de la variable -void Background::setSrcRect(SDL_Rect value) -{ - src_rect_ = value; -} - -// Ajusta el valor de la variable -void Background::setDstRect(SDL_Rect value) -{ - dst_rect_ = value; -} - // Establece el color_ de atenuación void Background::setColor(Color color) { diff --git a/source/background.h b/source/background.h index d525b0f..d323b91 100644 --- a/source/background.h +++ b/source/background.h @@ -32,12 +32,6 @@ class Texture; - setTransition(float value) Porcentaje (entre 0.0f (textura actual) y 1.0f (textura siguiente)) para mostrar entre la textura de fondo actual y la siguiente - - setSrcRect(SDL_Rect value) - Rectangulo de la textura de fondo que se desea mostrar - - - setDstRecr(SDL_Rect value) - Rectangulo de destino donde se mostrará el rectángulo antrior. Automaticamente modifica srcRect para coincidor en tamaño con el destino. - - setColor(Color color) Establece el color de la textura de superposición @@ -133,12 +127,6 @@ public: // Ajusta el valor de la variable void setTransition(float value); - // Ajusta el valor de la variable - void setSrcRect(SDL_Rect value); - - // Ajusta el valor de la variable - void setDstRect(SDL_Rect value); - // Establece el color de atenuación void setColor(Color color); diff --git a/source/game.cpp b/source/game.cpp index 8536c10..6b4d8f3 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -1527,17 +1527,19 @@ void Game::initPaths() for (int i = 0; i < first_part; ++i) { - stage_bitmap_path_[i] = (sin[(int)((i * 1.8f) + 90)] * (distance) + center_point); + int index = static_cast((i * 1.8f) + 90) % 360; + stage_bitmap_path_[i] = sin[index] * distance + center_point; } for (int i = first_part; i < second_part; ++i) { - stage_bitmap_path_[i] = (int)center_point; + stage_bitmap_path_[i] = center_point; } for (int i = second_part; i < STAGE_COUNTER_; ++i) { - stage_bitmap_path_[i] = (sin[(int)(((i - 149) * 1.8f) + 90)] * (center_point + 17) - 17); + int index = static_cast(((i - 149) * 1.8f) + 90) % 360; + stage_bitmap_path_[i] = sin[index] * (center_point + 17) - 17; } // Letrero de GetReady diff --git a/source/game.h b/source/game.h index 59ca0e3..170a20b 100644 --- a/source/game.h +++ b/source/game.h @@ -171,7 +171,7 @@ private: float default_balloon_speed_; // Velocidad base de los enemigos, sin incrementar float difficulty_score_multiplier_; // Multiplicador de puntos en función de la dificultad float get_ready_bitmap_path_[STAGE_COUNTER_]; // Vector con los puntos X por donde se desplaza el texto - float stage_bitmap_path_[STAGE_COUNTER_]; // Vector con los puntos Y por donde se desplaza el texto + int stage_bitmap_path_[STAGE_COUNTER_]; // Vector con los puntos Y por donde se desplaza el texto int balloon_deploy_counter_ = 0; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero int balloons_popped_ = 0; // Lleva la cuenta de los globos explotados int counter_ = 0; // Contador para el juego diff --git a/source/moving_sprite.cpp b/source/moving_sprite.cpp index 2ad08c9..a171e4d 100644 --- a/source/moving_sprite.cpp +++ b/source/moving_sprite.cpp @@ -6,10 +6,6 @@ MovingSprite::MovingSprite(std::shared_ptr texture, SDL_Rect pos, Rotat : Sprite(texture, pos), x_(pos.x), y_(pos.y), - vx_(0.0f), - vy_(0.0f), - ax_(0.0f), - ay_(0.0f), rotate_(rotate), zoom_w_(zoom_w), zoom_h_(zoom_h), @@ -19,10 +15,6 @@ MovingSprite::MovingSprite(std::shared_ptr texture, SDL_Rect pos) : Sprite(texture, pos), x_(pos.x), y_(pos.y), - vx_(0.0f), - vy_(0.0f), - ax_(0.0f), - ay_(0.0f), rotate_(Rotate()), zoom_w_(1.0f), zoom_h_(1.0f), @@ -32,10 +24,6 @@ MovingSprite::MovingSprite(std::shared_ptr texture) : Sprite(texture), x_(0.0f), y_(0.0f), - vx_(0.0f), - vy_(0.0f), - ax_(0.0f), - ay_(0.0f), rotate_(Rotate()), zoom_w_(1.0f), zoom_h_(1.0f), @@ -89,24 +77,6 @@ void MovingSprite::render() texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_w_, zoom_h_, rotate_.angle, rotate_.center, flip_); } -// Obtiene el valor de la variable -float MovingSprite::getZoomW() const -{ - return zoom_w_; -} - -// Obtiene el valor de la variable -float MovingSprite::getZoomH() const -{ - return zoom_h_; -} - -// Obtiene el valor de la variable -double MovingSprite::getAngle() const -{ - return rotate_.angle; -} - // Establece el valor de la variable void MovingSprite::setZoomW(float value) { @@ -137,12 +107,6 @@ bool MovingSprite::isRotating() const return rotate_.enabled; } -// Obtiene el valor de la variable -int MovingSprite::getRotateSpeed() const -{ - return rotate_.speed; -} - // Establece la rotacion void MovingSprite::rotate() { diff --git a/source/moving_sprite.h b/source/moving_sprite.h index e73a5dc..2d8dde6 100644 --- a/source/moving_sprite.h +++ b/source/moving_sprite.h @@ -27,11 +27,11 @@ protected: float x_; // Posición en el eje X float y_; // Posición en el eje Y - float vx_; // Velocidad en el eje X. Cantidad de pixeles a desplazarse - float vy_; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse + float vx_ = 0.0f; // Velocidad en el eje X. Cantidad de pixeles a desplazarse + float vy_ = 0.0f; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse - float ax_; // Aceleración en el eje X. Variación de la velocidad - float ay_; // Aceleración en el eje Y. Variación de la velocidad + float ax_ = 0.0f; // Aceleración en el eje X. Variación de la velocidad + float ay_ = 0.0f; // Aceleración en el eje Y. Variación de la velocidad Rotate rotate_; // Variables usada para controlar la rotación del sprite float zoom_w_; // Zoom aplicado a la anchura @@ -79,14 +79,8 @@ public: void setAccelX(float value); void setAccelY(float value); - // Obten el valor de la variable - float getZoomW() const; - float getZoomH() const; - // Obten el valor de la variable bool isRotating() const; - double getAngle() const; - int getRotateSpeed() const; // Establece el valor de la variable void setZoomW(float value); diff --git a/source/notifier.cpp b/source/notifier.cpp index 5baa3e3..b523688 100644 --- a/source/notifier.cpp +++ b/source/notifier.cpp @@ -237,8 +237,6 @@ void Notifier::showText(std::string text1, std::string text2, int icon, const st n.code = code; n.y = offset; n.travel_dist = travel_dist; - n.counter = 0; - n.status = NotificationStatus::RISING; n.text1 = text1; n.text2 = text2; n.shape = shape; diff --git a/source/notifier.h b/source/notifier.h index c2daaa0..68d768e 100644 --- a/source/notifier.h +++ b/source/notifier.h @@ -25,18 +25,6 @@ private: FINISHED, }; - enum class NotificationPosition - { - UPPER_LEFT, - UPPER_CENTER, - UPPER_RIGHT, - MIDDLE_LEFT, - MIDDLE_RIGHT, - BOTTOM_LEFT, - BOTTOM_CENTER, - BOTTOM_RIGHT, - }; - enum class NotificationShape { ROUNDED, @@ -51,15 +39,16 @@ private: std::string text2; int counter; NotificationStatus status; - NotificationPosition position; NotificationShape shape; SDL_Rect rect; int y; int travel_dist; std::string code; // Permite asignar un código a la notificación - // Constructor vacío - Notification() = default; + // Constructor + explicit Notification() + : texture(nullptr), sprite(nullptr), text1(""), text2(""), counter(0), status(NotificationStatus::RISING), + shape(NotificationShape::SQUARED), rect{0, 0, 0, 0}, y(0), travel_dist(0), code("") {} }; // Objetos y punteros diff --git a/source/screen.h b/source/screen.h index c8a028c..63fe6e6 100644 --- a/source/screen.h +++ b/source/screen.h @@ -57,7 +57,7 @@ private: Color color; // Color del efecto // Constructor - FlashEffect(bool en = false, int cnt = 0, int len = 0, Color col = Color(0xFF, 0xFF, 0xFF)) + explicit FlashEffect(bool en = false, int cnt = 0, int len = 0, Color col = Color(0xFF, 0xFF, 0xFF)) : enabled(en), counter(cnt), lenght(len), color(col) {} }; @@ -73,7 +73,7 @@ private: bool enabled; // Indica si el efecto está activo // Constructor - ShakeEffect(bool en = false, int dp = 2, int dl = 3, int cnt = 0, int len = 8, int rem = 0, int origPos = 0, int origWidth = param.game.width) + explicit ShakeEffect(bool en = false, int dp = 2, int dl = 3, int cnt = 0, int len = 8, int rem = 0, int origPos = 0, int origWidth = param.game.width) : desp(dp), delay(dl), counter(cnt), lenght(len), remaining(rem), originalPos(origPos), originalWidth(origWidth), enabled(en) {} }; diff --git a/source/smart_sprite.cpp b/source/smart_sprite.cpp index 5030b0d..cd7f653 100644 --- a/source/smart_sprite.cpp +++ b/source/smart_sprite.cpp @@ -34,18 +34,6 @@ void SmartSprite::setDestY(int y) dest_y_ = y; } -// Obtiene el valor de la variable -int SmartSprite::getDestX() const -{ - return dest_x_; -} - -// Obtiene el valor de la variable -int SmartSprite::getDestY() const -{ - return dest_y_; -} - // Comprueba el movimiento void SmartSprite::checkMove() {