revisat credits.cpp, player.cpp, balloon.cpp i balloon_manager.cpp
This commit is contained in:
@@ -165,10 +165,12 @@ void Player::move(float deltaTime) {
|
||||
handleContinueTimeOut();
|
||||
break;
|
||||
case State::LEAVING_SCREEN:
|
||||
handleLeavingScreen();
|
||||
updateStepCounter(deltaTime);
|
||||
handleLeavingScreen();
|
||||
break;
|
||||
case State::ENTERING_SCREEN:
|
||||
handleEnteringScreen();
|
||||
updateStepCounter(deltaTime);
|
||||
handleEnteringScreen();
|
||||
break;
|
||||
case State::CREDITS:
|
||||
handleCreditsMovement(deltaTime);
|
||||
@@ -184,22 +186,10 @@ void Player::move(float deltaTime) {
|
||||
}
|
||||
}
|
||||
|
||||
void Player::handlePlayingMovement() {
|
||||
// Mueve el jugador a derecha o izquierda
|
||||
pos_x_ += vel_x_;
|
||||
|
||||
// Si el jugador abandona el area de juego por los laterales, restaura su posición
|
||||
const float MIN_X = play_area_.x - 5;
|
||||
const float MAX_X = play_area_.w + 5 - WIDTH;
|
||||
pos_x_ = std::clamp(pos_x_, MIN_X, MAX_X);
|
||||
|
||||
shiftSprite();
|
||||
}
|
||||
|
||||
// Fase 1: Movimiento time-based durante el juego
|
||||
// Movimiento time-based durante el juego
|
||||
void Player::handlePlayingMovement(float deltaTime) {
|
||||
// Mueve el jugador a derecha o izquierda (time-based)
|
||||
pos_x_ += vel_x_ * deltaTime / (1000.0f / 60.0f);
|
||||
// Mueve el jugador a derecha o izquierda (time-based en segundos)
|
||||
pos_x_ += vel_x_ * deltaTime;
|
||||
|
||||
// Si el jugador abandona el area de juego por los laterales, restaura su posición
|
||||
const float MIN_X = play_area_.x - 5;
|
||||
@@ -286,7 +276,7 @@ void Player::handleContinueTimeOut() {
|
||||
}
|
||||
|
||||
void Player::handleLeavingScreen() {
|
||||
updateStepCounter();
|
||||
// updateStepCounter se llama desde move() con deltaTime
|
||||
setInputBasedOnPlayerId();
|
||||
|
||||
pos_x_ += vel_x_;
|
||||
@@ -301,7 +291,7 @@ void Player::handleLeavingScreen() {
|
||||
}
|
||||
|
||||
void Player::handleEnteringScreen() {
|
||||
updateStepCounter();
|
||||
// updateStepCounter se llama desde move() con deltaTime
|
||||
|
||||
switch (id_) {
|
||||
case Id::PLAYER1:
|
||||
@@ -335,22 +325,9 @@ void Player::handlePlayer2Entering() {
|
||||
}
|
||||
}
|
||||
|
||||
void Player::handleCreditsMovement() {
|
||||
pos_x_ += vel_x_ / 2.0F;
|
||||
|
||||
if (vel_x_ > 0) {
|
||||
handleCreditsRightMovement();
|
||||
} else {
|
||||
handleCreditsLeftMovement();
|
||||
}
|
||||
|
||||
updateWalkingStateForCredits();
|
||||
shiftSprite();
|
||||
}
|
||||
|
||||
// Fase 4: Movimiento general en la pantalla de créditos (time-based)
|
||||
// Movimiento general en la pantalla de créditos (time-based)
|
||||
void Player::handleCreditsMovement(float deltaTime) {
|
||||
pos_x_ += (vel_x_ / 2.0F) * deltaTime / (1000.0f / 60.0f); // Convert frame-based movement to time-based
|
||||
pos_x_ += (vel_x_ / 2.0F) * deltaTime;
|
||||
|
||||
if (vel_x_ > 0) {
|
||||
handleCreditsRightMovement();
|
||||
@@ -376,19 +353,11 @@ void Player::handleCreditsLeftMovement() {
|
||||
}
|
||||
}
|
||||
|
||||
void Player::handleWaitingMovement() {
|
||||
++waiting_counter_;
|
||||
if (waiting_counter_ == WAITING_COUNTER) {
|
||||
waiting_counter_ = 0;
|
||||
player_sprite_->resetAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 4: Controla la animación del jugador saludando (time-based)
|
||||
// Controla la animación del jugador saludando (time-based)
|
||||
void Player::handleWaitingMovement(float deltaTime) {
|
||||
waiting_time_accumulator_ += deltaTime;
|
||||
float waiting_duration = static_cast<float>(WAITING_COUNTER) * (1000.0f / 60.0f); // Convert frames to milliseconds
|
||||
if (waiting_time_accumulator_ >= waiting_duration) {
|
||||
const float WAITING_DURATION_S = static_cast<float>(WAITING_COUNTER) / 60.0f; // Convert frames to seconds
|
||||
if (waiting_time_accumulator_ >= WAITING_DURATION_S) {
|
||||
waiting_time_accumulator_ = 0.0f;
|
||||
player_sprite_->resetAnimation();
|
||||
}
|
||||
@@ -415,18 +384,11 @@ void Player::setInputBasedOnPlayerId() {
|
||||
}
|
||||
}
|
||||
|
||||
void Player::updateStepCounter() {
|
||||
++step_counter_;
|
||||
if (step_counter_ % 10 == 0) {
|
||||
playSound("walk.wav");
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 4: Incrementa o ajusta el contador de pasos (time-based)
|
||||
// Incrementa o ajusta el contador de pasos (time-based)
|
||||
void Player::updateStepCounter(float deltaTime) {
|
||||
step_time_accumulator_ += deltaTime;
|
||||
float step_interval = 10.0f / 60.0f; // 10 frames converted to seconds
|
||||
if (step_time_accumulator_ >= step_interval) {
|
||||
const float STEP_INTERVAL_S = 10.0f / 60.0f; // 10 frames converted to seconds
|
||||
if (step_time_accumulator_ >= STEP_INTERVAL_S) {
|
||||
step_time_accumulator_ = 0.0f;
|
||||
playSound("walk.wav");
|
||||
}
|
||||
@@ -435,20 +397,20 @@ void Player::updateStepCounter(float deltaTime) {
|
||||
// Pinta el jugador en pantalla
|
||||
void Player::render() {
|
||||
if (power_up_ && isPlaying()) {
|
||||
// Convertir lógica de parpadeo a deltaTime
|
||||
float total_powerup_time_ms = static_cast<float>(POWERUP_COUNTER) / 60.0f * 1000.0f; // Total time in ms
|
||||
float quarter_time_ms = total_powerup_time_ms / 4.0f; // 25% del tiempo total
|
||||
// Convertir lógica de parpadeo a deltaTime en segundos
|
||||
const float TOTAL_POWERUP_TIME_S = static_cast<float>(POWERUP_COUNTER) / 60.0f; // Total time in seconds
|
||||
const float QUARTER_TIME_S = TOTAL_POWERUP_TIME_S / 4.0f; // 25% del tiempo total
|
||||
|
||||
if (power_up_time_accumulator_ > quarter_time_ms) {
|
||||
if (power_up_time_accumulator_ > QUARTER_TIME_S) {
|
||||
// En los primeros 75% del tiempo, siempre visible
|
||||
power_sprite_->render();
|
||||
} else {
|
||||
// En el último 25%, parpadea cada 20 frames (333ms aprox)
|
||||
constexpr float blink_period_ms = 20.0f / 60.0f * 1000.0f; // 20 frames in ms
|
||||
constexpr float visible_proportion = 4.0f / 20.0f; // 4 frames visible de 20 total
|
||||
// En el último 25%, parpadea cada 20 frames (≈0.333s)
|
||||
constexpr float BLINK_PERIOD_S = 20.0f / 60.0f; // 20 frames in seconds
|
||||
constexpr float VISIBLE_PROPORTION = 4.0f / 20.0f; // 4 frames visible de 20 total
|
||||
|
||||
float cycle_position = fmod(power_up_time_accumulator_, blink_period_ms) / blink_period_ms;
|
||||
if (cycle_position >= visible_proportion) {
|
||||
float cycle_position = fmod(power_up_time_accumulator_, BLINK_PERIOD_S) / BLINK_PERIOD_S;
|
||||
if (cycle_position >= VISIBLE_PROPORTION) {
|
||||
power_sprite_->render();
|
||||
}
|
||||
}
|
||||
@@ -677,7 +639,7 @@ void Player::setPlayingState(State state) {
|
||||
case State::ROLLING: {
|
||||
// Activa la animación de rodar dando botes
|
||||
player_sprite_->setCurrentAnimation("rolling");
|
||||
player_sprite_->setAnimationSpeed(4);
|
||||
player_sprite_->setAnimationSpeed(4.0f / 60.0f); // 4 frames convertido a segundos
|
||||
player_sprite_->setVelY(-6.6F); // Velocidad inicial
|
||||
player_sprite_->setAccelY(0.2F); // Gravedad
|
||||
player_sprite_->setPosY(pos_y_ - 2); // Para "sacarlo" del suelo, ya que está hundido un pixel para ocultar el outline de los pies
|
||||
@@ -701,7 +663,7 @@ void Player::setPlayingState(State state) {
|
||||
player_sprite_->setVelY(-4.0F);
|
||||
player_sprite_->setVelX(0.0F);
|
||||
player_sprite_->setCurrentAnimation("rolling");
|
||||
player_sprite_->setAnimationSpeed(5);
|
||||
player_sprite_->setAnimationSpeed(5.0f / 60.0f); // 5 frames convertido a segundos
|
||||
setScoreboardMode(Scoreboard::Mode::GAME_OVER);
|
||||
playSound("voice_aw_aw_aw.wav");
|
||||
playSound("jump.wav");
|
||||
@@ -772,7 +734,7 @@ void Player::decScoreMultiplier() {
|
||||
void Player::setInvulnerable(bool value) {
|
||||
invulnerable_ = value;
|
||||
invulnerable_counter_ = invulnerable_ ? INVULNERABLE_COUNTER : 0;
|
||||
invulnerable_time_accumulator_ = invulnerable_ ? static_cast<float>(INVULNERABLE_COUNTER) / 60.0f * 1000.0f : 0.0f; // Convert frames to milliseconds
|
||||
invulnerable_time_accumulator_ = invulnerable_ ? static_cast<float>(INVULNERABLE_COUNTER) / 60.0f : 0.0f; // Convert frames to seconds
|
||||
}
|
||||
|
||||
// Monitoriza el estado (time-based)
|
||||
@@ -781,16 +743,16 @@ void Player::updateInvulnerable(float deltaTime) {
|
||||
if (invulnerable_time_accumulator_ > 0) {
|
||||
invulnerable_time_accumulator_ -= deltaTime;
|
||||
|
||||
// Frecuencia fija de parpadeo adaptada a deltaTime (en milisegundos)
|
||||
constexpr float blink_period_ms = 8.0f / 60.0f * 1000.0f; // 8 frames convertidos a ms
|
||||
// Frecuencia fija de parpadeo adaptada a deltaTime (en segundos)
|
||||
constexpr float BLINK_PERIOD_S = 8.0f / 60.0f; // 8 frames convertidos a segundos
|
||||
|
||||
// Calcula proporción decreciente basada en tiempo restante
|
||||
float total_invulnerable_time_ms = static_cast<float>(INVULNERABLE_COUNTER) / 60.0f * 1000.0f;
|
||||
float progress = 1.0f - (invulnerable_time_accumulator_ / total_invulnerable_time_ms);
|
||||
const float TOTAL_INVULNERABLE_TIME_S = static_cast<float>(INVULNERABLE_COUNTER) / 60.0f;
|
||||
float progress = 1.0f - (invulnerable_time_accumulator_ / TOTAL_INVULNERABLE_TIME_S);
|
||||
float white_proportion = 0.5f - progress * 0.2f; // Menos blanco hacia el final
|
||||
|
||||
// Calcula si debe mostrar textura de invulnerabilidad basado en el ciclo temporal
|
||||
float cycle_position = fmod(invulnerable_time_accumulator_, blink_period_ms) / blink_period_ms;
|
||||
float cycle_position = fmod(invulnerable_time_accumulator_, BLINK_PERIOD_S) / BLINK_PERIOD_S;
|
||||
bool should_show_invulnerable = cycle_position < white_proportion;
|
||||
size_t target_texture = should_show_invulnerable ? INVULNERABLE_TEXTURE : coffees_;
|
||||
|
||||
@@ -811,7 +773,7 @@ void Player::updateInvulnerable(float deltaTime) {
|
||||
void Player::setPowerUp() {
|
||||
power_up_ = true;
|
||||
power_up_counter_ = POWERUP_COUNTER;
|
||||
power_up_time_accumulator_ = static_cast<float>(POWERUP_COUNTER) / 60.0f * 1000.0f; // Convert frames to milliseconds
|
||||
power_up_time_accumulator_ = static_cast<float>(POWERUP_COUNTER) / 60.0f; // Convert frames to seconds
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable (time-based)
|
||||
@@ -863,9 +825,9 @@ void Player::setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &text
|
||||
void Player::updateContinueCounter(float deltaTime) {
|
||||
if (playing_state_ == State::CONTINUE) {
|
||||
continue_time_accumulator_ += deltaTime;
|
||||
constexpr float CONTINUE_INTERVAL = 1000.0f; // 1 segundo en milisegundos
|
||||
if (continue_time_accumulator_ >= CONTINUE_INTERVAL) {
|
||||
continue_time_accumulator_ -= CONTINUE_INTERVAL;
|
||||
constexpr float CONTINUE_INTERVAL_S = 1.0f; // 1 segundo
|
||||
if (continue_time_accumulator_ >= CONTINUE_INTERVAL_S) {
|
||||
continue_time_accumulator_ -= CONTINUE_INTERVAL_S;
|
||||
decContinueCounter();
|
||||
}
|
||||
}
|
||||
@@ -875,9 +837,9 @@ void Player::updateContinueCounter(float deltaTime) {
|
||||
void Player::updateEnterNameCounter(float deltaTime) {
|
||||
if (playing_state_ == State::ENTERING_NAME || playing_state_ == State::ENTERING_NAME_GAME_COMPLETED) {
|
||||
name_entry_time_accumulator_ += deltaTime;
|
||||
constexpr float NAME_ENTRY_INTERVAL = 1000.0f; // 1 segundo en milisegundos
|
||||
if (name_entry_time_accumulator_ >= NAME_ENTRY_INTERVAL) {
|
||||
name_entry_time_accumulator_ -= NAME_ENTRY_INTERVAL;
|
||||
constexpr float NAME_ENTRY_INTERVAL_S = 1.0f; // 1 segundo
|
||||
if (name_entry_time_accumulator_ >= NAME_ENTRY_INTERVAL_S) {
|
||||
name_entry_time_accumulator_ -= NAME_ENTRY_INTERVAL_S;
|
||||
decNameEntryCounter();
|
||||
}
|
||||
}
|
||||
@@ -887,8 +849,8 @@ void Player::updateEnterNameCounter(float deltaTime) {
|
||||
void Player::updateShowingName(float deltaTime) {
|
||||
if (playing_state_ == State::SHOWING_NAME) {
|
||||
showing_name_time_accumulator_ += deltaTime;
|
||||
constexpr float SHOWING_NAME_DURATION = 5000.0f; // 5 segundos en milisegundos
|
||||
if (showing_name_time_accumulator_ >= SHOWING_NAME_DURATION) {
|
||||
constexpr float SHOWING_NAME_DURATION_S = 5.0f; // 5 segundos
|
||||
if (showing_name_time_accumulator_ >= SHOWING_NAME_DURATION_S) {
|
||||
game_completed_ ? setPlayingState(State::LEAVING_SCREEN) : setPlayingState(State::CONTINUE);
|
||||
}
|
||||
}
|
||||
@@ -909,13 +871,16 @@ void Player::decContinueCounter() {
|
||||
void Player::decNameEntryCounter() {
|
||||
name_entry_time_accumulator_ = 0.0f; // Reset time accumulator
|
||||
|
||||
// Incrementa acumuladores de tiempo (1 segundo = 1000ms)
|
||||
name_entry_idle_time_accumulator_ += 1000.0f;
|
||||
name_entry_total_time_accumulator_ += 1000.0f;
|
||||
// Incrementa acumuladores de tiempo (1 segundo)
|
||||
name_entry_idle_time_accumulator_ += 1.0f;
|
||||
name_entry_total_time_accumulator_ += 1.0f;
|
||||
|
||||
// Comprueba los acumuladores directamente contra los límites en milisegundos
|
||||
if ((name_entry_total_time_accumulator_ >= param.game.name_entry_total_time) ||
|
||||
(name_entry_idle_time_accumulator_ >= param.game.name_entry_idle_time)) {
|
||||
// Convierte límites de param (milisegundos) a segundos para comparación
|
||||
const float NAME_ENTRY_TOTAL_TIME_S = param.game.name_entry_total_time / 1000.0f;
|
||||
const float NAME_ENTRY_IDLE_TIME_S = param.game.name_entry_idle_time / 1000.0f;
|
||||
|
||||
if ((name_entry_total_time_accumulator_ >= NAME_ENTRY_TOTAL_TIME_S) ||
|
||||
(name_entry_idle_time_accumulator_ >= NAME_ENTRY_IDLE_TIME_S)) {
|
||||
name_entry_total_time_accumulator_ = 0.0f;
|
||||
name_entry_idle_time_accumulator_ = 0.0f;
|
||||
if (playing_state_ == State::ENTERING_NAME) {
|
||||
@@ -1036,7 +1001,7 @@ void Player::updateVisualLine(float deltaTime) {
|
||||
// Inicia un disparo en ambas líneas
|
||||
void Player::startFiringSystem(int cooldown_frames) {
|
||||
// LÍNEA 1: Inicia cooldown funcional
|
||||
fire_cooldown_timer_ = static_cast<float>(cooldown_frames) / 60.0f * 1000.0f; // Convertir frames a ms
|
||||
fire_cooldown_timer_ = static_cast<float>(cooldown_frames) / 60.0f; // Convertir frames a segundos
|
||||
can_fire_new_system_ = false;
|
||||
|
||||
// LÍNEA 2: Resetea completamente el estado visual
|
||||
|
||||
Reference in New Issue
Block a user