revisant title.cpp (falla el jugador)
This commit is contained in:
@@ -46,6 +46,7 @@ Title::Title()
|
||||
num_controllers_(Input::get()->getNumGamepads()) {
|
||||
// Configura objetos
|
||||
tiled_bg_->setColor(param.title.bg_color);
|
||||
tiled_bg_->setSpeed(60.0F); // Set appropriate speed for seconds-based deltaTime
|
||||
game_logo_->enable();
|
||||
mini_logo_sprite_->setX(param.game.game_area.center_x - (mini_logo_sprite_->getWidth() / 2));
|
||||
fade_->setColor(param.fade.color);
|
||||
@@ -82,7 +83,7 @@ void Title::update(float deltaTime) {
|
||||
Screen::get()->update();
|
||||
updateFade();
|
||||
updateState(deltaTime);
|
||||
updateStartPrompt();
|
||||
updateStartPrompt(deltaTime);
|
||||
|
||||
for (auto& player : players_) {
|
||||
player->update(deltaTime);
|
||||
@@ -94,7 +95,7 @@ void Title::update(float deltaTime) {
|
||||
// Calcula el tiempo transcurrido desde el último frame
|
||||
float Title::calculateDeltaTime() {
|
||||
const Uint64 current_time = SDL_GetTicks();
|
||||
const float delta_time = static_cast<float>(current_time - last_time_);
|
||||
const float delta_time = static_cast<float>(current_time - last_time_) / 1000.0f; // Convert ms to seconds
|
||||
last_time_ = current_time;
|
||||
return delta_time;
|
||||
}
|
||||
@@ -403,7 +404,7 @@ void Title::updateState(float deltaTime) {
|
||||
case State::START_HAS_BEEN_PRESSED: {
|
||||
counter_time_ += deltaTime;
|
||||
|
||||
if (counter_time_ >= START_PRESSED_DELAY_MS) {
|
||||
if (counter_time_ >= START_PRESSED_DELAY_S) {
|
||||
fade_->activate();
|
||||
}
|
||||
break;
|
||||
@@ -414,23 +415,38 @@ void Title::updateState(float deltaTime) {
|
||||
}
|
||||
}
|
||||
|
||||
void Title::updateStartPrompt() {
|
||||
Uint32 time_ms = SDL_GetTicks();
|
||||
void Title::updateStartPrompt(float deltaTime) {
|
||||
blink_accumulator_ += deltaTime;
|
||||
|
||||
bool condition_met = false;
|
||||
float period = 0.0f;
|
||||
float on_time = 0.0f;
|
||||
|
||||
switch (state_) {
|
||||
case State::LOGO_FINISHED:
|
||||
condition_met = (time_ms % LOGO_BLINK_PERIOD_MS) >= (LOGO_BLINK_PERIOD_MS - LOGO_BLINK_ON_TIME_MS);
|
||||
period = LOGO_BLINK_PERIOD_S;
|
||||
on_time = LOGO_BLINK_ON_TIME_S;
|
||||
break;
|
||||
|
||||
case State::START_HAS_BEEN_PRESSED:
|
||||
condition_met = (time_ms % START_BLINK_PERIOD_MS) >= (START_BLINK_PERIOD_MS - START_BLINK_ON_TIME_MS);
|
||||
period = START_BLINK_PERIOD_S;
|
||||
on_time = START_BLINK_ON_TIME_S;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (period > 0.0f) {
|
||||
// Reset accumulator when it exceeds the period
|
||||
if (blink_accumulator_ >= period) {
|
||||
blink_accumulator_ -= period;
|
||||
}
|
||||
|
||||
// Check if we're in the "on" time of the blink cycle
|
||||
condition_met = blink_accumulator_ >= (period - on_time);
|
||||
}
|
||||
|
||||
should_render_start_prompt_ = condition_met;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user