diff --git a/source/game.cpp b/source/game.cpp index 5afb464..085fd93 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -1,14 +1,15 @@ #include "game.h" -#include // for SDL_BLENDMODE_BLEND -#include // for SDLK_1, SDLK_2, SDLK_3, SDLK_h -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for SDL_RWFromFile, SDL_RWclose, SDL_R... -#include // for SDL_GetTicks -#include // for SDL_WINDOWEVENT_FOCUS_GAINED, SDL_... -#include // for rand -#include // for min -#include // for basic_ifstream -#include // for char_traits, basic_istream, ifstream +#include // for SDL_BLENDMODE_BLEND +#include // for SDLK_1, SDLK_2, SDLK_3, SDLK_h +#include // for SDL_PIXELFORMAT_RGBA8888 +#include // for SDL_RWFromFile, SDL_RWclose, SDL_R... +#include // for SDL_GetTicks +#include // for SDL_WINDOWEVENT_FOCUS_GAINED, SDL_... +#include // for rand +#include // for min +#include // for basic_ifstream +#include // for char_traits, basic_istream, ifstream +#include #include "asset.h" // for Asset #include "background.h" // for Background #include "balloon.h" // for Balloon, BALLOON_SPEED_1, BALLOON_... @@ -133,13 +134,13 @@ void Game::init(int player_id) players_.push_back(std::move(player2)); // Obtiene mediante "playerID" el jugador que va a empezar jugar - auto player = getPlayer(player_id); + auto main_player = getPlayer(player_id); // Cambia el estado del jugador seleccionado - player->setStatusPlaying(PlayerStatus::PLAYING); + main_player->setStatusPlaying(PlayerStatus::PLAYING); // Como es el principio del juego, empieza sin inmunidad - player->setInvulnerable(false); + main_player->setInvulnerable(false); // Variables relacionadas con la dificultad switch (difficulty_) @@ -243,9 +244,9 @@ void Game::init(int player_id) // Activa o no al otro jugador if (rand() % 2 == 0) { - const auto otherPlayer = player_id == 1 ? 2 : 1; - auto player = getPlayer(otherPlayer); - player->setStatusPlaying(PlayerStatus::PLAYING); + const auto other_player_id = player_id == 1 ? 2 : 1; + auto other_player = getPlayer(other_player_id); + other_player->setStatusPlaying(PlayerStatus::PLAYING); } for (auto &player : players_) @@ -707,7 +708,7 @@ bool Game::saveDemoFile(const std::string &file_path) #endif // RECORDING // Crea una formación de enemigos -void Game::deployEnemyFormation() +void Game::deployBalloonFormation() { // Solo despliega una formación enemiga si ha pasado cierto tiempo desde la última if (balloon_deploy_counter_ == 0) @@ -1587,14 +1588,8 @@ void Game::killPlayer(std::shared_ptr &player) // Calcula y establece el valor de amenaza en funcion de los globos activos void Game::evaluateAndSetMenace() { - menace_current_ = 0; - for (auto &balloon : balloons_) - { - if (balloon->isEnabled()) - { - menace_current_ += balloon->getMenace(); - } - } + menace_current_ = std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon) + { return sum + (balloon->isEnabled() ? balloon->getMenace() : 0); }); } // Obtiene el valor de la variable @@ -1645,11 +1640,11 @@ void Game::updateTimeStoppedCounter() } // Actualiza la variable enemyDeployCounter -void Game::updateEnemyDeployCounter() +void Game::updateBalloonDeployCounter() { if (balloon_deploy_counter_ > 0) { - balloon_deploy_counter_--; + --balloon_deploy_counter_; } } @@ -1750,7 +1745,7 @@ void Game::update() // Actualiza los contadores de estado y efectos updateTimeStoppedCounter(); - updateEnemyDeployCounter(); + updateBalloonDeployCounter(); // Actualiza el ayudante updateHelper(); @@ -1872,7 +1867,7 @@ void Game::updateMenace() if (menace_current_ < menace_threshold_) { // Crea una formación de enemigos - deployEnemyFormation(); + deployBalloonFormation(); // Recalcula el nivel de amenaza con el nuevo globo evaluateAndSetMenace(); @@ -2248,28 +2243,14 @@ void Game::run() // Indica si se puede crear una powerball bool Game::canPowerBallBeCreated() { - if ((!power_ball_enabled_) && (calculateScreenPower() > POWERBALL_SCREENPOWER_MINIMUM) && (power_ball_counter_ == 0)) - { - return true; - } - - return false; + return (!power_ball_enabled_) && (calculateScreenPower() > POWERBALL_SCREENPOWER_MINIMUM) && (power_ball_counter_ == 0); } // Calcula el poder actual de los globos en pantalla int Game::calculateScreenPower() { - auto power = 0; - - for (auto &balloon : balloons_) - { - if (balloon->isEnabled()) - { - power += balloon->getPower(); - } - } - - return power; + return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon) + { return sum + (balloon->isEnabled() ? balloon->getPower() : 0); }); } // Inicializa las variables que contienen puntos de ruta para mover objetos @@ -2354,7 +2335,7 @@ void Game::updateHelper() // Solo ofrece ayuda cuando la amenaza es elevada if (menace_current_ > 15) { - for (auto &player : players_) + for (const auto &player : players_) { helper_.need_coffee = (player->getCoffees() == 0); helper_.need_coffee_machine = (!player->isPowerUp()); @@ -2370,7 +2351,7 @@ void Game::updateHelper() bool Game::allPlayersAreWaitingOrGameOver() { auto success = true; - for (auto &player : players_) + for (const auto &player : players_) { success &= player->isWaiting() || player->isGameOver(); } @@ -2382,7 +2363,7 @@ bool Game::allPlayersAreWaitingOrGameOver() bool Game::allPlayersAreGameOver() { auto success = true; - for (auto &player : players_) + for (const auto &player : players_) { success &= player->isGameOver(); } @@ -2394,7 +2375,7 @@ bool Game::allPlayersAreGameOver() bool Game::allPlayersAreNotPlaying() { auto success = true; - for (auto &player : players_) + for (const auto &player : players_) { success &= !player->isPlaying(); } @@ -2566,7 +2547,7 @@ void Game::reloadTextures() // Actualiza el marcador void Game::updateScoreboard() { - for (auto &player : players_) + for (const auto &player : players_) { scoreboard_->setScore(player->getScoreBoardPanel(), player->getScore()); scoreboard_->setMult(player->getScoreBoardPanel(), player->getScoreMultiplier()); @@ -2590,7 +2571,7 @@ void Game::pause(bool value) } // Añade una puntuación a la tabla de records -void Game::addScoreToScoreBoard(std::string name, int score) +void Game::addScoreToScoreBoard(const std::string &name, int score) { const auto entry = (HiScoreEntry){trim(name), score}; auto manager = std::make_unique(&options.game.hi_score_table); @@ -2635,7 +2616,7 @@ void Game::checkPlayersStatusPlaying() // Obtiene un jugador a partir de su "id" std::shared_ptr Game::getPlayer(int id) { - for (auto &player : players_) + for (const auto &player : players_) { if (player->getId() == id) { diff --git a/source/game.h b/source/game.h index b314066..cd92313 100644 --- a/source/game.h +++ b/source/game.h @@ -233,7 +233,7 @@ private: bool saveDemoFile(const std::string &file_path); #endif // Crea una formación de enemigos - void deployEnemyFormation(); + void deployBalloonFormation(); // Aumenta el poder de la fase void increaseStageCurrentPower(int power); @@ -362,7 +362,7 @@ private: void incTimeStoppedCounter(int value); // Actualiza la variable EnemyDeployCounter - void updateEnemyDeployCounter(); + void updateBalloonDeployCounter(); // Actualiza y comprueba el valor de la variable void updateTimeStoppedCounter(); @@ -431,7 +431,7 @@ private: void checkMusicStatus(); // Añade una puntuación a la tabla de records - void addScoreToScoreBoard(std::string name, int score); + void addScoreToScoreBoard(const std::string &name, int score); // Saca del estado de GAME OVER al jugador si el otro está activo void checkAndUpdatePlayerStatus(int active_player_index, int inactive_player_index); diff --git a/source/manage_hiscore_table.cpp b/source/manage_hiscore_table.cpp index 5b8e4d8..ff1abc0 100644 --- a/source/manage_hiscore_table.cpp +++ b/source/manage_hiscore_table.cpp @@ -50,7 +50,7 @@ void ManageHiScoreTable::sort() { struct { - bool operator()(HiScoreEntry &a, HiScoreEntry &b) const { return a.score > b.score; } + bool operator()(const HiScoreEntry &a, const HiScoreEntry &b) const { return a.score > b.score; } } custom_less; std::sort(table_->begin(), table_->end(), custom_less); diff --git a/source/notify.cpp b/source/notify.cpp index 3de069b..f68d51b 100644 --- a/source/notify.cpp +++ b/source/notify.cpp @@ -10,7 +10,7 @@ #include "texture.h" // for Texture // Constructor -Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile) +Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, const std::string &soundFile) : renderer(renderer), text(std::make_unique(bitmapFile, textFile, renderer)), bgColor(param.notification.color), diff --git a/source/notify.h b/source/notify.h index 75d4eb2..89ab780 100644 --- a/source/notify.h +++ b/source/notify.h @@ -77,7 +77,7 @@ private: public: // Constructor - Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile); + Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, const std::string &soundFile); // Destructor ~Notify(); diff --git a/source/options.cpp b/source/options.cpp index 53194e7..8439203 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -13,7 +13,7 @@ Options options; // Declaraciones -bool setOptions(std::string var, const std::string &value); +bool setOptions(const std::string &var, const std::string &value); // Inicializa las opciones del programa void initOptions() @@ -244,7 +244,7 @@ bool saveOptionsFile(std::string file_path) } // Asigna variables a partir de dos cadenas -bool setOptions(std::string var, const std::string &value) +bool setOptions(const std::string &var, const std::string &value) { // Indicador de éxito en la asignación auto success = true; diff --git a/source/param.cpp b/source/param.cpp index 6d850ee..59c6165 100644 --- a/source/param.cpp +++ b/source/param.cpp @@ -1,7 +1,10 @@ #include "param.h" #include // for char_traits, basic_ostream, basic_ifstream, basi... #include // for cout -#include "utils.h" // for Param, ParamGame, Zone, ParamBalloon +#include +#include +#include +#include "utils.h" // for Param, ParamGame, Zone, ParamBalloon Param param; @@ -40,7 +43,7 @@ void initParam() param.title.title_c_c_position = 11; // BACKGROUND - param.background.attenuate_color = {255, 255, 255}; + param.background.attenuate_color = (Color){255, 255, 255}; param.background.attenuate_alpha = 32; // BALLOONS @@ -52,10 +55,18 @@ void initParam() param.balloon_3.grav = 0.10f; param.balloon_4.vel = 4.95f; param.balloon_4.grav = 0.10f; + + // NOTIFICATION + param.notification.pos_v = NotifyPosition::TOP; + param.notification.pos_h = NotifyPosition::LEFT; + param.notification.sound = false; + param.notification.color.r = 48; + param.notification.color.g = 48; + param.notification.color.b = 48; } // Establece valores para los parametros a partir de un fichero de texto -void loadParamsFromFile(std::string file_path) +/*void loadParamsFromFile(std::string file_path) { // Pone valores por defecto a las variables initParam(); @@ -80,8 +91,15 @@ void loadParamsFromFile(std::string file_path) param1.clear(); param2.clear(); - // Elimina los comentarios - line = line.substr(0, line.find("#")); + // Elimina los comentarios al final de una linea + { + // line = line.substr(0, line.find("#")); + auto pos = line.find("#"); + if (pos != std::string::npos) + { + line.resize(pos); + } + } // Ignora los espacios en blanco int pos = 0; @@ -148,6 +166,50 @@ void loadParamsFromFile(std::string file_path) std::cout << "Failed to load file: " << file_path << std::endl; #endif + precalculateZones(); +}*/ +void loadParamsFromFile(const std::string &file_path) +{ + // Inicializa los parámetros con valores por defecto + initParam(); + + // Abre el archivo + std::ifstream file(file_path); + if (!file.is_open()) + { +#ifdef VERBOSE + std::cerr << "Error: No se pudo abrir el archivo " << file_path << std::endl; +#endif + throw std::runtime_error("No se pudo abrir el archivo: " + file_path); + } + +#ifdef VERBOSE + const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1); + std::cout << "Reading file: " << file_name << std::endl; +#endif + + std::string line, param1, param2; + while (std::getline(file, line)) + { + // Elimina comentarios + auto comment_pos = line.find('#'); + if (comment_pos != std::string::npos) + { + line = line.substr(0, comment_pos); + } + + // Usa un stream para separar palabras + std::istringstream iss(line); + if (iss >> param1 >> param2) + { + setParams(param1, param2); + } + } + + // Cierra el archivo + file.close(); + + // Realiza cálculos adicionales después de cargar los parámetros precalculateZones(); } diff --git a/source/param.h b/source/param.h index f0f9530..8e688a5 100644 --- a/source/param.h +++ b/source/param.h @@ -6,4 +6,4 @@ struct Param; extern Param param; // Establece valores para los parametros a partir de un fichero de texto -void loadParamsFromFile(std::string file_path); \ No newline at end of file +void loadParamsFromFile(const std::string &file_path); \ No newline at end of file diff --git a/source/player.cpp b/source/player.cpp index 7f10f9b..8ae99ef 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -12,30 +12,29 @@ // Constructor Player::Player(int id, float x, int y, bool demo, SDL_Rect *play_area, std::vector> texture, std::vector *> animations) + : player_sprite_(std::make_unique(texture[0], "", animations[0])), + power_sprite_(std::make_unique(texture[1], "", animations[1])), + enter_name_(std::make_unique()), + play_area_(play_area), + id_(id), + pos_x_(x), + pos_y_(y), + default_pos_x_(x), + default_pos_y_(y), + status_playing_(PlayerStatus::WAITING), + scoreboard_panel_(0), + name_(std::string()), + controller_index_(0), + demo_(demo) { // Reserva memoria para los objetos - player_sprite_ = std::make_unique(texture[0], "", animations[0]); - power_sprite_ = std::make_unique(texture[1], "", animations[1]); power_sprite_->getTexture()->setAlpha(224); - enter_name_ = std::make_unique(); - - // Rectangulo con la zona de juego - play_area_ = play_area; - - // Establece la posición inicial del jugador - default_pos_x_ = pos_x_ = x; - default_pos_y_ = pos_y_ = y; // Establece los offsets para el sprite de PowerUp power_up_desp_x_ = (power_sprite_->getWidth() - player_sprite_->getWidth()) / 2; power_sprite_->setPosY(y - (power_sprite_->getHeight() - player_sprite_->getHeight())); // Inicializa variables - id_ = id; - demo_ = demo; - status_playing_ = PlayerStatus::WAITING; - scoreboard_panel_ = 0; - name_.clear(); setRecordName(enter_name_->getName()); init(); } @@ -237,21 +236,13 @@ void Player::render() // Establece el estado del jugador cuando camina void Player::setWalkingStatus(PlayerStatus status) { - // Si cambiamos de estado, reiniciamos la animación - if (status_walking_ != status) - { - status_walking_ = status; - } + status_walking_ = status; } // Establece el estado del jugador cuando dispara void Player::setFiringStatus(PlayerStatus status) { - // Si cambiamos de estado, reiniciamos la animación - if (status_firing_ != status) - { - status_firing_ = status; - } + status_firing_ = status; } // Establece la animación correspondiente al estado @@ -694,7 +685,7 @@ void Player::shiftColliders() } // Pone las texturas del jugador -void Player::setPlayerTextures(std::vector> texture) +void Player::setPlayerTextures(const std::vector> &texture) { player_sprite_->setTexture(texture[0]); power_sprite_->setTexture(texture[1]); @@ -736,7 +727,7 @@ int Player::getScoreBoardPanel() const void Player::decContinueCounter() { continue_ticks_ = SDL_GetTicks(); - continue_counter_--; + --continue_counter_; if (continue_counter_ < 0) { setStatusPlaying(PlayerStatus::GAME_OVER); @@ -744,13 +735,13 @@ void Player::decContinueCounter() } // Establece el nombre del jugador -void Player::setName(std::string name) +void Player::setName(const std::string &name) { name_ = name; } // Establece el nombre del jugador para la tabla de mejores puntuaciones -void Player::setRecordName(std::string record_name) +void Player::setRecordName(const std::string &record_name) { record_name_ = record_name.substr(0, 8); } diff --git a/source/player.h b/source/player.h index 45adb4f..8047556 100644 --- a/source/player.h +++ b/source/player.h @@ -118,7 +118,7 @@ public: void render(); // Pone las texturas del jugador - void setPlayerTextures(std::vector> texture); + void setPlayerTextures(const std::vector> &texture); // Actua en consecuencia de la entrada recibida void setInput(InputType input); @@ -271,10 +271,10 @@ public: void decContinueCounter(); // Establece el nombre del jugador - void setName(std::string name); + void setName(const std::string &name); // Establece el nombre del jugador para la tabla de mejores puntuaciones - void setRecordName(std::string record_name); + void setRecordName(const std::string &record_name); // Obtiene el nombre del jugador std::string getName() const; diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index 668d509..7bdd94c 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -34,13 +34,21 @@ Scoreboard *Scoreboard::get() // Constructor Scoreboard::Scoreboard(SDL_Renderer *renderer) - : renderer_(renderer) + : renderer_(renderer), + + game_power_meter_texture_(std::make_shared(renderer, Asset::get()->get("game_power_meter.png"))), + power_meter_sprite_(std::make_unique(game_power_meter_texture_)), + text_scoreboard_(std::make_unique(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), renderer)), + + stage_(1), + hi_score_(0), + power_(0), + hi_score_name_(std::string()), + color_({0, 0, 0}), + rect_({0, 0, 320, 40}), + ticks_(SDL_GetTicks()), + counter_(0) { - // Inicializa punteros - game_power_meter_texture_ = nullptr; - power_meter_sprite_ = nullptr; - text_scoreboard_ = nullptr; - // Inicializa variables for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i) { @@ -51,25 +59,14 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer) mult_[i] = 0; continue_counter_[i] = 0; } - stage_ = 1; - hi_score_ = 0; - power_ = 0; - hi_score_name_.clear(); - color_ = {0, 0, 0}; - rect_ = {0, 0, 320, 40}; + panel_[SCOREBOARD_LEFT_PANEL].mode = ScoreboardMode::SCORE; panel_[SCOREBOARD_RIGHT_PANEL].mode = ScoreboardMode::SCORE; panel_[SCOREBOARD_CENTER_PANEL].mode = ScoreboardMode::STAGE_INFO; - ticks_ = SDL_GetTicks(); - counter_ = 0; // Recalcula las anclas de los elementos recalculateAnchors(); - - // Crea objetos - game_power_meter_texture_ = std::make_shared(renderer_, Asset::get()->get("game_power_meter.png")); - power_meter_sprite_ = std::make_unique(slot4_2_.x - 20, slot4_2_.y, 40, 7, game_power_meter_texture_); - text_scoreboard_ = std::make_unique(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), renderer_); + power_meter_sprite_->setPos({slot4_2_.x - 20, slot4_2_.y, 40, 7}); // Crea la textura de fondo background_ = nullptr; @@ -130,13 +127,13 @@ void Scoreboard::render() } // Establece el valor de la variable -void Scoreboard::setName(int panel_, std::string name_) +void Scoreboard::setName(int panel_, const std::string &name_) { this->name_[panel_] = name_; } // Establece el valor de la variable -void Scoreboard::setRecordName(int panel_, std::string record_name_) +void Scoreboard::setRecordName(int panel_, const std::string &record_name_) { this->record_name_[panel_] = record_name_; } @@ -184,7 +181,7 @@ void Scoreboard::setPower(float power_) } // Establece el valor de la variable -void Scoreboard::setHiScoreName(std::string name_) +void Scoreboard::setHiScoreName(const std::string &name_) { hi_score_name_ = name_; } @@ -323,7 +320,7 @@ void Scoreboard::fillPanelTextures() // ENTER NAME text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText(106)); - SDL_Rect rect_ = {enter_name_pos_.x, enter_name_pos_.y, 5, 7}; + SDL_Rect rect = {enter_name_pos_.x, enter_name_pos_.y, 5, 7}; SDL_SetRenderDrawColor(renderer_, 0xFF, 0xFF, 0xEB, 255); for (int j = 0; j < (int)record_name_[i].size(); ++j) { @@ -331,16 +328,16 @@ void Scoreboard::fillPanelTextures() { // La letra seleccionada se pinta de forma intermitente if (counter_ % 3 > 0) { - SDL_RenderDrawLine(renderer_, rect_.x, rect_.y + rect_.h, rect_.x + rect_.w, rect_.y + rect_.h); - text_scoreboard_->write(rect_.x, rect_.y, record_name_[i].substr(j, 1)); + SDL_RenderDrawLine(renderer_, rect.x, rect.y + rect.h, rect.x + rect.w, rect.y + rect.h); + text_scoreboard_->write(rect.x, rect.y, record_name_[i].substr(j, 1)); } } else { - SDL_RenderDrawLine(renderer_, rect_.x, rect_.y + rect_.h, rect_.x + rect_.w, rect_.y + rect_.h); - text_scoreboard_->write(rect_.x, rect_.y, record_name_[i].substr(j, 1)); + SDL_RenderDrawLine(renderer_, rect.x, rect.y + rect.h, rect.x + rect.w, rect.y + rect.h); + text_scoreboard_->write(rect.x, rect.y, record_name_[i].substr(j, 1)); } - rect_.x += 7; + rect.x += 7; } break; } diff --git a/source/scoreboard.h b/source/scoreboard.h index 1809ed1..1500388 100644 --- a/source/scoreboard.h +++ b/source/scoreboard.h @@ -50,9 +50,9 @@ private: std::shared_ptr game_power_meter_texture_; // Textura con el marcador de poder de la fase std::unique_ptr power_meter_sprite_; // Sprite para el medidor de poder de la fase - std::unique_ptr text_scoreboard_; // Fuente para el marcador del juego + std::unique_ptr text_scoreboard_; // Fuente para el marcador del juego - SDL_Texture *background_; // Textura para dibujar el marcador + SDL_Texture *background_; // Textura para dibujar el marcador std::vector panel_texture_; // Texturas para dibujar cada panel // Variables @@ -125,10 +125,10 @@ public: void render(); // Establece el valor de la variable - void setName(int panel, std::string name); + void setName(int panel, const std::string &name); // Establece el valor de la variable - void setRecordName(int panel, std::string record_name); + void setRecordName(int panel, const std::string &record_name); // Establece el valor de la variable void setSelectorPos(int panel, int pos); @@ -152,7 +152,7 @@ public: void setPower(float power); // Establece el valor de la variable - void setHiScoreName(std::string name); + void setHiScoreName(const std::string &name); // Establece el valor de la variable void setColor(Color color); diff --git a/source/screen.cpp b/source/screen.cpp index 926c8cc..c7e2026 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -44,12 +44,27 @@ Screen *Screen::get() // Constructor Screen::Screen(SDL_Window *window, SDL_Renderer *renderer) - : window_(window), renderer_(renderer) + : window_(window), + renderer_(renderer), + + notify_(std::make_unique(renderer_, std::string(), Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Asset::get()->get("notify.wav"))), + game_canvas_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)), + shader_canvas_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)), + + src_rect_({0, 0, param.game.width, param.game.height}), + dst_rect_({0, 0, param.game.width, param.game.height}), + border_color_({0x00, 0x00, 0x00}), + attenuate_effect_(false), + fps_ticks_(0), + fps_counter_(0), + fps_(0), +#ifdef DEBUG + show_info_(true) +#else + show_info_(false) +#endif { // Inicializa variables - src_rect_ = {0, 0, param.game.width, param.game.height}; - dst_rect_ = {0, 0, param.game.width, param.game.height}; - border_color_ = {0, 0, 0}; flash_effect_.enabled = false; flash_effect_.counter = 0; flash_effect_.lenght = 0; @@ -62,29 +77,10 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer) shake_effect_.remaining = 0; shake_effect_.originalPos = 0; shake_effect_.originalWidth = param.game.width; - attenuate_effect_ = false; - fps_ticks_ = 0; - fps_counter_ = 0; - fps_ = 0; -#ifdef DEBUG - show_info_ = true; -#else - show_info_ = false; -#endif SDL_DisplayMode DM; SDL_GetCurrentDisplayMode(0, &DM); info_resolution_ = std::to_string(DM.w) + " X " + std::to_string(DM.h) + " AT " + std::to_string(DM.refresh_rate) + " HZ"; - // Crea los objetos - notify_ = std::make_unique(renderer_, "", Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Asset::get()->get("notify.wav")); - - // Define el color del borde para el modo de pantalla completa - border_color_ = {0x00, 0x00, 0x00}; - - // Crea las textura donde se dibujan los graficos del juego - game_canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height); - shader_canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height); - // Establece el modo de video setVideoMode(options.video.mode); @@ -183,9 +179,10 @@ void Screen::blit() // Establece el modo de video void Screen::setVideoMode(ScreenVideoMode videoMode) { - options.video.mode = videoMode; #ifdef ARCADE options.video.mode = ScreenVideoMode::WINDOW; +#else + options.video.mode = videoMode; #endif switch (options.video.mode) @@ -455,7 +452,7 @@ void Screen::attenuate(bool value) } // Muestra una notificación de texto por pantalla; -void Screen::showNotification(std::string text1, std::string text2, int icon) +void Screen::showNotification(const std::string &text1, const std::string &text2, int icon) { notify_->showText(text1, text2, icon); } diff --git a/source/screen.h b/source/screen.h index 0749648..6379421 100644 --- a/source/screen.h +++ b/source/screen.h @@ -152,7 +152,7 @@ public: void attenuate(bool value); // Muestra una notificación de texto por pantalla; - void showNotification(std::string text1 = std::string(), std::string text2 = std::string(), int icon = -1); + void showNotification(const std::string &text1 = std::string(), const std::string &text2 = std::string(), int icon = -1); // Indica si hay alguna notificación activa en pantalla bool notificationsAreActive() const; diff --git a/source/text.cpp b/source/text.cpp index e28c40a..af93bcf 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -21,7 +21,9 @@ TextFile LoadTextFile(std::string file_path) } // Abre el fichero para leer los valores +#ifdef VERBOSE const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1).c_str(); +#endif std::ifstream file(file_path); if (file.is_open() && file.good()) @@ -55,7 +57,7 @@ TextFile LoadTextFile(std::string file_path) // Cierra el fichero #ifdef VERBOSE - std::cout << "Text loaded: " << file_name.c_str() << std::endl; + std::cout << "Text loaded: " << file_name << std::endl; #endif file.close(); } @@ -64,7 +66,7 @@ TextFile LoadTextFile(std::string file_path) else { #ifdef VERBOSE - std::cout << "Warning: Unable to open " << file_name.c_str() << " file" << std::endl; + std::cout << "Warning: Unable to open " << file_name << " file" << std::endl; #endif } @@ -146,7 +148,7 @@ Text::Text(TextFile *text_file, std::shared_ptr texture) } // Escribe texto en pantalla -void Text::write(int x, int y, std::string text, int kerning, int lenght) +void Text::write(int x, int y, const std::string &text, int kerning, int lenght) { auto shift = 0; @@ -169,7 +171,7 @@ void Text::write(int x, int y, std::string text, int kerning, int lenght) } // Escribe el texto con colores -void Text::writeColored(int x, int y, std::string text, Color color, int kerning, int lenght) +void Text::writeColored(int x, int y, const std::string &text, Color color, int kerning, int lenght) { sprite_->getTexture()->setColor(color.r, color.g, color.b); write(x, y, text, kerning, lenght); @@ -177,7 +179,7 @@ void Text::writeColored(int x, int y, std::string text, Color color, int kerning } // Escribe el texto con sombra -void Text::writeShadowed(int x, int y, std::string text, Color color, Uint8 shadow_distance, int kerning, int lenght) +void Text::writeShadowed(int x, int y, const std::string &text, Color color, Uint8 shadow_distance, int kerning, int lenght) { sprite_->getTexture()->setColor(color.r, color.g, color.b); write(x + shadow_distance, y + shadow_distance, text, kerning, lenght); @@ -186,14 +188,14 @@ void Text::writeShadowed(int x, int y, std::string text, Color color, Uint8 shad } // Escribe el texto centrado en un punto x -void Text::writeCentered(int x, int y, std::string text, int kerning, int lenght) +void Text::writeCentered(int x, int y, const std::string &text, int kerning, int lenght) { x -= (Text::lenght(text, kerning) / 2); write(x, y, text, kerning, lenght); } // Escribe texto con extras -void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, Color textColor, Uint8 shadow_distance, Color shadow_color, int lenght) +void Text::writeDX(Uint8 flags, int x, int y, const std::string &text, int kerning, Color textColor, Uint8 shadow_distance, Color shadow_color, int lenght) { const auto centered = ((flags & TEXT_CENTER) == TEXT_CENTER); const auto shadowed = ((flags & TEXT_SHADOW) == TEXT_SHADOW); @@ -235,7 +237,7 @@ void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, Col } // Obtiene la longitud en pixels de una cadena -int Text::lenght(std::string text, int kerning) const +int Text::lenght(const std::string &text, int kerning) const { auto shift = 0; @@ -267,7 +269,7 @@ void Text::setFixedWidth(bool value) } // Carga una paleta de colores para el texto -void Text::addPalette(std::string path) +void Text::addPalette(const std::string &path) { texture_->addPalette(path); } diff --git a/source/text.h b/source/text.h index 240514b..ae68315 100644 --- a/source/text.h +++ b/source/text.h @@ -52,22 +52,22 @@ public: ~Text() = default; // Escribe el texto en pantalla - void write(int x, int y, std::string text, int kerning = 1, int lenght = -1); + void write(int x, int y, const std::string &text, int kerning = 1, int lenght = -1); // Escribe el texto con colores - void writeColored(int x, int y, std::string text, Color color, int kerning = 1, int lenght = -1); + void writeColored(int x, int y, const std::string &text, Color color, int kerning = 1, int lenght = -1); // Escribe el texto con sombra - void writeShadowed(int x, int y, std::string text, Color color, Uint8 shadow_distance = 1, int kerning = 1, int lenght = -1); + void writeShadowed(int x, int y, const std::string &text, Color color, Uint8 shadow_distance = 1, int kerning = 1, int lenght = -1); // Escribe el texto centrado en un punto x - void writeCentered(int x, int y, std::string text, int kerning = 1, int lenght = -1); + void writeCentered(int x, int y, const std::string &text, int kerning = 1, int lenght = -1); // Escribe texto con extras - void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, Color textColor = {255, 255, 255}, Uint8 shadow_distance = 1, Color shadow_color = {0, 0, 0}, int lenght = -1); + void writeDX(Uint8 flags, int x, int y, const std::string &text, int kerning = 1, Color textColor = {255, 255, 255}, Uint8 shadow_distance = 1, Color shadow_color = {0, 0, 0}, int lenght = -1); // Obtiene la longitud en pixels de una cadena - int lenght(std::string text, int kerning = 1) const; + int lenght(const std::string &text, int kerning = 1) const; // Devuelve el valor de la variable int getCharacterSize() const; @@ -79,7 +79,7 @@ public: void setFixedWidth(bool value); // Carga una paleta de colores para el texto - void addPalette(std::string path); + void addPalette(const std::string &path); // Establece una paleta de colores para el texto void setPalette(int index); diff --git a/source/texture.cpp b/source/texture.cpp index 1e49bea..a661bc5 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -11,7 +11,7 @@ #include "stb_image.h" // for stbi_failure_reason, stbi_image_free // Constructor -Texture::Texture(SDL_Renderer *renderer, std::string path) +Texture::Texture(SDL_Renderer *renderer, const std::string &path) : renderer_(renderer), path_(path) { // Inicializa @@ -37,8 +37,8 @@ Texture::Texture(SDL_Renderer *renderer, std::string path) // .gif else if (extension == "gif") { - surface_ = loadSurface(path_.c_str()); - addPalette(path_.c_str()); + surface_ = loadSurface(path_); + addPalette(path_); setPaletteColor(0, 0, 0x00000000); createBlank(width_, height_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING); SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND); @@ -54,13 +54,13 @@ Texture::~Texture() } // Carga una imagen desde un fichero -bool Texture::loadFromFile(std::string path) +bool Texture::loadFromFile(const std::string &path) { const std::string file_name = path.substr(path.find_last_of("\\/") + 1); int req_format = STBI_rgb_alpha; int width, height, orig_format; unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format); - if (data == nullptr) + if (!data) { #ifdef VERBOSE std::cout << "Loading image failed: " << stbi_failure_reason() << std::endl; @@ -70,19 +70,19 @@ bool Texture::loadFromFile(std::string path) else { #ifdef VERBOSE - std::cout << "Image loaded: " << file_name.c_str() << std::endl; + std::cout << "Image loaded: " << file_name << std::endl; #endif } int depth, pitch; Uint32 pixel_format; - if (req_format == STBI_rgb) + /*if (req_format == STBI_rgb) { depth = 24; pitch = 3 * width; // 3 bytes por pixel * pixels por linea pixel_format = SDL_PIXELFORMAT_RGB24; } - else + else*/ { // STBI_rgb_alpha (RGBA) depth = 32; pitch = 4 * width; @@ -96,11 +96,11 @@ bool Texture::loadFromFile(std::string path) SDL_Texture *newTexture = nullptr; // Carga la imagen desde una ruta específica - SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format); + auto loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom(static_cast(data), width, height, depth, pitch, pixel_format); if (loadedSurface == nullptr) { #ifdef VERBOSE - std::cout << "Unable to load image " << path.c_str() << std::endl; + std::cout << "Unable to load image " << path << std::endl; #endif } else @@ -110,7 +110,7 @@ bool Texture::loadFromFile(std::string path) if (newTexture == nullptr) { #ifdef VERBOSE - std::cout << "Unable to create texture from " << path.c_str() << "! SDL Error: " << SDL_GetError() << std::endl; + std::cout << "Unable to create texture from " << path << "! SDL Error: " << SDL_GetError() << std::endl; #endif } else @@ -241,10 +241,10 @@ SDL_Texture *Texture::getSDLTexture() // Crea una nueva surface Surface Texture::newSurface(int w, int h) { - Surface surf = (Surface)malloc(sizeof(surface_s)); + Surface surf = static_cast(malloc(sizeof(surface_s))); surf->w = w; surf->h = h; - surf->data = (Uint8 *)malloc(w * h); + surf->data = static_cast(malloc(w * h)); return surf; } @@ -265,29 +265,29 @@ void Texture::deleteSurface(Surface surface) } // Crea una surface desde un fichero .gif -Surface Texture::loadSurface(const char *file_name) +Surface Texture::loadSurface(const std::string &file_name) { - FILE *f = fopen(file_name, "rb"); + FILE *f = fopen(file_name.c_str(), "rb"); if (!f) { - return NULL; + return nullptr; } fseek(f, 0, SEEK_END); long size = ftell(f); fseek(f, 0, SEEK_SET); - Uint8 *buffer = (Uint8 *)malloc(size); + Uint8 *buffer = static_cast(malloc(size)); fread(buffer, size, 1, f); fclose(f); Uint16 w, h; Uint8 *pixels = LoadGif(buffer, &w, &h); - if (pixels == NULL) + if (pixels == nullptr) { - return NULL; + return nullptr; } - Surface surface = (Surface)malloc(sizeof(surface_s)); + Surface surface = static_cast(malloc(sizeof(surface_s))); surface->w = w; surface->h = h; surface->data = pixels; @@ -312,7 +312,7 @@ void Texture::flipSurface() // Vuelca los datos Uint32 *pixels; int pitch; - SDL_LockTexture(texture_, nullptr, (void **)&pixels, &pitch); + SDL_LockTexture(texture_, nullptr, reinterpret_cast(&pixels), &pitch); for (int i = 0; i < width_ * height_; ++i) { pixels[i] = palettes_[paletteIndex_][surface_->data[i]]; @@ -327,11 +327,11 @@ void Texture::setPaletteColor(int palette, int index, Uint32 color) } // Carga una paleta desde un fichero -std::vector Texture::loadPal(const char *file_name) +std::vector Texture::loadPal(const std::string &file_name) { std::vector palette; - FILE *f = fopen(file_name, "rb"); + FILE *f = fopen(file_name.c_str(), "rb"); if (!f) { return palette; @@ -340,12 +340,12 @@ std::vector Texture::loadPal(const char *file_name) fseek(f, 0, SEEK_END); long size = ftell(f); fseek(f, 0, SEEK_SET); - Uint8 *buffer = (Uint8 *)malloc(size); + Uint8 *buffer = static_cast(malloc(size)); fread(buffer, size, 1, f); fclose(f); - Uint32 *pal = LoadPalette(buffer); - if (pal == nullptr) + auto pal = LoadPalette(buffer); + if (!pal) { return palette; } diff --git a/source/texture.h b/source/texture.h index c533ab0..361bcee 100644 --- a/source/texture.h +++ b/source/texture.h @@ -39,23 +39,23 @@ private: void deleteSurface(Surface surface); // Crea una surface desde un fichero .gif - Surface loadSurface(const char *file_name); + Surface loadSurface(const std::string &file_name); // Vuelca la surface en la textura void flipSurface(); // Carga una paleta desde un fichero - std::vector loadPal(const char *file_name); + std::vector loadPal(const std::string &file_name); public: // Constructor - explicit Texture(SDL_Renderer *renderer, std::string path = std::string()); + explicit Texture(SDL_Renderer *renderer, const std::string &path = std::string()); // Destructor ~Texture(); // Carga una imagen desde un fichero - bool loadFromFile(std::string path); + bool loadFromFile(const std::string &path); // Crea una textura en blanco bool createBlank(int width, int height, SDL_PixelFormatEnum format = SDL_PIXELFORMAT_RGBA8888, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING); diff --git a/source/title.cpp b/source/title.cpp index 5a170b9..3ddc578 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -315,9 +315,9 @@ void Title::resetCounter() // Intercambia la asignación de mandos a los jugadores void Title::swapControllers() { - const int num_controllers_ = input_->getNumControllers(); + const auto num_controllers = input_->getNumControllers(); - if (num_controllers_ == 0) + if (num_controllers == 0) { return; } diff --git a/source/utils.cpp b/source/utils.cpp index e8fdc10..01394ab 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -29,210 +29,112 @@ double distanceSquared(int x1, int y1, int x2, int y2) } // Detector de colisiones entre dos circulos -bool checkCollision(Circle &a, Circle &b) +bool checkCollision(const Circle &a, const Circle &b) { // Calcula el radio total al cuadrado - int total_radius_squared = a.r + b.r; - total_radius_squared = total_radius_squared * total_radius_squared; + int total_radius_squared = (a.r + b.r) * (a.r + b.r); - // Si la distancia entre el centro de los circulos es inferior a la suma de sus radios - if (distanceSquared(a.x, a.y, b.x, b.y) < (total_radius_squared)) - { - // Los circulos han colisionado - return true; - } - - // En caso contrario - return false; + // Comprueba si la distancia entre los centros de los círculos es inferior a la suma de sus radios + return distanceSquared(a.x, a.y, b.x, b.y) < total_radius_squared; } // Detector de colisiones entre un circulo y un rectangulo -bool checkCollision(Circle &a, SDL_Rect &b) +bool checkCollision(const Circle &a, const SDL_Rect &b) { - // Closest point on collision box - int cX, cY; + // Encuentra el punto más cercano en el rectángulo + int cX = std::clamp(a.x, b.x, b.x + b.w); + int cY = std::clamp(a.y, b.y, b.y + b.h); - // Find closest x offset - if (a.x < b.x) - { - cX = b.x; - } - else if (a.x > b.x + b.w) - { - cX = b.x + b.w; - } - else - { - cX = a.x; - } - - // Find closest y offset - if (a.y < b.y) - { - cY = b.y; - } - else if (a.y > b.y + b.h) - { - cY = b.y + b.h; - } - else - { - cY = a.y; - } - - // If the closest point is inside the Circle - if (distanceSquared(a.x, a.y, cX, cY) < a.r * a.r) - { - // This box and the Circle have collided - return true; - } - - // If the shapes have not collided - return false; + // Si el punto más cercano está dentro del círculo + return distanceSquared(a.x, a.y, cX, cY) < a.r * a.r; } // Detector de colisiones entre dos rectangulos -bool checkCollision(SDL_Rect &a, SDL_Rect &b) +bool checkCollision(const SDL_Rect &a, const SDL_Rect &b) { - // Calcula las caras del rectangulo a - const int leftA = a.x; - const int rightA = a.x + a.w; - const int topA = a.y; - const int bottomA = a.y + a.h; + const int leftA = a.x, rightA = a.x + a.w, topA = a.y, bottomA = a.y + a.h; + const int leftB = b.x, rightB = b.x + b.w, topB = b.y, bottomB = b.y + b.h; - // Calcula las caras del rectangulo b - const int leftB = b.x; - const int rightB = b.x + b.w; - const int topB = b.y; - const int bottomB = b.y + b.h; - - // Si cualquiera de las caras de a está fuera de b if (bottomA <= topB) - { return false; - } - if (topA >= bottomB) - { return false; - } - if (rightA <= leftB) - { return false; - } - if (leftA >= rightB) - { return false; - } - // Si ninguna de las caras está fuera de b return true; } // Detector de colisiones entre un punto y un rectangulo -bool checkCollision(SDL_Point &p, SDL_Rect &r) +bool checkCollision(const SDL_Point &p, const SDL_Rect &r) { - // Comprueba si el punto está a la izquierda del rectangulo - if (p.x < r.x) - { + if (p.x < r.x || p.x > r.x + r.w) return false; - } - - // Comprueba si el punto está a la derecha del rectangulo - if (p.x > r.x + r.w) - { + if (p.y < r.y || p.y > r.y + r.h) return false; - } - - // Comprueba si el punto está por encima del rectangulo - if (p.y < r.y) - { - return false; - } - - // Comprueba si el punto está por debajo del rectangulo - if (p.y > r.y + r.h) - { - return false; - } - - // Si no está fuera, es que está dentro return true; } // Convierte una cadena en un valor booleano -bool stringToBool(std::string str) +bool stringToBool(const std::string &str) { - return str == "true" ? true : false; + return str == "true"; } // Convierte un valor booleano en una cadena std::string boolToString(bool value) { - return value == true ? "true" : "false"; + return value ? "true" : "false"; } // Convierte un valor booleano en una cadena "on" o "off" std::string boolToOnOff(bool value) { - return value == true ? "on" : "off"; + return value ? "on" : "off"; } // Convierte una cadena a minusculas -std::string toLower(std::string str) +std::string toLower(const std::string &str) { - const char *original = str.c_str(); - char *lower = (char *)malloc(str.size() + 1); - for (int i = 0; i < (int)str.size(); ++i) - { - char c = original[i]; - lower[i] = (c >= 65 && c <= 90) ? c + 32 : c; - } - lower[str.size()] = 0; - std::string nova(lower); - free(lower); - return nova; + std::string result = str; + std::transform(result.begin(), result.end(), result.begin(), + [](unsigned char c) + { return std::tolower(c); }); + return result; } // Obtiene el fichero de sonido a partir de un nombre -JA_Sound_t *getSound(std::vector sounds, std::string name) +JA_Sound_t *getSound(const std::vector &sounds, const std::string &name) { - for (auto s : sounds) + for (const auto &s : sounds) { if (s.name == name) { return s.file; } } - return nullptr; } // Obtiene el fichero de música a partir de un nombre -JA_Music_t *getMusic(std::vector music, std::string name) +JA_Music_t *getMusic(const std::vector &music, const std::string &name) { - for (auto m : music) + for (const auto &m : music) { if (m.name == name) { return m.file; } } - return nullptr; } // Ordena las entradas de la tabla de records -HiScoreEntry sortHiScoreTable(HiScoreEntry entry1, HiScoreEntry entry2) +HiScoreEntry sortHiScoreTable(const HiScoreEntry &entry1, const HiScoreEntry &entry2) { - if (entry1.score > entry2.score) - { - return entry1; - } - - return entry2; + return (entry1.score > entry2.score) ? entry1 : entry2; } // Dibuja un circulo @@ -275,41 +177,31 @@ void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_ } // Aclara el color -Color lightenColor(Color color, int amount) +Color lightenColor(const Color &color, int amount) { Color newColor; - newColor.r = std::min(255, (int)color.r + amount); - newColor.g = std::min(255, (int)color.g + amount); - newColor.b = std::min(255, (int)color.b + amount); + newColor.r = std::min(255, color.r + amount); + newColor.g = std::min(255, color.g + amount); + newColor.b = std::min(255, color.b + amount); return newColor; } // Oscurece el color -Color DarkenColor(Color color, int amount) +Color DarkenColor(const Color &color, int amount) { Color newColor; - newColor.r = std::max(0, (int)color.r - amount); - newColor.g = std::max(0, (int)color.g - amount); - newColor.b = std::max(0, (int)color.b - amount); + newColor.r = std::min(255, color.r - +amount); + newColor.g = std::min(255, color.g - +amount); + newColor.b = std::min(255, color.b - +amount); return newColor; } // Quita los espacioes en un string std::string trim(const std::string &str) { - auto start = str.begin(); - while (start != str.end() && std::isspace(*start)) - { - start++; - } - - auto end = str.end(); - do - { - end--; - } while (std::distance(start, end) > 0 && std::isspace(*end)); - - return std::string(start, end + 1); + auto start = std::find_if_not(str.begin(), str.end(), ::isspace); + auto end = std::find_if_not(str.rbegin(), str.rend(), ::isspace).base(); + return (start < end ? std::string(start, end) : std::string()); } // Función de suavizado diff --git a/source/utils.h b/source/utils.h index a1fac60..c40143d 100644 --- a/source/utils.h +++ b/source/utils.h @@ -235,19 +235,19 @@ struct MusicFile double distanceSquared(int x1, int y1, int x2, int y2); // Detector de colisiones entre dos circulos -bool checkCollision(Circle &a, Circle &b); +bool checkCollision(const Circle &a, const Circle &b); // Detector de colisiones entre un circulo y un rectangulo -bool checkCollision(Circle &a, SDL_Rect &b); +bool checkCollision(const Circle &a, const SDL_Rect &b); // Detector de colisiones entre un dos rectangulos -bool checkCollision(SDL_Rect &a, SDL_Rect &b); +bool checkCollision(const SDL_Rect &a, const SDL_Rect &b); // Detector de colisiones entre un punto y un rectangulo -bool checkCollision(SDL_Point &p, SDL_Rect &r); +bool checkCollision(const SDL_Point &p, const SDL_Rect &r); // Convierte una cadena en un valor booleano -bool stringToBool(std::string str); +bool stringToBool(const std::string &str); // Convierte un valor booleano en una cadena std::string boolToString(bool value); @@ -256,25 +256,25 @@ std::string boolToString(bool value); std::string boolToOnOff(bool value); // Convierte una cadena a minusculas -std::string toLower(std::string str); +std::string toLower(const std::string &str); // Obtiene el fichero de sonido a partir de un nombre -JA_Sound_t *getSound(std::vector sounds, std::string name); +JA_Sound_t *getSound(const std::vector &sounds, const std::string &name); // Obtiene el fichero de música a partir de un nombre -JA_Music_t *getMusic(std::vector music, std::string name); +JA_Music_t *getMusic(const std::vector &music, const std::string &name); // Ordena las entradas de la tabla de records -HiScoreEntry sortHiScoreTable(HiScoreEntry entry1, HiScoreEntry entry2); +HiScoreEntry sortHiScoreTable(const HiScoreEntry &entry1, const HiScoreEntry &entry2); // Dibuja un circulo void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius); // Aclara el color -Color lightenColor(Color color, int amount); +Color lightenColor(const Color &color, int amount); // Oscurece el color -Color DarkenColor(Color color, int amount); +Color DarkenColor(const Color &color, int amount); // Quita los espacioes en un string std::string trim(const std::string &str); diff --git a/source/writer.h b/source/writer.h index 9e1419e..ba03ce4 100644 --- a/source/writer.h +++ b/source/writer.h @@ -4,7 +4,7 @@ #include #include "text.h" -// Clase Writer. Pinta texto en pantalla letra a letra a partir de una cadena y un bitmap +// Clase Writer. Pinta texto en pantalla letra a letra a partir de una cadena y un objeto Text class Writer { private: