Compare commits
2 Commits
efe8628a3c
...
a0fb6934b0
| Author | SHA1 | Date | |
|---|---|---|---|
| a0fb6934b0 | |||
| 19645445b2 |
@@ -208,6 +208,7 @@ void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon> &balloon,
|
|||||||
Balloon::Config config = {
|
Balloon::Config config = {
|
||||||
.x = std::clamp(X - (CHILD_WIDTH / 2), MIN_X, MAX_X),
|
.x = std::clamp(X - (CHILD_WIDTH / 2), MIN_X, MAX_X),
|
||||||
.y = balloon->getPosY() + ((PARENT_HEIGHT - CHILD_HEIGHT) / 2),
|
.y = balloon->getPosY() + ((PARENT_HEIGHT - CHILD_HEIGHT) / 2),
|
||||||
|
.type = balloon->getType(),
|
||||||
.size = static_cast<Balloon::Size>(static_cast<int>(balloon->getSize()) - 1),
|
.size = static_cast<Balloon::Size>(static_cast<int>(balloon->getSize()) - 1),
|
||||||
.vel_x = direction == "LEFT" ? Balloon::VELX_NEGATIVE : Balloon::VELX_POSITIVE,
|
.vel_x = direction == "LEFT" ? Balloon::VELX_NEGATIVE : Balloon::VELX_POSITIVE,
|
||||||
.game_tempo = balloon_speed_,
|
.game_tempo = balloon_speed_,
|
||||||
|
|||||||
@@ -1551,8 +1551,9 @@ void Game::initDemo(Player::Id player_id) {
|
|||||||
// Selecciona una pantalla al azar
|
// Selecciona una pantalla al azar
|
||||||
constexpr auto NUM_STAGES = 3;
|
constexpr auto NUM_STAGES = 3;
|
||||||
const auto STAGE = rand() % NUM_STAGES;
|
const auto STAGE = rand() % NUM_STAGES;
|
||||||
constexpr std::array<int, NUM_STAGES> STAGES = {0, 3, 5};
|
constexpr std::array<float, NUM_STAGES> STAGES = {0.005F, 0.32F, 0.53F};
|
||||||
stage_manager_->jumpToStage(STAGES.at(STAGE));
|
stage_manager_->setTotalPower(stage_manager_->getTotalPowerNeededToCompleteGame() * STAGES.at(STAGE));
|
||||||
|
background_->setProgress(stage_manager_->getTotalPower());
|
||||||
|
|
||||||
// Activa o no al otro jugador
|
// Activa o no al otro jugador
|
||||||
if (rand() % 3 != 0) {
|
if (rand() % 3 != 0) {
|
||||||
|
|||||||
@@ -151,6 +151,51 @@ auto StageManager::jumpToStage(size_t target_stage_index) -> bool {
|
|||||||
return true;
|
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 {
|
auto StageManager::subtractPower(int amount) -> bool {
|
||||||
if (amount <= 0 || current_power_ < amount) {
|
if (amount <= 0 || current_power_ < amount) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ class StageManager : public IStageInfo {
|
|||||||
|
|
||||||
// --- Navegación ---
|
// --- Navegación ---
|
||||||
auto jumpToStage(size_t target_stage_index) -> bool; // Salta a una fase específica
|
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 ---
|
// --- Consultas de estado ---
|
||||||
[[nodiscard]] auto getCurrentStage() const -> std::optional<StageData>; // Obtiene la fase actual
|
[[nodiscard]] auto getCurrentStage() const -> std::optional<StageData>; // Obtiene la fase actual
|
||||||
|
|||||||
Reference in New Issue
Block a user