Mes recomanacions de cppcheck aplicades
Abans de tocar unes cosetes de strings buits
This commit is contained in:
181
source/game.cpp
181
source/game.cpp
@@ -13,7 +13,7 @@
|
||||
#include "background.h" // for Background
|
||||
#include "balloon.h" // for Balloon, BALLOON_SPEED_1, BALLOON_...
|
||||
#include "bullet.h" // for Bullet, BulletType::LEFT, BulletType::RIGHT
|
||||
#include "enemy_formations.h" // for Stage, EnemyFormations, enemyIni...
|
||||
#include "balloon_formations.h" // for Stage, EnemyFormations, enemyIni...
|
||||
#include "explosions.h" // for Explosions
|
||||
#include "fade.h" // for Fade, FadeType::RANDOM_SQUARE, FADE_VEN...
|
||||
#include "global_inputs.h" // for globalInputs::check
|
||||
@@ -56,7 +56,7 @@ Game::Game(int player_id, int current_stage, bool demo, JA_Music_t *music)
|
||||
|
||||
background_ = std::make_unique<Background>(renderer_);
|
||||
explosions_ = std::make_unique<Explosions>();
|
||||
enemy_formations_ = std::make_unique<EnemyFormations>();
|
||||
balloon_formations_ = std::make_unique<BalloonFormations>();
|
||||
|
||||
// Carga los recursos
|
||||
loadMedia();
|
||||
@@ -146,7 +146,7 @@ void Game::init(int player_id)
|
||||
{
|
||||
case GameDifficulty::EASY:
|
||||
{
|
||||
default_enemy_speed_ = BALLOON_SPEED_1;
|
||||
default_balloon_speed_ = BALLOON_SPEED_1;
|
||||
difficulty_score_multiplier_ = 0.5f;
|
||||
difficulty_color_ = difficulty_easy_color;
|
||||
scoreboard_->setColor(difficulty_color_);
|
||||
@@ -155,7 +155,7 @@ void Game::init(int player_id)
|
||||
|
||||
case GameDifficulty::NORMAL:
|
||||
{
|
||||
default_enemy_speed_ = BALLOON_SPEED_1;
|
||||
default_balloon_speed_ = BALLOON_SPEED_1;
|
||||
difficulty_score_multiplier_ = 1.0f;
|
||||
difficulty_color_ = difficulty_normal_color;
|
||||
scoreboard_->setColor(scoreboard_color);
|
||||
@@ -164,7 +164,7 @@ void Game::init(int player_id)
|
||||
|
||||
case GameDifficulty::HARD:
|
||||
{
|
||||
default_enemy_speed_ = BALLOON_SPEED_5;
|
||||
default_balloon_speed_ = BALLOON_SPEED_5;
|
||||
difficulty_score_multiplier_ = 1.5f;
|
||||
difficulty_color_ = difficulty_hard_color;
|
||||
scoreboard_->setColor(difficulty_color_);
|
||||
@@ -177,7 +177,7 @@ void Game::init(int player_id)
|
||||
|
||||
// Variables para el marcador
|
||||
scoreboard_->setPos({param.scoreboard.x, param.scoreboard.y, param.scoreboard.w, param.scoreboard.h});
|
||||
for (auto &player : players_)
|
||||
for (const auto &player : players_)
|
||||
{
|
||||
scoreboard_->setName(player->getScoreBoardPanel(), player->getName());
|
||||
if (player->isWaiting())
|
||||
@@ -204,9 +204,9 @@ void Game::init(int player_id)
|
||||
time_stopped_ = false;
|
||||
time_stopped_counter_ = 0;
|
||||
counter_ = 0;
|
||||
last_enemy_deploy_ = 0;
|
||||
enemy_deploy_counter_ = 0;
|
||||
balloon_speed_ = default_enemy_speed_;
|
||||
last_ballon_deploy_ = 0;
|
||||
balloon_deploy_counter_ = 0;
|
||||
balloon_speed_ = default_balloon_speed_;
|
||||
helper_.need_coffee = false;
|
||||
helper_.need_coffee_machine = false;
|
||||
helper_.need_power_ball = false;
|
||||
@@ -237,7 +237,7 @@ void Game::init(int player_id)
|
||||
// Actualiza el numero de globos explotados según la fase de la demo
|
||||
for (int i = 0; i < current_stage_; ++i)
|
||||
{
|
||||
balloons_popped_ += enemy_formations_->getStage(i).power_to_complete;
|
||||
balloons_popped_ += balloon_formations_->getStage(i).power_to_complete;
|
||||
}
|
||||
|
||||
// Activa o no al otro jugador
|
||||
@@ -273,7 +273,7 @@ void Game::init(int player_id)
|
||||
total_power_to_complete_game_ = 0;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
total_power_to_complete_game_ += enemy_formations_->getStage(i).power_to_complete;
|
||||
total_power_to_complete_game_ += balloon_formations_->getStage(i).power_to_complete;
|
||||
}
|
||||
|
||||
// Modo grabar demo
|
||||
@@ -598,12 +598,13 @@ void Game::unloadMedia()
|
||||
}
|
||||
|
||||
// Carga el fichero de datos para la demo
|
||||
bool Game::loadDemoFile(std::string file_path, DemoKeys (*data_file)[TOTAL_DEMO_DATA])
|
||||
bool Game::loadDemoFile(const std::string &file_path, DemoKeys (*data_file)[TOTAL_DEMO_DATA])
|
||||
{
|
||||
// Indicador de éxito en la carga
|
||||
auto success = true;
|
||||
#ifdef VERBOSE
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
|
||||
#endif
|
||||
auto file = SDL_RWFromFile(file_path.c_str(), "r+b");
|
||||
if (!file)
|
||||
{ // El fichero no existe
|
||||
@@ -671,10 +672,12 @@ bool Game::loadDemoFile(std::string file_path, DemoKeys (*data_file)[TOTAL_DEMO_
|
||||
|
||||
#ifdef RECORDING
|
||||
// Guarda el fichero de datos para la demo
|
||||
bool Game::saveDemoFile(std::string file_path)
|
||||
bool Game::saveDemoFile(const std::string &file_path)
|
||||
{
|
||||
auto success = true;
|
||||
#ifdef VERBOSE
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
#endif // VERBOSE
|
||||
|
||||
auto file = SDL_RWFromFile(file_path.c_str(), "w+b");
|
||||
if (file)
|
||||
@@ -707,7 +710,7 @@ bool Game::saveDemoFile(std::string file_path)
|
||||
void Game::deployEnemyFormation()
|
||||
{
|
||||
// Solo despliega una formación enemiga si ha pasado cierto tiempo desde la última
|
||||
if (enemy_deploy_counter_ == 0)
|
||||
if (balloon_deploy_counter_ == 0)
|
||||
{
|
||||
|
||||
// En este punto se decide entre crear una powerball o una formación enemiga
|
||||
@@ -717,7 +720,7 @@ void Game::deployEnemyFormation()
|
||||
createPowerBall();
|
||||
|
||||
// Da un poco de margen para que se creen mas enemigos
|
||||
enemy_deploy_counter_ = 300;
|
||||
balloon_deploy_counter_ = 300;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -728,26 +731,26 @@ void Game::deployEnemyFormation()
|
||||
auto set = rand() % 10;
|
||||
|
||||
// Evita repetir la ultima formación enemiga desplegada
|
||||
if (set == last_enemy_deploy_)
|
||||
if (set == last_ballon_deploy_)
|
||||
{
|
||||
++set %= 10;
|
||||
}
|
||||
|
||||
last_enemy_deploy_ = set;
|
||||
last_ballon_deploy_ = set;
|
||||
|
||||
const Stage stage = enemy_formations_->getStage(current_stage_);
|
||||
const auto numEnemies = stage.enemy_pool->set[set]->number_of_enemies;
|
||||
const Stage stage = balloon_formations_->getStage(current_stage_);
|
||||
const auto numEnemies = stage.balloon_pool->set[set]->number_of_balloons;
|
||||
for (int i = 0; i < numEnemies; ++i)
|
||||
{
|
||||
createBalloon(stage.enemy_pool->set[set]->init[i].x,
|
||||
stage.enemy_pool->set[set]->init[i].y,
|
||||
stage.enemy_pool->set[set]->init[i].kind,
|
||||
stage.enemy_pool->set[set]->init[i].vel_x,
|
||||
createBalloon(stage.balloon_pool->set[set]->init[i].x,
|
||||
stage.balloon_pool->set[set]->init[i].y,
|
||||
stage.balloon_pool->set[set]->init[i].kind,
|
||||
stage.balloon_pool->set[set]->init[i].vel_x,
|
||||
balloon_speed_,
|
||||
stage.enemy_pool->set[set]->init[i].creation_counter);
|
||||
stage.balloon_pool->set[set]->init[i].creation_counter);
|
||||
}
|
||||
|
||||
enemy_deploy_counter_ = 300;
|
||||
balloon_deploy_counter_ = 300;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -762,7 +765,7 @@ void Game::increaseStageCurrentPower(int power)
|
||||
void Game::updateHiScore()
|
||||
{
|
||||
// Si la puntuación actual es mayor que la máxima puntuación
|
||||
for (auto &player : players_)
|
||||
for (const auto &player : players_)
|
||||
{
|
||||
if (player->getScore() > hi_score_.score)
|
||||
{
|
||||
@@ -826,7 +829,7 @@ void Game::renderPlayers()
|
||||
// Comprueba si hay cambio de fase y actualiza las variables
|
||||
void Game::updateStage()
|
||||
{
|
||||
if (current_power_ >= enemy_formations_->getStage(current_stage_).power_to_complete)
|
||||
if (current_power_ >= balloon_formations_->getStage(current_stage_).power_to_complete)
|
||||
{
|
||||
// Cambio de fase
|
||||
current_stage_++;
|
||||
@@ -851,7 +854,7 @@ void Game::updateStage()
|
||||
}
|
||||
JA_PlaySound(stage_change_sound_);
|
||||
stage_bitmap_counter_ = 0;
|
||||
balloon_speed_ = default_enemy_speed_;
|
||||
balloon_speed_ = default_balloon_speed_;
|
||||
setBalloonSpeed(balloon_speed_);
|
||||
screen_->flash(flash_color, 5);
|
||||
screen_->shake();
|
||||
@@ -970,7 +973,7 @@ void Game::setBalloonSpeed(float speed)
|
||||
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
|
||||
void Game::updateBalloonSpeed()
|
||||
{
|
||||
const float percent = (float)current_power_ / (float)enemy_formations_->getStage(current_stage_).power_to_complete;
|
||||
const float percent = (float)current_power_ / (float)balloon_formations_->getStage(current_stage_).power_to_complete;
|
||||
float old_balloon_speed = balloon_speed_;
|
||||
|
||||
// Comprueba si se ha de modificar la velocidad de los globos
|
||||
@@ -1013,7 +1016,7 @@ void Game::popBalloon(std::shared_ptr<Balloon> balloon)
|
||||
{
|
||||
destroyAllBalloons();
|
||||
power_ball_enabled_ = false;
|
||||
enemy_deploy_counter_ = 20;
|
||||
balloon_deploy_counter_ = 20;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1103,20 +1106,6 @@ void Game::destroyBalloon(std::shared_ptr<Balloon> &balloon)
|
||||
evaluateAndSetMenace();
|
||||
}
|
||||
|
||||
// Explosiona todos los globos
|
||||
void Game::popAllBalloons()
|
||||
{
|
||||
for (auto &balloon : balloons_)
|
||||
{
|
||||
if (balloon->canBePopped())
|
||||
{
|
||||
popBalloon(balloon);
|
||||
}
|
||||
}
|
||||
|
||||
JA_PlaySound(balloon_sound_);
|
||||
}
|
||||
|
||||
// Destruye todos los globos
|
||||
void Game::destroyAllBalloons()
|
||||
{
|
||||
@@ -1128,7 +1117,7 @@ void Game::destroyAllBalloons()
|
||||
}
|
||||
}
|
||||
|
||||
enemy_deploy_counter_ = 300;
|
||||
balloon_deploy_counter_ = 300;
|
||||
JA_PlaySound(power_ball_sound_);
|
||||
screen_->flash(flash_color, 5);
|
||||
screen_->shake();
|
||||
@@ -1160,22 +1149,6 @@ void Game::startAllBalloons()
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el número de globos activos
|
||||
int Game::countBalloons()
|
||||
{
|
||||
auto num = 0;
|
||||
|
||||
for (auto &balloon : balloons_)
|
||||
{
|
||||
if (balloon->isEnabled())
|
||||
{
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
// Vacia del vector de globos los globos que ya no sirven
|
||||
void Game::freeBalloons()
|
||||
{
|
||||
@@ -1674,9 +1647,9 @@ void Game::updateTimeStoppedCounter()
|
||||
// Actualiza la variable enemyDeployCounter
|
||||
void Game::updateEnemyDeployCounter()
|
||||
{
|
||||
if (enemy_deploy_counter_ > 0)
|
||||
if (balloon_deploy_counter_ > 0)
|
||||
{
|
||||
enemy_deploy_counter_--;
|
||||
balloon_deploy_counter_--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1888,7 +1861,7 @@ void Game::updateMenace()
|
||||
return;
|
||||
}
|
||||
|
||||
const auto stage = enemy_formations_->getStage(current_stage_);
|
||||
const auto stage = balloon_formations_->getStage(current_stage_);
|
||||
const float percent = current_power_ / stage.power_to_complete;
|
||||
const int difference = stage.max_menace - stage.min_menace;
|
||||
|
||||
@@ -2195,7 +2168,7 @@ void Game::renderMessages()
|
||||
// STAGE NUMBER
|
||||
if (stage_bitmap_counter_ < STAGE_COUNTER)
|
||||
{
|
||||
const auto stage_number = enemy_formations_->getStage(current_stage_).number;
|
||||
const auto stage_number = balloon_formations_->getStage(current_stage_).number;
|
||||
std::string text = "";
|
||||
|
||||
if (stage_number == 10)
|
||||
@@ -2315,22 +2288,19 @@ void Game::initPaths()
|
||||
const auto center_point = param.game.play_area.center_y - (BLOCK * 2);
|
||||
const auto distance = (param.game.play_area.rect.h) - (param.game.play_area.center_y - 16);
|
||||
|
||||
for (int i = 0; i < STAGE_COUNTER; ++i)
|
||||
for (int i = 0; i < first_part; ++i)
|
||||
{
|
||||
if (i < first_part)
|
||||
{
|
||||
stage_bitmap_path_[i] = (sin[(int)((i * 1.8f) + 90)] * (distance) + center_point);
|
||||
}
|
||||
stage_bitmap_path_[i] = (sin[(int)((i * 1.8f) + 90)] * (distance) + center_point);
|
||||
}
|
||||
|
||||
else if (i < second_part)
|
||||
{
|
||||
stage_bitmap_path_[i] = (int)center_point;
|
||||
}
|
||||
for (int i = first_part; i < second_part; ++i)
|
||||
{
|
||||
stage_bitmap_path_[i] = (int)center_point;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
stage_bitmap_path_[i] = (sin[(int)(((i - 149) * 1.8f) + 90)] * (center_point + 17) - 17);
|
||||
}
|
||||
for (int i = second_part; i < STAGE_COUNTER; ++i)
|
||||
{
|
||||
stage_bitmap_path_[i] = (sin[(int)(((i - 149) * 1.8f) + 90)] * (center_point + 17) - 17);
|
||||
}
|
||||
|
||||
// Letrero de GetReady
|
||||
@@ -2338,33 +2308,28 @@ void Game::initPaths()
|
||||
|
||||
const float start1 = param.game.play_area.rect.x - size;
|
||||
const float finish1 = param.game.play_area.center_x - (size / 2);
|
||||
|
||||
const float start2 = finish1;
|
||||
const float finish2 = param.game.play_area.rect.w;
|
||||
|
||||
const float distance1 = finish1 - start1;
|
||||
const float distance2 = finish2 - start2;
|
||||
const float distance2 = finish2 - finish1;
|
||||
|
||||
for (int i = 0; i < STAGE_COUNTER; ++i)
|
||||
for (int i = 0; i < first_part; ++i)
|
||||
{
|
||||
if (i < first_part)
|
||||
{
|
||||
get_ready_bitmap_path_[i] = sin[(int)(i * 1.8f)];
|
||||
get_ready_bitmap_path_[i] *= distance1;
|
||||
get_ready_bitmap_path_[i] -= size;
|
||||
}
|
||||
get_ready_bitmap_path_[i] = sin[(int)(i * 1.8f)];
|
||||
get_ready_bitmap_path_[i] *= distance1;
|
||||
get_ready_bitmap_path_[i] -= size;
|
||||
}
|
||||
|
||||
else if (i < second_part)
|
||||
{
|
||||
get_ready_bitmap_path_[i] = (int)finish1;
|
||||
}
|
||||
for (int i = first_part; i < second_part; ++i)
|
||||
{
|
||||
get_ready_bitmap_path_[i] = (int)finish1;
|
||||
}
|
||||
|
||||
else if (i < STAGE_COUNTER)
|
||||
{
|
||||
get_ready_bitmap_path_[i] = sin[(int)((i - second_part) * 1.8f)];
|
||||
get_ready_bitmap_path_[i] *= distance2;
|
||||
get_ready_bitmap_path_[i] += finish1;
|
||||
}
|
||||
for (int i = second_part; i < STAGE_COUNTER; ++i)
|
||||
{
|
||||
get_ready_bitmap_path_[i] = sin[(int)((i - second_part) * 1.8f)];
|
||||
get_ready_bitmap_path_[i] *= distance2;
|
||||
get_ready_bitmap_path_[i] += finish1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2496,16 +2461,16 @@ void Game::checkEvents()
|
||||
case SDLK_2:
|
||||
{
|
||||
const auto set = 0;
|
||||
const auto stage = enemy_formations_->getStage(0);
|
||||
const auto numEnemies = stage.enemy_pool->set[set]->number_of_enemies;
|
||||
const auto stage = balloon_formations_->getStage(0);
|
||||
const auto numEnemies = stage.balloon_pool->set[set]->number_of_balloons;
|
||||
for (int i = 0; i < numEnemies; ++i)
|
||||
{
|
||||
createBalloon(stage.enemy_pool->set[set]->init[i].x,
|
||||
stage.enemy_pool->set[set]->init[i].y,
|
||||
stage.enemy_pool->set[set]->init[i].kind,
|
||||
stage.enemy_pool->set[set]->init[i].vel_x,
|
||||
createBalloon(stage.balloon_pool->set[set]->init[i].x,
|
||||
stage.balloon_pool->set[set]->init[i].y,
|
||||
stage.balloon_pool->set[set]->init[i].kind,
|
||||
stage.balloon_pool->set[set]->init[i].vel_x,
|
||||
balloon_speed_,
|
||||
stage.enemy_pool->set[set]->init[i].creation_counter);
|
||||
stage.balloon_pool->set[set]->init[i].creation_counter);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -2608,8 +2573,8 @@ void Game::updateScoreboard()
|
||||
}
|
||||
|
||||
// Resto de marcador
|
||||
scoreboard_->setStage(enemy_formations_->getStage(current_stage_).number);
|
||||
scoreboard_->setPower((float)current_power_ / (float)enemy_formations_->getStage(current_stage_).power_to_complete);
|
||||
scoreboard_->setStage(balloon_formations_->getStage(current_stage_).number);
|
||||
scoreboard_->setPower((float)current_power_ / (float)balloon_formations_->getStage(current_stage_).power_to_complete);
|
||||
scoreboard_->setHiScore(hi_score_.score);
|
||||
scoreboard_->setHiScoreName(hi_score_.name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user