corregit: en el mode demo no calculava correctament el estat del fondo

This commit is contained in:
2025-09-30 09:56:32 +02:00
parent 19645445b2
commit a0fb6934b0
3 changed files with 49 additions and 2 deletions

View File

@@ -1551,8 +1551,9 @@ void Game::initDemo(Player::Id player_id) {
// Selecciona una pantalla al azar
constexpr auto NUM_STAGES = 3;
const auto STAGE = rand() % NUM_STAGES;
constexpr std::array<int, NUM_STAGES> STAGES = {0, 2, 4};
stage_manager_->jumpToStage(STAGES.at(STAGE));
constexpr std::array<float, NUM_STAGES> STAGES = {0.005F, 0.32F, 0.53F};
stage_manager_->setTotalPower(stage_manager_->getTotalPowerNeededToCompleteGame() * STAGES.at(STAGE));
background_->setProgress(stage_manager_->getTotalPower());
// Activa o no al otro jugador
if (rand() % 3 != 0) {

View File

@@ -151,6 +151,51 @@ auto StageManager::jumpToStage(size_t target_stage_index) -> bool {
return true;
}
auto StageManager::setTotalPower(int target_total_power) -> bool {
if (target_total_power < 0) {
return false;
}
int total_power_needed = getTotalPowerNeededToCompleteGame();
if (target_total_power > total_power_needed) {
return false;
}
// Calcular en qué fase debería estar y cuánto poder de esa fase
int accumulated_power = 0;
size_t target_stage_index = 0;
int target_current_power = 0;
for (size_t i = 0; i < stages_.size(); ++i) {
int stage_power = stages_[i].getPowerToComplete();
if (accumulated_power + stage_power > target_total_power) {
// El objetivo está dentro de esta fase
target_stage_index = i;
target_current_power = target_total_power - accumulated_power;
break;
}
accumulated_power += stage_power;
if (accumulated_power == target_total_power) {
// El objetivo coincide exactamente con el final de esta fase
// Mover a la siguiente fase (si existe) con power 0
target_stage_index = (i + 1 < stages_.size()) ? i + 1 : i;
target_current_power = (i + 1 < stages_.size()) ? 0 : stage_power;
break;
}
}
// Actualizar estado
current_stage_index_ = target_stage_index;
current_power_ = target_current_power;
total_power_ = target_total_power;
updateStageStatuses();
return true;
}
auto StageManager::subtractPower(int amount) -> bool {
if (amount <= 0 || current_power_ < amount) {
return false;

View File

@@ -67,6 +67,7 @@ class StageManager : public IStageInfo {
// --- Navegación ---
auto jumpToStage(size_t target_stage_index) -> bool; // Salta a una fase específica
auto setTotalPower(int target_total_power) -> bool; // Establece el poder total y ajusta fase/progreso
// --- Consultas de estado ---
[[nodiscard]] auto getCurrentStage() const -> std::optional<StageData>; // Obtiene la fase actual