delta-time: player.cpp
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_FlipMode
|
||||
|
||||
#include <algorithm> // Para clamp, max, min
|
||||
#include <cmath> // Para fmod
|
||||
#include <cstdlib> // Para rand
|
||||
|
||||
#include "animated_sprite.h" // Para AnimatedSprite
|
||||
@@ -186,6 +187,41 @@ void Player::move() {
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 1: Sistema de movimiento time-based
|
||||
void Player::move(float deltaTime) {
|
||||
switch (playing_state_) {
|
||||
case State::PLAYING:
|
||||
handlePlayingMovement(deltaTime);
|
||||
break;
|
||||
case State::ROLLING:
|
||||
handleRollingMovement(); // Usa MovingSprite que ya soporta deltaTime
|
||||
break;
|
||||
case State::TITLE_ANIMATION:
|
||||
handleTitleAnimation(); // Sin cambios - usa solo animaciones
|
||||
break;
|
||||
case State::CONTINUE_TIME_OUT:
|
||||
handleContinueTimeOut(); // Sin cambios - usa MovingSprite que ya soporta deltaTime
|
||||
break;
|
||||
case State::LEAVING_SCREEN:
|
||||
handleLeavingScreen(); // Sin cambios - usa MovingSprite que ya soporta deltaTime
|
||||
break;
|
||||
case State::ENTERING_SCREEN:
|
||||
handleEnteringScreen(); // Sin cambios - usa MovingSprite que ya soporta deltaTime
|
||||
break;
|
||||
case State::CREDITS:
|
||||
handleCreditsMovement(deltaTime); // Fase 4: Sistema de créditos time-based
|
||||
break;
|
||||
case State::WAITING:
|
||||
handleWaitingMovement(deltaTime); // Fase 4: Sistema de waiting time-based
|
||||
break;
|
||||
case State::RECOVER:
|
||||
handleRecoverMovement(); // Sin cambios - usa AnimatedSprite que ya soporta deltaTime
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::handlePlayingMovement() {
|
||||
// Mueve el jugador a derecha o izquierda
|
||||
pos_x_ += vel_x_;
|
||||
@@ -198,6 +234,19 @@ void Player::handlePlayingMovement() {
|
||||
shiftSprite();
|
||||
}
|
||||
|
||||
// Fase 1: Movimiento time-based durante el juego
|
||||
void Player::handlePlayingMovement(float deltaTime) {
|
||||
// Mueve el jugador a derecha o izquierda (time-based)
|
||||
pos_x_ += vel_x_ * 60.0f * deltaTime;
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
void Player::handleRecoverMovement() {
|
||||
if (player_sprite_->getCurrentAnimationFrame() == 10) { playSound("voice_recover.wav"); }
|
||||
if (player_sprite_->animationIsCompleted()) { setPlayingState(State::RESPAWNING); }
|
||||
@@ -337,6 +386,20 @@ void Player::handleCreditsMovement() {
|
||||
shiftSprite();
|
||||
}
|
||||
|
||||
// Fase 4: Movimiento general en la pantalla de créditos (time-based)
|
||||
void Player::handleCreditsMovement(float deltaTime) {
|
||||
pos_x_ += (vel_x_ / 2.0F) * 60.0f * deltaTime; // Convert frame-based movement to time-based
|
||||
|
||||
if (vel_x_ > 0) {
|
||||
handleCreditsRightMovement();
|
||||
} else {
|
||||
handleCreditsLeftMovement();
|
||||
}
|
||||
|
||||
updateWalkingStateForCredits();
|
||||
shiftSprite();
|
||||
}
|
||||
|
||||
void Player::handleCreditsRightMovement() {
|
||||
if (pos_x_ > param.game.game_area.rect.w - WIDTH) {
|
||||
pos_x_ = param.game.game_area.rect.w - WIDTH;
|
||||
@@ -359,6 +422,16 @@ void Player::handleWaitingMovement() {
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 4: 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) / 60.0f; // Convert frames to seconds
|
||||
if (waiting_time_accumulator_ >= waiting_duration) {
|
||||
waiting_time_accumulator_ = 0.0f;
|
||||
player_sprite_->resetAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
void Player::updateWalkingStateForCredits() {
|
||||
if (pos_x_ > param.game.game_area.center_x - WIDTH / 2) {
|
||||
setWalkingState(State::WALKING_LEFT);
|
||||
@@ -387,6 +460,16 @@ void Player::updateStepCounter() {
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 4: 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) {
|
||||
step_time_accumulator_ = 0.0f;
|
||||
playSound("walk.wav");
|
||||
}
|
||||
}
|
||||
|
||||
// Pinta el jugador en pantalla
|
||||
void Player::render() {
|
||||
if (power_up_ && isPlaying()) {
|
||||
@@ -454,7 +537,7 @@ auto Player::computeAnimation() const -> std::pair<std::string, SDL_FlipMode> {
|
||||
return {anim_name, flip_mode};
|
||||
}
|
||||
|
||||
// Establece la animación correspondiente al estado
|
||||
// Establece la animación correspondiente al estado (frame-based)
|
||||
void Player::setAnimation() {
|
||||
switch (playing_state_) {
|
||||
case State::PLAYING:
|
||||
@@ -495,7 +578,49 @@ void Player::setAnimation() {
|
||||
power_sprite_->update();
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
// Fase 1: Establece la animación correspondiente al estado (time-based)
|
||||
void Player::setAnimation(float deltaTime) {
|
||||
switch (playing_state_) {
|
||||
case State::PLAYING:
|
||||
case State::ENTERING_NAME_GAME_COMPLETED:
|
||||
case State::ENTERING_SCREEN:
|
||||
case State::LEAVING_SCREEN:
|
||||
case State::TITLE_ANIMATION:
|
||||
case State::CREDITS: {
|
||||
auto [animName, flipMode] = computeAnimation();
|
||||
player_sprite_->setCurrentAnimation(animName, false);
|
||||
player_sprite_->setFlip(flipMode);
|
||||
break;
|
||||
}
|
||||
case State::RECOVER:
|
||||
player_sprite_->setCurrentAnimation("recover");
|
||||
break;
|
||||
case State::WAITING:
|
||||
case State::GAME_OVER:
|
||||
player_sprite_->setCurrentAnimation("hello");
|
||||
break;
|
||||
case State::ROLLING:
|
||||
case State::CONTINUE_TIME_OUT:
|
||||
player_sprite_->setCurrentAnimation("rolling");
|
||||
break;
|
||||
case State::LYING_ON_THE_FLOOR_FOREVER:
|
||||
case State::ENTERING_NAME:
|
||||
case State::CONTINUE:
|
||||
player_sprite_->setCurrentAnimation("dizzy");
|
||||
break;
|
||||
case State::CELEBRATING:
|
||||
player_sprite_->setCurrentAnimation("celebration");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// La diferencia clave: usa deltaTime para las animaciones
|
||||
player_sprite_->update(deltaTime);
|
||||
power_sprite_->update(deltaTime);
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable (frame-based)
|
||||
void Player::updateCooldown() {
|
||||
if (playing_state_ != State::PLAYING) {
|
||||
return;
|
||||
@@ -508,6 +633,19 @@ void Player::updateCooldown() {
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 2: Actualiza el cooldown de disparo (time-based)
|
||||
void Player::updateCooldown(float deltaTime) {
|
||||
if (playing_state_ != State::PLAYING) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cant_fire_time_accumulator_ > 0) {
|
||||
handleFiringCooldown(deltaTime);
|
||||
} else {
|
||||
handleRecoilAndCooling(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::handleFiringCooldown() {
|
||||
cooling_state_counter_ = COOLING_DURATION;
|
||||
|
||||
@@ -522,6 +660,28 @@ void Player::handleFiringCooldown() {
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 2: Manejo de cooldown de disparo (time-based)
|
||||
void Player::handleFiringCooldown(float deltaTime) {
|
||||
cooling_time_accumulator_ = static_cast<float>(COOLING_DURATION) / 60.0f;
|
||||
|
||||
// Convertir frames a tiempo: 1 frame = 1/60 segundos
|
||||
float frameTime = 1.0f / 60.0f;
|
||||
float halfwayTime = static_cast<float>(recoiling_state_duration_) / 2.0f / 60.0f;
|
||||
|
||||
// Reducir tiempo acumulado
|
||||
cant_fire_time_accumulator_ -= deltaTime;
|
||||
|
||||
// Transition to recoiling state at halfway point
|
||||
if (cant_fire_time_accumulator_ <= halfwayTime && cant_fire_time_accumulator_ > halfwayTime - frameTime) {
|
||||
transitionToRecoiling();
|
||||
}
|
||||
|
||||
if (cant_fire_time_accumulator_ <= 0) {
|
||||
cant_fire_time_accumulator_ = 0;
|
||||
recoiling_time_accumulator_ = static_cast<float>(recoiling_state_duration_) / 60.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::handleRecoilAndCooling() {
|
||||
if (recoiling_state_counter_ > 0) {
|
||||
--recoiling_state_counter_;
|
||||
@@ -531,6 +691,16 @@ void Player::handleRecoilAndCooling() {
|
||||
handleCoolingState();
|
||||
}
|
||||
|
||||
// Fase 2: Manejo de retroceso y enfriamiento (time-based)
|
||||
void Player::handleRecoilAndCooling(float deltaTime) {
|
||||
if (recoiling_time_accumulator_ > 0) {
|
||||
recoiling_time_accumulator_ -= deltaTime;
|
||||
return;
|
||||
}
|
||||
|
||||
handleCoolingState(deltaTime);
|
||||
}
|
||||
|
||||
void Player::handleCoolingState() {
|
||||
if (cooling_state_counter_ > COOLING_COMPLETE) {
|
||||
if (cooling_state_counter_ == COOLING_DURATION) {
|
||||
@@ -544,6 +714,26 @@ void Player::handleCoolingState() {
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 2: Manejo del estado de enfriamiento (time-based)
|
||||
void Player::handleCoolingState(float deltaTime) {
|
||||
float coolingCompleteTime = static_cast<float>(COOLING_COMPLETE) / 60.0f;
|
||||
float coolingDurationTime = static_cast<float>(COOLING_DURATION) / 60.0f;
|
||||
float frameTime = 1.0f / 60.0f;
|
||||
|
||||
if (cooling_time_accumulator_ > coolingCompleteTime) {
|
||||
// Transición a cooling cuando empezamos (equivalente a == COOLING_DURATION)
|
||||
if (cooling_time_accumulator_ <= coolingDurationTime && cooling_time_accumulator_ > coolingDurationTime - frameTime) {
|
||||
transitionToCooling();
|
||||
}
|
||||
cooling_time_accumulator_ -= deltaTime;
|
||||
}
|
||||
|
||||
if (cooling_time_accumulator_ <= coolingCompleteTime) {
|
||||
cooling_time_accumulator_ = coolingCompleteTime;
|
||||
completeCooling();
|
||||
}
|
||||
}
|
||||
|
||||
void Player::transitionToRecoiling() {
|
||||
switch (firing_state_) {
|
||||
case State::FIRING_LEFT:
|
||||
@@ -595,6 +785,20 @@ void Player::update() {
|
||||
updateShowingName();
|
||||
}
|
||||
|
||||
// Fase 1-4: Método deltaTime completo
|
||||
void Player::update(float deltaTime) {
|
||||
move(deltaTime); // Sistema de movimiento time-based
|
||||
setAnimation(deltaTime); // Animaciones time-based
|
||||
shiftColliders(); // Sin cambios (posicional)
|
||||
updateCooldown(deltaTime); // Fase 2: Sistema de disparo time-based
|
||||
updatePowerUp(deltaTime); // Fase 3: Sistema de power-up time-based
|
||||
updateInvulnerable(deltaTime); // Fase 3: Sistema de invulnerabilidad time-based
|
||||
updateScoreboard(); // Sin cambios (no temporal)
|
||||
updateContinueCounter(deltaTime); // Fase 4: Sistema de continue time-based
|
||||
updateEnterNameCounter(deltaTime); // Fase 4: Sistema de name entry time-based
|
||||
updateShowingName(); // Sin cambios (no temporal)
|
||||
}
|
||||
|
||||
void Player::passShowingName() {
|
||||
if (game_completed_) {
|
||||
setPlayingState(State::LEAVING_SCREEN);
|
||||
@@ -664,6 +868,7 @@ void Player::setPlayingState(State state) {
|
||||
// Inicializa el contador de continuar
|
||||
continue_ticks_ = SDL_GetTicks();
|
||||
continue_counter_ = 9;
|
||||
continue_time_accumulator_ = 0.0f; // Initialize time accumulator
|
||||
playSound("continue_clock.wav");
|
||||
setScoreboardMode(Scoreboard::Mode::CONTINUE);
|
||||
break;
|
||||
@@ -682,6 +887,7 @@ void Player::setPlayingState(State state) {
|
||||
}
|
||||
pos_y_ = default_pos_y_;
|
||||
waiting_counter_ = 0;
|
||||
waiting_time_accumulator_ = 0.0f; // Initialize time accumulator
|
||||
shiftSprite();
|
||||
player_sprite_->setCurrentAnimation("hello");
|
||||
player_sprite_->animtionPause();
|
||||
@@ -749,12 +955,14 @@ void Player::setPlayingState(State state) {
|
||||
}
|
||||
case State::LEAVING_SCREEN: {
|
||||
step_counter_ = 0;
|
||||
step_time_accumulator_ = 0.0f; // Initialize time accumulator
|
||||
setScoreboardMode(Scoreboard::Mode::GAME_COMPLETED);
|
||||
break;
|
||||
}
|
||||
case State::ENTERING_SCREEN: {
|
||||
init();
|
||||
step_counter_ = 0;
|
||||
step_time_accumulator_ = 0.0f; // Initialize time accumulator
|
||||
setScoreboardMode(Scoreboard::Mode::SCORE);
|
||||
switch (id_) {
|
||||
case Id::PLAYER1:
|
||||
@@ -795,9 +1003,10 @@ 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 : 0.0f; // Initialize time accumulator
|
||||
}
|
||||
|
||||
// Monitoriza el estado
|
||||
// Monitoriza el estado (frame-based)
|
||||
void Player::updateInvulnerable() {
|
||||
if (playing_state_ == State::PLAYING && invulnerable_) {
|
||||
if (invulnerable_counter_ > 0) {
|
||||
@@ -827,13 +1036,46 @@ void Player::updateInvulnerable() {
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 3: Monitoriza el estado (time-based)
|
||||
void Player::updateInvulnerable(float deltaTime) {
|
||||
if (playing_state_ == State::PLAYING && invulnerable_) {
|
||||
if (invulnerable_time_accumulator_ > 0) {
|
||||
invulnerable_time_accumulator_ -= deltaTime;
|
||||
|
||||
// Frecuencia fija de parpadeo adaptada a deltaTime
|
||||
constexpr float blink_period = 8.0f / 60.0f; // 8 frames convertidos a segundos
|
||||
|
||||
// Calcula proporción decreciente basada en tiempo restante
|
||||
float total_invulnerable_time = static_cast<float>(INVULNERABLE_COUNTER) / 60.0f;
|
||||
float progress = 1.0f - (invulnerable_time_accumulator_ / total_invulnerable_time);
|
||||
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) / blink_period;
|
||||
bool should_show_invulnerable = cycle_position < white_proportion;
|
||||
size_t target_texture = should_show_invulnerable ? INVULNERABLE_TEXTURE : coffees_;
|
||||
|
||||
// Solo cambia textura si es diferente (optimización)
|
||||
if (player_sprite_->getActiveTexture() != target_texture) {
|
||||
player_sprite_->setActiveTexture(target_texture);
|
||||
}
|
||||
} else {
|
||||
// Fin de invulnerabilidad
|
||||
invulnerable_time_accumulator_ = 0;
|
||||
setInvulnerable(false);
|
||||
player_sprite_->setActiveTexture(coffees_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setPowerUp() {
|
||||
power_up_ = true;
|
||||
power_up_counter_ = POWERUP_COUNTER;
|
||||
power_up_time_accumulator_ = static_cast<float>(POWERUP_COUNTER) / 60.0f; // Initialize time accumulator
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
// Actualiza el valor de la variable (frame-based)
|
||||
void Player::updatePowerUp() {
|
||||
if (playing_state_ == State::PLAYING) {
|
||||
if (power_up_) {
|
||||
@@ -843,6 +1085,19 @@ void Player::updatePowerUp() {
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 3: Actualiza el valor de la variable (time-based)
|
||||
void Player::updatePowerUp(float deltaTime) {
|
||||
if (playing_state_ == State::PLAYING) {
|
||||
if (power_up_) {
|
||||
power_up_time_accumulator_ -= deltaTime;
|
||||
power_up_ = power_up_time_accumulator_ > 0;
|
||||
if (!power_up_) {
|
||||
power_up_time_accumulator_ = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Concede un toque extra al jugador
|
||||
void Player::giveExtraHit() {
|
||||
extra_hit_ = true;
|
||||
@@ -875,7 +1130,7 @@ void Player::setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &text
|
||||
power_sprite_->setTexture(texture[1]);
|
||||
}
|
||||
|
||||
// Actualiza el contador de continue
|
||||
// Actualiza el contador de continue (frame-based)
|
||||
void Player::updateContinueCounter() {
|
||||
if (playing_state_ == State::CONTINUE) {
|
||||
constexpr int TICKS_SPEED = 1000;
|
||||
@@ -885,7 +1140,19 @@ void Player::updateContinueCounter() {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el contador de entrar nombre
|
||||
// Fase 4: Actualiza el contador de continue (time-based)
|
||||
void Player::updateContinueCounter(float deltaTime) {
|
||||
if (playing_state_ == State::CONTINUE) {
|
||||
continue_time_accumulator_ += deltaTime;
|
||||
constexpr float CONTINUE_INTERVAL = 1.0f; // 1 segundo
|
||||
if (continue_time_accumulator_ >= CONTINUE_INTERVAL) {
|
||||
continue_time_accumulator_ -= CONTINUE_INTERVAL;
|
||||
decContinueCounter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el contador de entrar nombre (frame-based)
|
||||
void Player::updateEnterNameCounter() {
|
||||
if (playing_state_ == State::ENTERING_NAME || playing_state_ == State::ENTERING_NAME_GAME_COMPLETED) {
|
||||
constexpr int TICKS_SPEED = 1000;
|
||||
@@ -895,6 +1162,18 @@ void Player::updateEnterNameCounter() {
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 4: Actualiza el contador de entrar nombre (time-based)
|
||||
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 = 1.0f; // 1 segundo
|
||||
if (name_entry_time_accumulator_ >= NAME_ENTRY_INTERVAL) {
|
||||
name_entry_time_accumulator_ -= NAME_ENTRY_INTERVAL;
|
||||
decNameEntryCounter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el estado de SHOWING_NAME
|
||||
void Player::updateShowingName() {
|
||||
if (playing_state_ == State::SHOWING_NAME) {
|
||||
@@ -919,6 +1198,7 @@ void Player::decContinueCounter() {
|
||||
// Decrementa el contador de entrar nombre
|
||||
void Player::decNameEntryCounter() {
|
||||
name_entry_ticks_ = SDL_GetTicks();
|
||||
name_entry_time_accumulator_ = 0.0f; // Reset time accumulator
|
||||
|
||||
// Actualiza contadores
|
||||
++name_entry_idle_counter_;
|
||||
|
||||
@@ -94,9 +94,10 @@ class Player {
|
||||
~Player() = default;
|
||||
|
||||
// --- Inicialización y ciclo de vida ---
|
||||
void init(); // Inicializa el jugador
|
||||
void update(); // Actualiza estado, animación y contadores
|
||||
void render(); // Dibuja el jugador en pantalla
|
||||
void init(); // Inicializa el jugador
|
||||
void update(); // Actualiza estado, animación y contadores (frame-based)
|
||||
void update(float deltaTime); // Actualiza estado, animación y contadores (time-based)
|
||||
void render(); // Dibuja el jugador en pantalla
|
||||
|
||||
// --- Entrada y control ---
|
||||
void setInput(Input::Action action); // Procesa entrada general
|
||||
@@ -104,14 +105,17 @@ class Player {
|
||||
void setInputEnteringName(Input::Action action); // Procesa entrada al introducir nombre
|
||||
|
||||
// --- Movimiento y animación ---
|
||||
void move(); // Mueve el jugador
|
||||
void setAnimation(); // Establece la animación según el estado
|
||||
void move(); // Mueve el jugador (frame-based)
|
||||
void move(float deltaTime); // Mueve el jugador (time-based)
|
||||
void setAnimation(); // Establece la animación según el estado (frame-based)
|
||||
void setAnimation(float deltaTime); // Establece la animación según el estado (time-based)
|
||||
|
||||
// --- Texturas y animaciones ---
|
||||
void setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &texture); // Cambia las texturas del jugador
|
||||
|
||||
// --- Estados y contadores ---
|
||||
void updateCooldown(); // Actualiza el cooldown de disparo
|
||||
void updateCooldown(); // Actualiza el cooldown de disparo (frame-based)
|
||||
void updateCooldown(float deltaTime); // Actualiza el cooldown de disparo (time-based)
|
||||
|
||||
// --- Puntuación y marcador ---
|
||||
void addScore(int score, int lowest_hi_score_entry); // Añade puntos
|
||||
@@ -122,7 +126,8 @@ class Player {
|
||||
void setPlayingState(State state); // Cambia el estado de juego
|
||||
void setInvulnerable(bool value); // Establece el valor del estado de invulnerabilidad
|
||||
void setPowerUp(); // Activa el modo PowerUp
|
||||
void updatePowerUp(); // Actualiza el valor de PowerUp
|
||||
void updatePowerUp(); // Actualiza el valor de PowerUp (frame-based)
|
||||
void updatePowerUp(float deltaTime); // Actualiza el valor de PowerUp (time-based)
|
||||
void giveExtraHit(); // Concede un toque extra al jugador
|
||||
void removeExtraHit(); // Quita el toque extra al jugador
|
||||
void decContinueCounter(); // Decrementa el contador de continuar
|
||||
@@ -232,10 +237,19 @@ class Player {
|
||||
int pos_y_ = 0; // Posición en el eje Y
|
||||
int default_pos_y_; // Posición inicial para el jugador
|
||||
int vel_y_ = 0; // Cantidad de píxeles a desplazarse en el eje Y
|
||||
int cant_fire_counter_ = 0; // Contador durante el cual no puede disparar
|
||||
int recoiling_state_counter_ = 0; // Contador para la animación del estado de retroceso
|
||||
int cant_fire_counter_ = 0; // Contador durante el cual no puede disparar (frame-based)
|
||||
int recoiling_state_counter_ = 0; // Contador para la animación del estado de retroceso (frame-based)
|
||||
int recoiling_state_duration_ = 0; // Número de frames que dura el estado de retroceso
|
||||
int cooling_state_counter_ = 0; // Contador para la animación del estado cooling
|
||||
int cooling_state_counter_ = 0; // Contador para la animación del estado cooling (frame-based)
|
||||
float cant_fire_time_accumulator_ = 0.0f; // Acumulador de tiempo para cooldown de disparo (time-based)
|
||||
float recoiling_time_accumulator_ = 0.0f; // Acumulador de tiempo para retroceso (time-based)
|
||||
float cooling_time_accumulator_ = 0.0f; // Acumulador de tiempo para enfriamiento (time-based)
|
||||
float invulnerable_time_accumulator_ = 0.0f; // Acumulador de tiempo para invulnerabilidad (time-based)
|
||||
float power_up_time_accumulator_ = 0.0f; // Acumulador de tiempo para power-up (time-based)
|
||||
float continue_time_accumulator_ = 0.0f; // Acumulador de tiempo para continue counter (time-based)
|
||||
float name_entry_time_accumulator_ = 0.0f; // Acumulador de tiempo para name entry counter (time-based)
|
||||
float waiting_time_accumulator_ = 0.0f; // Acumulador de tiempo para waiting movement (time-based)
|
||||
float step_time_accumulator_ = 0.0f; // Acumulador de tiempo para step counter (time-based)
|
||||
int invulnerable_counter_ = INVULNERABLE_COUNTER; // Contador para la invulnerabilidad
|
||||
int score_ = 0; // Puntos del jugador
|
||||
int coffees_ = 0; // Indica cuántos cafés lleva acumulados
|
||||
@@ -259,9 +273,12 @@ class Player {
|
||||
// --- Métodos internos ---
|
||||
void shiftColliders(); // Actualiza el círculo de colisión a la posición del jugador
|
||||
void shiftSprite(); // Recoloca el sprite
|
||||
void updateInvulnerable(); // Monitoriza el estado de invulnerabilidad
|
||||
void updateContinueCounter(); // Actualiza el contador de continue
|
||||
void updateEnterNameCounter(); // Actualiza el contador de entrar nombre
|
||||
void updateInvulnerable(); // Monitoriza el estado de invulnerabilidad (frame-based)
|
||||
void updateInvulnerable(float deltaTime); // Monitoriza el estado de invulnerabilidad (time-based)
|
||||
void updateContinueCounter(); // Actualiza el contador de continue (frame-based)
|
||||
void updateContinueCounter(float deltaTime); // Actualiza el contador de continue (time-based)
|
||||
void updateEnterNameCounter(); // Actualiza el contador de entrar nombre (frame-based)
|
||||
void updateEnterNameCounter(float deltaTime); // Actualiza el contador de entrar nombre (time-based)
|
||||
void updateShowingName(); // Actualiza el estado SHOWING_NAME
|
||||
void decNameEntryCounter(); // Decrementa el contador de entrar nombre
|
||||
void updateScoreboard(); // Actualiza el panel del marcador
|
||||
@@ -269,13 +286,17 @@ class Player {
|
||||
void playSound(const std::string &name) const; // Hace sonar un sonido
|
||||
[[nodiscard]] auto isRenderable() const -> bool; // Indica si se puede dibujar el objeto
|
||||
void addScoreToScoreBoard() const; // Añade una puntuación a la tabla de records
|
||||
void handleFiringCooldown(); // Gestiona el tiempo de espera después de disparar antes de permitir otro disparo
|
||||
void handleRecoilAndCooling(); // Procesa simultáneamente el retroceso del arma y la transición al estado de enfriamiento si aplica
|
||||
void handleCoolingState(); // Actualiza la lógica interna mientras el sistema está en estado de enfriamiento
|
||||
void handleFiringCooldown(); // Gestiona el tiempo de espera después de disparar antes de permitir otro disparo (frame-based)
|
||||
void handleFiringCooldown(float deltaTime); // Gestiona el tiempo de espera después de disparar antes de permitir otro disparo (time-based)
|
||||
void handleRecoilAndCooling(); // Procesa simultáneamente el retroceso del arma y la transición al estado de enfriamiento si aplica (frame-based)
|
||||
void handleRecoilAndCooling(float deltaTime); // Procesa simultáneamente el retroceso del arma y la transición al estado de enfriamiento si aplica (time-based)
|
||||
void handleCoolingState(); // Actualiza la lógica interna mientras el sistema está en estado de enfriamiento (frame-based)
|
||||
void handleCoolingState(float deltaTime); // Actualiza la lógica interna mientras el sistema está en estado de enfriamiento (time-based)
|
||||
void transitionToRecoiling(); // Cambia el estado actual al de retroceso después de disparar
|
||||
void transitionToCooling(); // Cambia el estado actual al de enfriamiento (por ejemplo, tras una ráfaga o sobrecalentamiento)
|
||||
void completeCooling(); // Finaliza el proceso de enfriamiento y restablece el estado listo para disparar
|
||||
void handlePlayingMovement(); // Gestiona el movimiento del personaje u objeto durante el estado de juego activo
|
||||
void handlePlayingMovement(); // Gestiona el movimiento del personaje u objeto durante el estado de juego activo (frame-based)
|
||||
void handlePlayingMovement(float deltaTime); // Gestiona el movimiento del personaje u objeto durante el estado de juego activo (time-based)
|
||||
void handleRecoverMovement(); // Comprueba si ha acabado la animación
|
||||
void handleRollingMovement(); // Actualiza la lógica de movimiento de "rodar" (posiblemente tras impacto o acción especial)
|
||||
void handleRollingBoundaryCollision(); // Detecta y maneja colisiones del objeto rodante con los límites de la pantalla
|
||||
@@ -288,12 +309,15 @@ class Player {
|
||||
void handleEnteringScreen(); // Lógica para entrar en una nueva pantalla, posiblemente con animación o retraso
|
||||
void handlePlayer1Entering(); // Controla la animación o posición de entrada del Jugador 1 en pantalla
|
||||
void handlePlayer2Entering(); // Controla la animación o posición de entrada del Jugador 2 en pantalla
|
||||
void handleCreditsMovement(); // Movimiento general en la pantalla de créditos (desplazamiento vertical u horizontal)
|
||||
void handleCreditsMovement(); // Movimiento general en la pantalla de créditos (frame-based)
|
||||
void handleCreditsMovement(float deltaTime); // Movimiento general en la pantalla de créditos (time-based)
|
||||
void handleCreditsRightMovement(); // Lógica específica para mover los créditos hacia la derecha
|
||||
void handleCreditsLeftMovement(); // Lógica específica para mover los créditos hacia la izquierda
|
||||
void handleWaitingMovement(); // Controla la animación del jugador saludando
|
||||
void handleWaitingMovement(); // Controla la animación del jugador saludando (frame-based)
|
||||
void handleWaitingMovement(float deltaTime); // Controla la animación del jugador saludando (time-based)
|
||||
void updateWalkingStateForCredits(); // Actualiza el estado de caminata de algún personaje u elemento animado en los créditos
|
||||
void setInputBasedOnPlayerId(); // Asocia las entradas de control en función del identificador del jugador (teclas, mando, etc.)
|
||||
void updateStepCounter(); // Incrementa o ajusta el contador de pasos para animaciones o mecánicas relacionadas con movimiento
|
||||
void updateStepCounter(); // Incrementa o ajusta el contador de pasos (frame-based)
|
||||
void updateStepCounter(float deltaTime); // Incrementa o ajusta el contador de pasos (time-based)
|
||||
[[nodiscard]] auto computeAnimation() const -> std::pair<std::string, SDL_FlipMode>; // Calcula la animacion de moverse y disparar del jugador
|
||||
};
|
||||
Reference in New Issue
Block a user