commit pa borrar lo del slowdown

This commit is contained in:
2025-07-27 19:51:02 +02:00
parent 5dc46dda5a
commit bb2d6e5d0b
5 changed files with 158 additions and 6 deletions

View File

@@ -851,12 +851,13 @@ void Game::handlePlayerCollision(std::shared_ptr<Player> &player, std::shared_pt
pauseMusic();
auto position = getCollisionPoint(player->getCollider(), balloon->getCollider());
putHitOnScreen(position);
SDL_Delay(param.game.hit_stop_ms);
hit_.disable();
resumeMusic();
//SDL_Delay(param.game.hit_stop_ms);
enableSlowMotion();
//hit_.disable();
//resumeMusic();
}
screen_->shake();
playSound("voice_no.wav");
//playSound("voice_no.wav");
player->setPlayingState(Player::State::ROLLING);
sendPlayerToTheBack(player);
if (allPlayersAreNotPlaying()) {
@@ -887,6 +888,94 @@ void Game::updateTimeStopped() {
}
}
void Game::updateSlowMotion() {
if (!slow_game_enabled && slow_phase == SlowPhase::NONE) {
return; // No hacer nada si no está activado
}
Uint32 current_time = SDL_GetTicks();
switch (slow_phase) {
case SlowPhase::NONE:
if (slow_game_enabled) {
// Iniciar fase 1: ralentizar
slow_phase = SlowPhase::SLOWING_DOWN;
original_speed = param.game.speed;
maintain_start_time = current_time; // Reutilizar para controlar tiempo de transición
}
break;
case SlowPhase::SLOWING_DOWN:
{
// Fase 1: Transición suave hacia velocidad lenta basada en TIEMPO
Uint32 transition_duration = slowing_down_duration;
Uint32 elapsed = current_time - maintain_start_time;
if (elapsed < transition_duration) {
float progress = (float)elapsed / transition_duration;
float smoothed_progress = easeOutCubic(progress);
param.game.speed = original_speed +
(target_slow_speed - original_speed) * smoothed_progress;
} else {
// Transición completada, pasar a fase 2
param.game.speed = target_slow_speed;
slow_phase = SlowPhase::MAINTAINING;
maintain_start_time = current_time; // Resetear para fase 2
}
}
break;
case SlowPhase::MAINTAINING:
// Fase 2: Comportamiento según la constante CENTRAL_PHASE_BEHAVIOR
if constexpr (CENTRAL_PHASE_BEHAVIOR == CentralPhaseType::SLOW_MOTION) {
// Mantener velocidad lenta durante un tiempo
if (current_time - maintain_start_time >= maintain_duration) {
// Tiempo cumplido, pasar a fase 3
slow_phase = SlowPhase::SPEEDING_UP;
maintain_start_time = current_time; // Resetear para fase 3
}
} else if constexpr (CENTRAL_PHASE_BEHAVIOR == CentralPhaseType::FREEZE_TIME) {
// Congelar el tiempo completamente
// No actualizar param.game.speed, mantenerlo "congelado"
// (se podría poner a un valor muy alto para casi pausar)
param.game.speed = 999999; // Prácticamente congela el update del juego
if (current_time - maintain_start_time >= maintain_duration) {
// Tiempo cumplido, pasar a fase 3
slow_phase = SlowPhase::SPEEDING_UP;
maintain_start_time = current_time; // Resetear para fase 3
}
}
break;
case SlowPhase::SPEEDING_UP:
{
// Fase 3: Transición suave de vuelta a velocidad normal basada en TIEMPO
Uint32 transition_duration = speeding_up_duration;
Uint32 elapsed = current_time - maintain_start_time;
if (elapsed < transition_duration) {
float progress = (float)elapsed / transition_duration;
float smoothed_progress = easeInCubic(progress);
param.game.speed = target_slow_speed +
(original_speed - target_slow_speed) * smoothed_progress;
} else {
// Transición completada, finalizar
param.game.speed = original_speed;
slow_phase = SlowPhase::NONE;
slow_game_enabled = false; // Resetear flag
hit_.disable();
resumeMusic();
playSound("voice_no.wav");
}
}
break;
}
}
// Actualiza el juego
void Game::update() {
if (SDL_GetTicks() - ticks_ > param.game.speed) {
@@ -902,6 +991,8 @@ void Game::update() {
fillCanvas();
}
updateSlowMotion();
static const auto audio = Audio::get();
audio->update();
}
@@ -1899,8 +1990,10 @@ void Game::checkDebugEvents(const SDL_Event &event) {
switch (event.key.key) {
case SDLK_1: // Crea una powerball
{
enableSlowMotion();
// balloon_manager_->createPowerBall();
throwCoffee(players_.at(0)->getPosX() + (players_.at(0)->getWidth() / 2), players_.at(0)->getPosY() + (players_.at(0)->getHeight() / 2));
//throwCoffee(players_.at(0)->getPosX() + (players_.at(0)->getWidth() / 2), players_.at(0)->getPosY() + (players_.at(0)->getHeight() / 2));
break;
}
case SDLK_2: // Activa o desactiva la aparición de globos