game.cpp: llevat codi comentat mort de feia temps

This commit is contained in:
2025-08-14 13:58:24 +02:00
parent ca6edcccc0
commit 3e68afa4be

View File

@@ -109,15 +109,6 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
pause_manager_->setServiceMenuPause(is_active);
}
});
/* #ifdef _DEBUG
// Si se empieza en una fase que no es la primera
if (!demo_.enabled) {
for (int i = 0; i < Stage::number; ++i) {
Stage::total_power += Stage::get(i).power_to_complete;
}
}
#endif */
}
Game::~Game() {
@@ -262,37 +253,6 @@ void Game::renderPlayers() {
}
}
/* // Comprueba si hay cambio de fase y actualiza las variables
void Game::updateStage() {
if (Stage::power >= Stage::get(Stage::number).power_to_complete) {
// Cambio de fase
Stage::power = Stage::get(Stage::number).power_to_complete - Stage::power;
++Stage::number;
playSound("stage_change.wav");
balloon_manager_->resetBalloonSpeed();
screen_->flash(FLASH_COLOR, 3);
screen_->shake();
// Escribe el texto por pantalla
if (Stage::number < 10) {
std::vector<Path> paths = {paths_.at(2), paths_.at(3)};
if (Stage::number == 9) {
createMessage(paths, Resource::get()->getTexture("game_text_last_stage"));
} else {
auto text = Resource::get()->getText("04b_25_2x");
const std::string CAPTION = Lang::getText("[GAME_TEXT] 2") + std::to_string(10 - Stage::number) + Lang::getText("[GAME_TEXT] 2A");
createMessage(paths, text->writeToTexture(CAPTION, 1, -4));
}
}
// Modifica el color de fondo al llegar a la Fase 10
if (Stage::number == 9) {
background_->setColor(Color(0xdd, 0x19, 0x1d).DARKEN());
background_->setAlpha(96);
}
}
} */
// Comprueba si hay cambio de fase y actualiza las variables
void Game::updateStage() {
if (!stage_manager_->isCurrentStageCompleted()) {
@@ -390,11 +350,9 @@ void Game::updateGameStateGameOver() {
if (fade_out_->hasEnded()) {
if (game_completed_counter_ > 0) {
// Los jugadores han completado el juego
Section::name = Section::Name::CREDITS;
Section::name = Section::Name::CREDITS; // Los jugadores han completado el juego
} else {
// La partida ha terminado con la derrota de los jugadores
Section::name = Section::Name::HI_SCORE_TABLE;
Section::name = Section::Name::HI_SCORE_TABLE; // La partida ha terminado con la derrota de los jugadores
}
Section::options = Section::Options::HI_SCORE_AFTER_PLAYING;
if (Options::audio.enabled) {
@@ -422,12 +380,10 @@ void Game::updateGameStateCompleted() {
// Para la música y elimina todos los globos e items
if (game_completed_counter_ == 0) {
stopMusic();
// Stage::number = 9; // Deja el valor dentro de los limites
stopMusic(); // Detiene la música
balloon_manager_->destroyAllBalloons(); // Destruye a todos los globos
playSound("power_ball_explosion.wav");
playSound("power_ball_explosion.wav"); // Sonido de destruir todos los globos
destroyAllItems(); // Destruye todos los items
// Stage::power = 0; // Vuelve a dejar el poder a cero, por lo que hubiera podido subir al destruir todos los globos
background_->setAlpha(0); // Elimina el tono rojo de las últimas pantallas
}
@@ -585,11 +541,11 @@ void Game::checkBulletCollision() {
}
if (checkBulletTabeCollision(bullet)) {
break; // Exit early if bullet hit Tabe
break;
}
if (checkBulletBalloonCollision(bullet)) {
break; // Exit early if bullet hit balloon
break;
}
}
}
@@ -914,8 +870,7 @@ void Game::renderPathSprites() {
// Acciones a realizar cuando el jugador colisiona con un globo
void Game::handlePlayerCollision(std::shared_ptr<Player> &player, std::shared_ptr<Balloon> &balloon) {
if (!player->isPlaying() || player->isInvulnerable()) {
// Si no está jugando o tiene inmunidad, no hace nada
return;
return; // Si no está jugando o tiene inmunidad, no hace nada
}
// Si tiene cafes
@@ -938,7 +893,6 @@ void Game::handlePlayerCollision(std::shared_ptr<Player> &player, std::shared_pt
player->setPlayingState(Player::State::ROLLING);
sendPlayerToTheBack(player);
if (allPlayersAreNotPlaying()) {
// Stage::power_can_be_added = false; // No se puede subir poder de fase si no hay nadie jugando
stage_manager_->disablePowerCollection();
}
}
@@ -1024,38 +978,12 @@ void Game::updateGameStates() {
// Actualiza el fondo
void Game::updateBackground() {
/* static const auto total_power_to_complete_game = stage_manager_->getTotalPowerNeededToCompleteGame();
// Si el juego está completado, se reduce la velocidad de las nubes
if (state_ == State::COMPLETED) {
Stage::total_power = (Stage::total_power > 200) ? (Stage::total_power - 25) : 200;
}
// Calcula la velocidad en función de los globos explotados y el total de globos a explotar para acabar el juego
constexpr float CLOUDS_INITIAL_SPEED = 0.05F;
constexpr float CLOUDS_FINAL_SPEED = 2.00F - CLOUDS_INITIAL_SPEED;
const float CLOUDS_SPEED = (-CLOUDS_INITIAL_SPEED) + (-CLOUDS_FINAL_SPEED * (static_cast<float>(Stage::total_power) / total_power_to_complete_game));
background_->setCloudsSpeed(CLOUDS_SPEED);
// Calcula la transición de los diferentes fondos
constexpr float NUM = 1525.0F; // total_power_to_complete div 4
const float GRADIENT_NUMBER = std::min(Stage::total_power / NUM, 3.0F);
const float PERCENT = GRADIENT_NUMBER - static_cast<int>(GRADIENT_NUMBER);
background_->setGradientNumber(static_cast<int>(GRADIENT_NUMBER));
background_->setTransition(PERCENT);
// Calcula la posición del sol
constexpr float SUN_FINAL_POWER = NUM * 2;
background_->setSunProgression(Stage::total_power / SUN_FINAL_POWER);
background_->setMoonProgression(Stage::total_power / static_cast<float>(total_power_to_complete_game)); */
// Actualiza el objeto
background_->update();
}
// Dibuja los elementos de la zona de juego en su textura
void Game::fillCanvas() {
// Dibujamos el contenido de la zona de juego en su textura
// Dibuja el contenido de la zona de juego en su textura
auto *temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, canvas_);
@@ -1559,11 +1487,6 @@ void Game::initDemo(Player::Id player_id) {
stage_manager_->jumpToStage(STAGES.at(DEMO));
}
// Actualiza el numero de globos explotados según la fase del modo demostración
/* for (int i = 0; i < Stage::number; ++i) {
Stage::total_power += Stage::get(i).power_to_complete;
} */
// Activa o no al otro jugador
if (rand() % 3 != 0) {
const auto OTHER_PLAYER_ID = player_id == Player::Id::PLAYER1 ? Player::Id::PLAYER2 : Player::Id::PLAYER1;