diff --git a/source/animated_sprite.h b/source/animated_sprite.h index e2cc6f5..0cd3279 100644 --- a/source/animated_sprite.h +++ b/source/animated_sprite.h @@ -46,7 +46,7 @@ public: : MovingSprite(texture) {} // Destructor - virtual ~AnimatedSprite() = default; + virtual ~AnimatedSprite() override = default; // Actualiza las variables del objeto void update() override; diff --git a/source/balloon.cpp b/source/balloon.cpp index 6bf5b53..870a20b 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -118,7 +118,7 @@ void Balloon::render() if (!invulnerable_) { SDL_Point p = {24, 24}; - sprite_->setRotatingCenter(&p); + sprite_->setRotatingCenter(p); sprite_->render(); } diff --git a/source/enter_name.cpp b/source/enter_name.cpp index a293afa..69e9738 100644 --- a/source/enter_name.cpp +++ b/source/enter_name.cpp @@ -4,7 +4,8 @@ // Constructor EnterName::EnterName() - : character_list_(" ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+-*/=?¿<>!\"#$%&/()") {} + : character_list_(" ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+-*/=?¿<>!\"#$%&/()"), + character_index_{0} {} // Inicializa el objeto void EnterName::init(const std::string &name) @@ -44,23 +45,21 @@ void EnterName::incPosition() position_ = MAX_NAME_LENGHT; // Mantenemos en el índice máximo válido. position_overflow_ = true; // Activamos el flag de overflow. } - else + else if (position_ > 0) // No es necesario verificar position_ < MAX_NAME_LENGHT { // Copiamos el índice del carácter anterior si es posible. - if (position_ > 0 && position_ < MAX_NAME_LENGHT) - { - character_index_[position_] = character_index_[position_ - 1]; - } - else - { - // Si position_ es 0, inicializamos el carácter actual. - character_index_[position_] = 0; - } + character_index_[position_] = character_index_[position_ - 1]; + } + else + { + // Si position_ es 0, inicializamos el carácter actual. + character_index_[position_] = 0; } updateNameFromCharacterIndex(); } + // Decrementa la posición void EnterName::decPosition() { diff --git a/source/enter_name.h b/source/enter_name.h index 1ae2435..ac48daa 100644 --- a/source/enter_name.h +++ b/source/enter_name.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "utils.h" constexpr int MAX_NAME_LENGHT = 6; @@ -17,11 +18,11 @@ constexpr int MAX_NAME_LENGHT = 6; class EnterName { private: - std::string character_list_; // Lista de todos los caracteres permitidos - std::string name_; // Nombre introducido - int position_ = 0; // Posición a editar del nombre - bool position_overflow_ = false; // Indica si hemos incrementado la posición más allá del límite - int character_index_[MAX_NAME_LENGHT]; // Indice de la lista para cada uno de los caracteres que forman el nombre + std::string character_list_; // Lista de todos los caracteres permitidos + std::string name_; // Nombre introducido + int position_ = 0; // Posición a editar del nombre + bool position_overflow_ = false; // Indica si hemos incrementado la posición más allá del límite + std::array character_index_; // Indice de la lista para cada uno de los caracteres que forman el nombre // Actualiza el nombre a partir de la lista de índices void updateNameFromCharacterIndex(); diff --git a/source/game.cpp b/source/game.cpp index f359e9b..97f7f0e 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -2023,7 +2023,6 @@ void Game::checkDebugEvents(const SDL_Event &event) const int X = players_.at(0)->getPosX() + (players_.at(0)->getWidth() - game_text_textures_[3]->getWidth()) / 2; createItemText(X, game_text_textures_.at(6)); break; - break; } case SDLK_8: { diff --git a/source/game_logo.h b/source/game_logo.h index daaec08..ab81b2d 100644 --- a/source/game_logo.h +++ b/source/game_logo.h @@ -25,7 +25,7 @@ private: int lenght = 8; // Cantidad de desplazamientos a realizar int remaining = lenght; // Cantidad de desplazamientos pendientes a realizar int counter = delay; // Contador para el retraso - int origin; // Valor inicial de la pantalla para dejarla igual tras el desplazamiento + int origin = 0; // Valor inicial de la pantalla para dejarla igual tras el desplazamiento // Constructor por defect Shake() = default; @@ -61,9 +61,9 @@ private: std::unique_ptr arcade_edition_sprite_; // Sprite con los graficos de "Arcade Edition" // Variables - int x_; // Posición donde dibujar el logo - int y_; // Posición donde dibujar el logo - float zoom_; // Zoom aplicado al texto "ARCADE EDITION" + int x_; // Posición donde dibujar el logo + int y_; // Posición donde dibujar el logo + float zoom_ = 1.0f; // Zoom aplicado al texto "ARCADE EDITION" int post_finished_counter_ = 1; // Contador final una vez terminada las animaciones de los logos Status coffee_crisis_status_ = Status::DISABLED; // Estado en el que se encuentra el texto "COFFEE CRISIS" diff --git a/source/intro.cpp b/source/intro.cpp index 8380937..5deaa91 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -338,7 +338,6 @@ void Intro::initSprites() const int SHADOW_SPRITE_HEIGHT = SPRITE_HEIGHT + BORDER; const int S_X_DEST = X_DEST - BORDER / 2; const int S_Y_DEST = Y_DEST - BORDER / 2; - ; // Crea las texturas para las sombras std::vector> shadow_textures; @@ -356,12 +355,10 @@ void Intro::initSprites() SDL_RenderClear(Screen::get()->getRenderer()); SDL_Rect rect = {BORDER / 2, BORDER / 2, SPRITE_WIDTH, SPRITE_HEIGHT}; - auto texture = Resource::get()->getTexture(TEXTURE_LIST.at(i))->getSDLTexture(); - SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD); - SDL_RenderCopy(Screen::get()->getRenderer(), texture, nullptr, &rect); - SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_NONE); - - // shadow_texture->setAlpha(160); + auto inner_texture = Resource::get()->getTexture(TEXTURE_LIST.at(i))->getSDLTexture(); + SDL_SetTextureBlendMode(inner_texture, SDL_BLENDMODE_MOD); + SDL_RenderCopy(Screen::get()->getRenderer(), inner_texture, nullptr, &rect); + SDL_SetTextureBlendMode(inner_texture, SDL_BLENDMODE_NONE); SDL_SetRenderTarget(Screen::get()->getRenderer(), temp); shadow_textures.push_back(shadow_texture); diff --git a/source/moving_sprite.cpp b/source/moving_sprite.cpp index 2dcdf0e..8b680fe 100644 --- a/source/moving_sprite.cpp +++ b/source/moving_sprite.cpp @@ -72,7 +72,7 @@ void MovingSprite::update() } // Muestra el sprite por pantalla -void MovingSprite::render() { texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_w_, zoom_h_, rotate_.angle, rotate_.center, flip_); } +void MovingSprite::render() { texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_w_, zoom_h_, rotate_.angle, &rotate_.center, flip_); } // Establece la rotacion void MovingSprite::rotate() diff --git a/source/moving_sprite.h b/source/moving_sprite.h index 4bab8e0..c55c2c1 100644 --- a/source/moving_sprite.h +++ b/source/moving_sprite.h @@ -4,8 +4,8 @@ #include // Para SDL_RendererFlip #include // Para shared_ptr #include -#include "sprite.h" // Para Sprite -class Texture; // lines 8-8 +#include "sprite.h" // Para Sprite +class Texture; // lines 8-8 // Clase MovingSprite. Añade movimiento y efectos de rotación, zoom y flip al sprite class MovingSprite : public Sprite @@ -13,14 +13,14 @@ class MovingSprite : public Sprite public: struct Rotate { - bool enabled; // Indica si ha de rotar - int counter; // Contador - int speed; // Velocidad de giro - double angle; // Angulo para dibujarlo - float amount; // Cantidad de grados a girar en cada iteración - SDL_Point *center; // Centro de rotación + bool enabled; // Indica si ha de rotar + int counter; // Contador + int speed; // Velocidad de giro + double angle; // Angulo para dibujarlo + float amount; // Cantidad de grados a girar en cada iteración + SDL_Point center; // Centro de rotación - Rotate() : enabled(false), counter(0), speed(1), angle(0.0), amount(0.0f), center(nullptr) {} + Rotate() : enabled(false), counter(0), speed(1), angle(0.0), amount(0.0f), center({0, 0}) {} }; protected: @@ -54,7 +54,7 @@ public: explicit MovingSprite(std::shared_ptr texture); // Destructor - virtual ~MovingSprite() = default; + virtual ~MovingSprite() override = default; // Actualiza las variables internas del objeto virtual void update(); @@ -88,7 +88,7 @@ public: // Establece el valor de la variable void setAngle(double value) { rotate_.angle = value; } - void setRotatingCenter(SDL_Point *point) { rotate_.center = point; } + void setRotatingCenter(SDL_Point point) { rotate_.center = point; } // Activa o desactiva el efecto de rotación void setRotate(bool enable); diff --git a/source/notifier.cpp b/source/notifier.cpp index 9cbdfd7..079ff1f 100644 --- a/source/notifier.cpp +++ b/source/notifier.cpp @@ -294,9 +294,6 @@ void Notifier::show(std::vector texts, int icon, const std::string notifications_.emplace_back(n); } -// Indica si hay notificaciones activas -bool Notifier::isActive() { return !notifications_.empty(); } - // Finaliza y elimnina todas las notificaciones activas void Notifier::clearAllNotifications() { @@ -317,10 +314,4 @@ std::vector Notifier::getCodes() codes.emplace_back(notification.code); } return codes; -} - -// Comprueba si hay alguna notificacion con un código -bool Notifier::checkCode(std::string code) -{ - return stringInVector(getCodes(), code); } \ No newline at end of file diff --git a/source/notifier.h b/source/notifier.h index 778ca82..47995be 100644 --- a/source/notifier.h +++ b/source/notifier.h @@ -96,11 +96,11 @@ public: void show(std::vector texts, int icon = -1, const std::string &code = std::string()); // Indica si hay notificaciones activas - bool isActive(); + bool isActive() { return !notifications_.empty(); } // Obtiene los códigos de las notificaciones std::vector getCodes(); // Comprueba si hay alguna notificacion con un código - bool checkCode(std::string code); + bool checkCode(const std::string &code) { return stringInVector(getCodes(), code); } }; diff --git a/source/path_sprite.h b/source/path_sprite.h index 00f9a9a..404bec4 100644 --- a/source/path_sprite.h +++ b/source/path_sprite.h @@ -59,7 +59,7 @@ public: : Sprite(texture) {} // Destructor - ~PathSprite() = default; + ~PathSprite() override = default; // Actualiza la posición del sprite void update(); diff --git a/source/player.h b/source/player.h index 0a28e96..bfa8aee 100644 --- a/source/player.h +++ b/source/player.h @@ -238,7 +238,7 @@ public: int getScoreBoardPanel() const { return scoreboard_panel_; } int getWidth() const { return WIDTH_; } PlayerState getPlayingState() const { return playing_state_; } - std::string getName() const { return name_; } + const std::string& getName() const { return name_; } bool get1CC() const { return game_completed_ && credits_used_ == 1; } bool getEnterNamePositionOverflow() const { return enter_name_->getPositionOverflow(); } diff --git a/source/smart_sprite.h b/source/smart_sprite.h index 91da328..57c2b80 100644 --- a/source/smart_sprite.h +++ b/source/smart_sprite.h @@ -28,7 +28,7 @@ public: : AnimatedSprite(texture) {} // Destructor - ~SmartSprite() = default; + ~SmartSprite() override = default; // Actualiza la posición y comprueba si ha llegado a su destino void update() override; diff --git a/source/tabe.h b/source/tabe.h index 63df5c8..7b9679f 100644 --- a/source/tabe.h +++ b/source/tabe.h @@ -30,9 +30,9 @@ struct TabeTimer // Constructor TabeTimer(float minTime, float maxTime) - : min_spawn_time(minTime * 60000), max_spawn_time(maxTime * 60000) + : min_spawn_time(minTime * 60000), max_spawn_time(maxTime * 60000), + current_time(SDL_GetTicks()) { - current_time = SDL_GetTicks(); reset(); } @@ -80,20 +80,20 @@ private: std::unique_ptr sprite_; // Sprite con los graficos y animaciones // Variables - float x_ = 0; // Posición del objeto - float y_ = 0; // Posición del objeto - float speed_ = 0.0f; // Velocidad de movimiento del objeto - float accel_ = 0.0f; // Aceleración del objeto - int fly_distance_ = 0; // Distancia de vuelo - int waiting_counter_ = 0; // Tiempo que pasa quieto el objeto - bool enabled_ = false; // Indica si el objeto está activo - TabeDirection direction_; // Dirección del objeto - TabeDirection destiny_; // Destino del objeto - TabeState state_ = TabeState::FLY; // Estado - int hit_counter_ = 0; // Contador para el estado HIT - int number_of_hits_ = 0; // Cantidad de disparos que ha recibido - bool has_bonus_ = true; // Indica si el Tabe aun tiene el bonus para soltar - TabeTimer timer_; // Temporizador para gestionar la aparición del Tabe + float x_ = 0; // Posición del objeto + float y_ = 0; // Posición del objeto + float speed_ = 0.0f; // Velocidad de movimiento del objeto + float accel_ = 0.0f; // Aceleración del objeto + int fly_distance_ = 0; // Distancia de vuelo + int waiting_counter_ = 0; // Tiempo que pasa quieto el objeto + bool enabled_ = false; // Indica si el objeto está activo + TabeDirection direction_ = TabeDirection::TO_THE_LEFT; // Dirección del objeto + TabeDirection destiny_ = TabeDirection::TO_THE_LEFT; // Destino del objeto + TabeState state_ = TabeState::FLY; // Estado + int hit_counter_ = 0; // Contador para el estado HIT + int number_of_hits_ = 0; // Cantidad de disparos que ha recibido + bool has_bonus_ = true; // Indica si el Tabe aun tiene el bonus para soltar + TabeTimer timer_; // Temporizador para gestionar la aparición del Tabe // Mueve el objeto void move();