posant ordre en Stage i Background
This commit is contained in:
@@ -42,7 +42,7 @@
|
||||
#include "texture.h" // Para Texture
|
||||
#include "ui/service_menu.h" // Para ServiceMenu
|
||||
#ifdef _DEBUG
|
||||
#include <iostream> // Para Notifier
|
||||
#include <iostream> // Para std::cout
|
||||
|
||||
#include "ui/notifier.h" // Para Notifier
|
||||
#endif
|
||||
@@ -55,9 +55,10 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
||||
background_(std::make_unique<Background>()),
|
||||
canvas_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.play_area.rect.w, param.game.play_area.rect.h)),
|
||||
pause_manager_(std::make_unique<PauseManager>([this](bool is_paused) { onPauseStateChanged(is_paused); })),
|
||||
stage_manager_(std::make_unique<StageManager>()),
|
||||
fade_in_(std::make_unique<Fade>()),
|
||||
fade_out_(std::make_unique<Fade>()),
|
||||
balloon_manager_(std::make_unique<BalloonManager>()),
|
||||
balloon_manager_(std::make_unique<BalloonManager>(stage_manager_.get())),
|
||||
tabe_(std::make_unique<Tabe>()),
|
||||
hit_(Hit(Resource::get()->getTexture("hit.png"))) {
|
||||
// Pasa variables
|
||||
@@ -66,8 +67,8 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
||||
// Otras variables
|
||||
Section::name = Section::Name::GAME;
|
||||
Section::options = Section::Options::NONE;
|
||||
Stage::init();
|
||||
Stage::number = current_stage;
|
||||
stage_manager_->initialize();
|
||||
stage_manager_->jumpToStage(current_stage);
|
||||
|
||||
// Asigna texturas y animaciones
|
||||
setResources();
|
||||
@@ -99,7 +100,6 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
||||
initDifficultyVars();
|
||||
initDemo(player_id);
|
||||
initPaths();
|
||||
setTotalPower();
|
||||
|
||||
// Registra callbacks
|
||||
ServiceMenu::get()->setStateChangeCallback([this](bool is_active) {
|
||||
@@ -109,14 +109,14 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
||||
}
|
||||
});
|
||||
|
||||
#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;
|
||||
/* #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
|
||||
#endif */
|
||||
}
|
||||
|
||||
Game::~Game() {
|
||||
@@ -260,7 +260,7 @@ void Game::renderPlayers() {
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba si hay cambio de fase y actualiza las variables
|
||||
/* // 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
|
||||
@@ -289,6 +289,64 @@ void Game::updateStage() {
|
||||
background_->setAlpha(96);
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
// Comprueba si hay cambio de fase y actualiza las variables
|
||||
void Game::updateStage() {
|
||||
if (!stage_manager_->isCurrentStageCompleted()) {
|
||||
return; // No hay cambio de fase
|
||||
}
|
||||
|
||||
// Calcular poder sobrante antes de avanzar
|
||||
int power_overflow = 0;
|
||||
auto current_stage = stage_manager_->getCurrentStage();
|
||||
if (current_stage.has_value()) {
|
||||
int current_power = stage_manager_->getCurrentPower();
|
||||
int power_needed = current_stage->getPowerToComplete();
|
||||
power_overflow = current_power - power_needed; // Poder que sobra
|
||||
}
|
||||
|
||||
// Intentar avanzar a la siguiente fase
|
||||
if (!stage_manager_->advanceToNextStage()) {
|
||||
// No se pudo avanzar (probablemente juego completado)
|
||||
return;
|
||||
}
|
||||
|
||||
// Aplicar el poder sobrante a la nueva fase
|
||||
if (power_overflow > 0) {
|
||||
stage_manager_->addPower(power_overflow);
|
||||
}
|
||||
|
||||
// Efectos de cambio de fase
|
||||
playSound("stage_change.wav");
|
||||
balloon_manager_->resetBalloonSpeed();
|
||||
screen_->flash(FLASH_COLOR, 3);
|
||||
screen_->shake();
|
||||
|
||||
// Obtener datos de la nueva fase
|
||||
size_t current_stage_index = stage_manager_->getCurrentStageIndex();
|
||||
size_t total_stages = stage_manager_->getTotalStages();
|
||||
|
||||
// Escribir texto por pantalla
|
||||
if (current_stage_index < total_stages - 1) { // No es la última fase
|
||||
std::vector<Path> paths = {paths_.at(2), paths_.at(3)};
|
||||
|
||||
if (current_stage_index == total_stages - 2) { // Penúltima fase (será la última)
|
||||
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(total_stages - current_stage_index) +
|
||||
Lang::getText("[GAME_TEXT] 2A");
|
||||
createMessage(paths, text->writeToTexture(CAPTION, 1, -4));
|
||||
}
|
||||
}
|
||||
|
||||
// Modificar color de fondo en la última fase
|
||||
if (current_stage_index == total_stages - 1) { // Última fase
|
||||
background_->setColor(Color(0xdd, 0x19, 0x1d).DARKEN());
|
||||
background_->setAlpha(96);
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el estado de fin de la partida
|
||||
@@ -363,11 +421,11 @@ 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
|
||||
// Stage::number = 9; // Deja el valor dentro de los limites
|
||||
balloon_manager_->destroyAllBalloons(); // Destruye a todos los globos
|
||||
playSound("power_ball_explosion.wav");
|
||||
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
|
||||
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
|
||||
}
|
||||
|
||||
@@ -409,8 +467,10 @@ void Game::updateGameStateCompleted() {
|
||||
|
||||
// Comprueba el estado del juego
|
||||
void Game::checkState() {
|
||||
if (state_ != State::COMPLETED && Stage::number == 10) {
|
||||
// if (state_ != State::COMPLETED && Stage::number == 10) {
|
||||
if (state_ != State::COMPLETED && stage_manager_->isGameCompleted()) {
|
||||
setState(State::COMPLETED);
|
||||
background_->setState(Background::State::COMPLETED);
|
||||
}
|
||||
|
||||
if (state_ != State::GAME_OVER && allPlayersAreGameOver()) {
|
||||
@@ -876,7 +936,8 @@ 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::power_can_be_added = false; // No se puede subir poder de fase si no hay nadie jugando
|
||||
stage_manager_->disablePowerCollection();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -961,6 +1022,8 @@ 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;
|
||||
@@ -969,7 +1032,7 @@ void Game::updateBackground() {
|
||||
// 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_));
|
||||
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
|
||||
@@ -982,7 +1045,7 @@ void Game::updateBackground() {
|
||||
// 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_));
|
||||
background_->setMoonProgression(Stage::total_power / static_cast<float>(total_power_to_complete_game)); */
|
||||
|
||||
// Actualiza el objeto
|
||||
background_->update();
|
||||
@@ -1166,12 +1229,11 @@ void Game::updateScoreboard() {
|
||||
}
|
||||
|
||||
// Resto de marcador
|
||||
scoreboard_->setStage(Stage::number + 1);
|
||||
scoreboard_->setPower((float)Stage::power / (float)Stage::get(Stage::number).power_to_complete);
|
||||
scoreboard_->setStage(stage_manager_->getCurrentStageIndex() + 1);
|
||||
scoreboard_->setPower(stage_manager_->getCurrentStageProgressFraction());
|
||||
scoreboard_->setHiScore(hi_score_.score);
|
||||
scoreboard_->setHiScoreName(hi_score_.name);
|
||||
|
||||
// Lógica del marcador
|
||||
scoreboard_->update();
|
||||
}
|
||||
|
||||
@@ -1488,13 +1550,14 @@ void Game::initDemo(Player::Id player_id) {
|
||||
constexpr auto NUM_DEMOS = 3;
|
||||
const auto DEMO = rand() % NUM_DEMOS;
|
||||
constexpr std::array<int, NUM_DEMOS> STAGES = {0, 3, 5};
|
||||
Stage::number = STAGES[DEMO];
|
||||
// Stage::number = STAGES[DEMO];
|
||||
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) {
|
||||
/* 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) {
|
||||
@@ -1529,14 +1592,6 @@ void Game::initDemo(Player::Id player_id) {
|
||||
demo_.counter = 0;
|
||||
}
|
||||
|
||||
// Calcula el poder total necesario para completar el juego
|
||||
void Game::setTotalPower() {
|
||||
total_power_to_complete_game_ = 0;
|
||||
for (const auto &stage : Stage::stages) {
|
||||
total_power_to_complete_game_ += stage.power_to_complete;
|
||||
}
|
||||
}
|
||||
|
||||
// Inicializa el marcador
|
||||
void Game::initScoreboard() {
|
||||
scoreboard_->setPos(param.scoreboard.rect);
|
||||
@@ -1596,6 +1651,7 @@ void Game::initPlayers(Player::Id player_id) {
|
||||
config_player1.animations = player_animations_;
|
||||
config_player1.hi_score_table = &Options::settings.hi_score_table;
|
||||
config_player1.glowing_entry = &Options::settings.glowing_entries.at(static_cast<int>(Player::Id::PLAYER1) - 1);
|
||||
config_player1.stage_info = stage_manager_.get();
|
||||
|
||||
auto player1 = std::make_unique<Player>(config_player1);
|
||||
player1->setScoreBoardPanel(Scoreboard::Id::LEFT);
|
||||
@@ -1616,6 +1672,7 @@ void Game::initPlayers(Player::Id player_id) {
|
||||
config_player2.animations = player_animations_;
|
||||
config_player2.hi_score_table = &Options::settings.hi_score_table;
|
||||
config_player2.glowing_entry = &Options::settings.glowing_entries.at(static_cast<int>(Player::Id::PLAYER2) - 1);
|
||||
config_player2.stage_info = stage_manager_.get();
|
||||
|
||||
auto player2 = std::make_unique<Player>(config_player2);
|
||||
player2->setScoreBoardPanel(Scoreboard::Id::RIGHT);
|
||||
@@ -1755,7 +1812,8 @@ void Game::updateGameStateShowingGetReadyMessage() {
|
||||
void Game::updateGameStatePlaying() {
|
||||
#ifdef _DEBUG
|
||||
if (auto_pop_balloons_) {
|
||||
Stage::addPower(5);
|
||||
// Stage::addPower(5);
|
||||
stage_manager_->addPower(5);
|
||||
}
|
||||
#endif
|
||||
updatePlayers();
|
||||
@@ -1787,7 +1845,7 @@ void Game::cleanVectors() {
|
||||
freePathSprites();
|
||||
}
|
||||
|
||||
// Gestiona el nivel de amenaza
|
||||
/* // Gestiona el nivel de amenaza
|
||||
void Game::updateMenace() {
|
||||
if (state_ == State::PLAYING) {
|
||||
const auto STAGE = Stage::get(Stage::number);
|
||||
@@ -1803,6 +1861,30 @@ void Game::updateMenace() {
|
||||
evaluateAndSetMenace(); // Recalcula el nivel de amenaza con el nuevo globo
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
// Gestiona el nivel de amenaza
|
||||
void Game::updateMenace() {
|
||||
if (state_ != State::PLAYING) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto current_stage = stage_manager_->getCurrentStage();
|
||||
if (!current_stage.has_value()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &stage = current_stage.value();
|
||||
const double fraction = stage_manager_->getCurrentStageProgressFraction();
|
||||
const int difference = stage.getMaxMenace() - stage.getMinMenace();
|
||||
|
||||
// Aumenta el nivel de amenaza en función del progreso de la fase
|
||||
menace_threshold_ = stage.getMinMenace() + (difference * fraction);
|
||||
|
||||
if (menace_current_ < menace_threshold_) {
|
||||
balloon_manager_->deployRandomFormation(stage_manager_->getCurrentStageIndex());
|
||||
evaluateAndSetMenace();
|
||||
}
|
||||
}
|
||||
|
||||
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
||||
@@ -1816,7 +1898,8 @@ void Game::checkAndUpdateBalloonSpeed() {
|
||||
return;
|
||||
}
|
||||
|
||||
const float PERCENT = static_cast<float>(Stage::power) / Stage::get(Stage::number).power_to_complete;
|
||||
// const float PERCENT = static_cast<float>(Stage::power) / Stage::get(Stage::number).power_to_complete;
|
||||
const float PERCENT = stage_manager_->getCurrentStageProgressPercentage();
|
||||
constexpr std::array<float, 4> THRESHOLDS = {0.2F, 0.4F, 0.6F, 0.8F};
|
||||
|
||||
for (size_t i = 0; i < std::size(THRESHOLDS); ++i) {
|
||||
|
||||
Reference in New Issue
Block a user