migrat a deltaTime screen.cpp i notifier.cpp

This commit is contained in:
2025-09-24 18:08:50 +02:00
parent 40a2b2cc00
commit d077374883
19 changed files with 192 additions and 437 deletions

View File

@@ -105,6 +105,10 @@ void Credits::update(float deltaTime) {
const float multiplier = want_to_pass_ ? 4.0f : 1.0f;
const float adjusted_delta_time = deltaTime * multiplier;
static auto *screen = Screen::get();
screen->update(deltaTime); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
tiled_bg_->update(adjusted_delta_time);
cycleColors();
balloon_manager_->update(adjusted_delta_time);
@@ -117,9 +121,7 @@ void Credits::update(float deltaTime) {
const float frameFactor = adjusted_delta_time * 60.0f;
counter_ += frameFactor;
Screen::get()->update();
fillCanvas();
Audio::update();
}
// Dibuja Credits::en patalla
@@ -290,7 +292,7 @@ void Credits::fillCanvas() {
// Actualiza el destino de los rectangulos de las texturas (time-based)
void Credits::updateTextureDstRects(float deltaTime) {
constexpr float TEXTURE_UPDATE_INTERVAL_S = 10.0f / 60.0f; // ~0.167s (cada 10 frames)
constexpr float TEXTURE_UPDATE_INTERVAL_S = 10.0f / 60.0f; // ~0.167s (cada 10 frames)
static float texture_accumulator = 0.0f;
texture_accumulator += deltaTime;
@@ -327,8 +329,8 @@ void Credits::updateTextureDstRects(float deltaTime) {
void Credits::throwBalloons(float deltaTime) {
constexpr int SPEED = 200;
const std::vector<int> SETS = {0, 63, 25, 67, 17, 75, 13, 50};
constexpr float BALLOON_INTERVAL_S = SPEED / 60.0f; // ~3.33s (cada 200 frames)
constexpr float POWERBALL_INTERVAL_S = (SPEED * 4) / 60.0f; // ~13.33s (cada 800 frames)
constexpr float BALLOON_INTERVAL_S = SPEED / 60.0f; // ~3.33s (cada 200 frames)
constexpr float POWERBALL_INTERVAL_S = (SPEED * 4) / 60.0f; // ~13.33s (cada 800 frames)
if (counter_ > ((SETS.size() - 1) * SPEED) * 3) {
return;
@@ -422,7 +424,7 @@ void Credits::initPlayers() {
// Actualiza los rectangulos negros (time-based)
void Credits::updateBlackRects(float deltaTime) {
static float current_step_ = static_cast<float>(steps_);
constexpr float BLACK_RECT_INTERVAL_S = 4.0f / 60.0f; // ~0.067s (cada 4 frames)
constexpr float BLACK_RECT_INTERVAL_S = 4.0f / 60.0f; // ~0.067s (cada 4 frames)
static float black_rect_accumulator = 0.0f;
if (top_black_rect_.h != param.game.game_area.center_y - 1 && bottom_black_rect_.y != param.game.game_area.center_y + 1) {
@@ -485,12 +487,12 @@ void Credits::updateAllFades(float deltaTime) {
updateRedRect();
}
fade_in_->update(); // Fade ya usa tiempo interno
fade_in_->update(); // Fade ya usa tiempo interno
if (fade_in_->hasEnded()) {
Audio::get()->playMusic("credits.ogg");
}
fade_out_->update(); // Fade ya usa tiempo interno
fade_out_->update(); // Fade ya usa tiempo interno
if (fade_out_->hasEnded()) {
Section::name = Section::Name::HI_SCORE_TABLE;
}

View File

@@ -282,7 +282,7 @@ void Game::updateStage() {
// Efectos de cambio de fase
playSound("stage_change.wav");
balloon_manager_->resetBalloonSpeed();
screen_->flash(Colors::FLASH, 3);
screen_->flash(Colors::FLASH, 0.05F);
screen_->shake();
// Obtener datos de la nueva fase
@@ -635,7 +635,7 @@ void Game::updateItems(float deltaTime) {
item->update(deltaTime);
if (item->isOnFloor()) {
playSound("title.wav");
screen_->shake(1, 2, 4);
screen_->shake(1, 0.033f, 0.067f); // desp=1, delay=0.033s, length=0.067s
}
}
}
@@ -784,7 +784,7 @@ void Game::throwCoffee(int x, int y) {
smart_sprites_.back()->setWidth(param.game.item_size);
smart_sprites_.back()->setHeight(param.game.item_size);
smart_sprites_.back()->setVelX((-1.0F + ((rand() % 5) * 0.5F)) * 60.0f); // Convertir a pixels/segundo
smart_sprites_.back()->setVelY(-4.0F * 60.0f); // Convertir a pixels/segundo
smart_sprites_.back()->setVelY(-4.0F * 60.0f); // Convertir a pixels/segundo
smart_sprites_.back()->setAccelX(0.0F);
smart_sprites_.back()->setAccelY(0.2F * 60.0f * 60.0f); // Convertir a pixels/segundo² (0.2 × 60²)
smart_sprites_.back()->setDestX(x + (smart_sprites_.back()->getVelX() * 50));
@@ -859,9 +859,9 @@ void Game::handlePlayerCollision(std::shared_ptr<Player> &player, std::shared_pt
// Actualiza el estado del tiempo detenido
void Game::updateTimeStopped(float deltaTime) {
static constexpr float WARNING_THRESHOLD_S = 2.0f; // 120 frames a 60fps → segundos
static constexpr float CLOCK_SOUND_INTERVAL_S = 0.5f; // 30 frames a 60fps → segundos
static constexpr float COLOR_FLASH_INTERVAL_S = 0.25f; // 15 frames a 60fps → segundos
static constexpr float WARNING_THRESHOLD_S = 2.0f; // 120 frames a 60fps → segundos
static constexpr float CLOCK_SOUND_INTERVAL_S = 0.5f; // 30 frames a 60fps → segundos
static constexpr float COLOR_FLASH_INTERVAL_S = 0.25f; // 15 frames a 60fps → segundos
if (time_stopped_timer_ > 0) {
time_stopped_timer_ -= deltaTime;
@@ -895,7 +895,8 @@ void Game::updateTimeStopped(float deltaTime) {
// Actualiza toda la lógica del juego
void Game::update(float deltaTime) {
screen_->update();
screen_->update(deltaTime); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
updateDemo();
#ifdef RECORDING
@@ -903,8 +904,6 @@ void Game::update(float deltaTime) {
#endif
updateGameStates(deltaTime);
fillCanvas();
Audio::update();
}
// Dibuja el juego
@@ -1735,9 +1734,6 @@ void Game::updateGameStateEnteringPlayer(float deltaTime) {
// Actualiza las variables durante dicho estado
void Game::updateGameStateShowingGetReadyMessage(float deltaTime) {
updateGameStatePlaying(deltaTime);
if (path_sprites_.empty()) {
setState(State::PLAYING);
}
// Reproducir música después de ~1.67 segundos (100 frames a 60fps)
static bool music_started = false;

View File

@@ -55,15 +55,16 @@ HiScoreTable::~HiScoreTable() {
// Actualiza las variables
void HiScoreTable::update(float delta_time) {
elapsed_time_ += delta_time; // Incrementa el tiempo transcurrido
Screen::get()->update(); // Actualiza el objeto screen
static auto *screen = Screen::get();
screen->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
updateSprites(delta_time); // Actualiza las posiciones de los sprites de texto
background_->update(delta_time); // Actualiza el fondo
updateFade(delta_time); // Gestiona el fade
updateCounter(); // Gestiona el contador y sus eventos
fillTexture(); // Dibuja los sprites en la textura
Audio::update();
}
// Pinta en pantalla

View File

@@ -205,16 +205,17 @@ void Instructions::fillBackbuffer() {
// Actualiza las variables
void Instructions::update(float delta_time) {
elapsed_time_ += delta_time; // Incrementa el tiempo transcurrido
Screen::get()->update(); // Actualiza el objeto screen
elapsed_time_ += delta_time; // Incrementa el tiempo transcurrido
updateSprites(); // Actualiza los sprites
updateBackbuffer(delta_time); // Gestiona la textura con los graficos
tiled_bg_->update(delta_time); // Actualiza el mosaico de fondo
fade_->update(delta_time); // Actualiza el objeto "fade"
fillBackbuffer(); // Rellena el backbuffer
static auto *screen = Screen::get();
screen->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
Audio::update();
updateSprites(); // Actualiza los sprites
updateBackbuffer(delta_time); // Gestiona la textura con los graficos
tiled_bg_->update(delta_time); // Actualiza el mosaico de fondo
fade_->update(delta_time); // Actualiza el objeto "fade"
fillBackbuffer(); // Rellena el backbuffer
}
// Pinta en pantalla

View File

@@ -208,7 +208,9 @@ void Intro::switchText(int from_index, int to_index) {
// Actualiza las variables del objeto
void Intro::update(float delta_time) {
Screen::get()->update(); // Actualiza el objeto screen
static auto *screen = Screen::get();
screen->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto Aud
tiled_bg_->update(delta_time); // Actualiza el fondo
@@ -223,8 +225,6 @@ void Intro::update(float delta_time) {
updatePostState();
break;
}
Audio::update();
}
// Dibuja el objeto en pantalla

View File

@@ -138,10 +138,11 @@ void Logo::updateTextureColors(float delta_time) {
// Actualiza las variables
void Logo::update(float delta_time) {
elapsed_time_s_ += delta_time; // Acumula el tiempo transcurrido
elapsed_time_s_ += delta_time; // Acumula el tiempo transcurrido
Screen::get()->update(); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
static auto *screen = Screen::get();
screen->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
handleSound(); // Maneja la reproducción del sonido
updateTextureColors(delta_time); // Actualiza los colores de las texturas

View File

@@ -80,7 +80,10 @@ Title::~Title() {
// Actualiza las variables del objeto
void Title::update(float deltaTime) {
Screen::get()->update();
static auto* screen = Screen::get();
screen->update(deltaTime); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
updateFade();
updateState(deltaTime);
updateStartPrompt(deltaTime);
@@ -88,8 +91,6 @@ void Title::update(float deltaTime) {
for (auto& player : players_) {
player->update(deltaTime);
}
Audio::update();
}
// Calcula el tiempo transcurrido desde el último frame