magic numbers: game.cpp i player.cpp
This commit is contained in:
@@ -10,8 +10,8 @@ game.play_area.rect.x 0 # Posición X de la zona jugable
|
||||
game.play_area.rect.y 0 # Posición Y de la zona jugable
|
||||
game.play_area.rect.w 320 # Ancho de la zona jugable
|
||||
game.play_area.rect.h 200 # Alto de la zona jugable
|
||||
game.name_entry_idle_time 10 # Segundos para introducir el nombre al finalizar la partida si no se pulsa nada
|
||||
game.name_entry_total_time 60 # Segundos totales para introducir el nombre al finalizar la partida
|
||||
game.name_entry_idle_time 10000 # Segundos para introducir el nombre al finalizar la partida si no se pulsa nada
|
||||
game.name_entry_total_time 60000 # Segundos totales para introducir el nombre al finalizar la partida
|
||||
game.hit_stop false # Indica si debe haber un paro cuando el jugador es golpeado por un globo
|
||||
game.hit_stop_ms 500 # Cantidad de milisegundos que dura el hit_stop
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ game.play_area.rect.x 0 # Posición X de la zona jugable
|
||||
game.play_area.rect.y 0 # Posición Y de la zona jugable
|
||||
game.play_area.rect.w 320 # Ancho de la zona jugable
|
||||
game.play_area.rect.h 216 # Alto de la zona jugable
|
||||
game.name_entry_idle_time 10 # Segundos para introducir el nombre al finalizar la partida si no se pulsa nada
|
||||
game.name_entry_total_time 60 # Segundos totales para introducir el nombre al finalizar la partida
|
||||
game.name_entry_idle_time 10000 # Segundos para introducir el nombre al finalizar la partida si no se pulsa nada
|
||||
game.name_entry_total_time 60000 # Segundos totales para introducir el nombre al finalizar la partida
|
||||
game.hit_stop false # Indica si debe haber un paro cuando el jugador es golpeado por un globo
|
||||
game.hit_stop_ms 500 # Cantidad de milisegundos que dura el hit_stop
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Game {
|
||||
constexpr float WIDTH = 320.0F;
|
||||
constexpr float HEIGHT = 256.0F;
|
||||
constexpr float ITEM_SIZE = 20.0F;
|
||||
constexpr int NAME_ENTRY_IDLE_TIME = 10;
|
||||
constexpr int NAME_ENTRY_TOTAL_TIME = 60;
|
||||
constexpr int NAME_ENTRY_IDLE_TIME = 10000; // 10 segundos en milisegundos
|
||||
constexpr int NAME_ENTRY_TOTAL_TIME = 60000; // 60 segundos en milisegundos
|
||||
constexpr bool HIT_STOP = false;
|
||||
constexpr int HIT_STOP_MS = 500;
|
||||
constexpr const char* ITEM_TEXT_OUTLINE_COLOR = "FFFFFF00"; // 255, 255, 255, 0
|
||||
|
||||
@@ -42,7 +42,7 @@ Director::Director(int argc, std::span<char *> argv) {
|
||||
Section::name = Section::Name::GAME;
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
#elif _DEBUG
|
||||
Section::name = Section::Name::TITLE;
|
||||
Section::name = Section::Name::GAME;
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
#else // NORMAL GAME
|
||||
Section::name = Section::Name::LOGO;
|
||||
|
||||
@@ -60,17 +60,14 @@ void Player::init() {
|
||||
power_up_counter_ = POWERUP_COUNTER;
|
||||
extra_hit_ = false;
|
||||
coffees_ = 0;
|
||||
continue_ticks_ = 0;
|
||||
continue_counter_ = 10;
|
||||
name_entry_ticks_ = 0;
|
||||
name_entry_idle_counter_ = 0;
|
||||
name_entry_total_counter_ = 0;
|
||||
name_entry_idle_time_accumulator_ = 0.0f;
|
||||
name_entry_total_time_accumulator_ = 0.0f;
|
||||
shiftColliders();
|
||||
vel_x_ = 0;
|
||||
vel_y_ = 0;
|
||||
score_ = 0;
|
||||
score_multiplier_ = 1.0F;
|
||||
cant_fire_counter_ = 10;
|
||||
enter_name_->init(last_enter_name_);
|
||||
|
||||
// Establece la posición del sprite
|
||||
@@ -149,7 +146,7 @@ void Player::setInputEnteringName(Input::Action action) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
name_entry_idle_counter_ = 0;
|
||||
name_entry_idle_time_accumulator_ = 0.0f;
|
||||
}
|
||||
|
||||
// Mueve el jugador a la posición y animación que le corresponde
|
||||
@@ -634,189 +631,18 @@ void Player::setAnimation(float deltaTime) {
|
||||
power_sprite_->update(deltaTime);
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable (frame-based)
|
||||
void Player::updateCooldown() {
|
||||
if (playing_state_ != State::PLAYING) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cant_fire_counter_ > 0) {
|
||||
handleFiringCooldown();
|
||||
} else {
|
||||
handleRecoilAndCooling();
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
// Transition to recoiling state at halfway point
|
||||
if (cant_fire_counter_ == recoiling_state_duration_ / 2) {
|
||||
transitionToRecoiling();
|
||||
}
|
||||
|
||||
--cant_fire_counter_;
|
||||
if (cant_fire_counter_ == 0) {
|
||||
recoiling_state_counter_ = recoiling_state_duration_;
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 2: Manejo de cooldown de disparo (time-based)
|
||||
void Player::handleFiringCooldown(float deltaTime) {
|
||||
// Convertir frames a tiempo en milisegundos
|
||||
float halfwayTime = static_cast<float>(recoiling_state_duration_) / 2.0f / 60.0f * 1000.0f;
|
||||
|
||||
// Reducir tiempo acumulado
|
||||
cant_fire_time_accumulator_ -= deltaTime;
|
||||
|
||||
// Transition to recoiling state at halfway point
|
||||
if (cant_fire_time_accumulator_ <= halfwayTime && !recoiling_transition_done_) {
|
||||
transitionToRecoiling();
|
||||
recoiling_transition_done_ = true;
|
||||
}
|
||||
|
||||
if (cant_fire_time_accumulator_ <= 0) {
|
||||
cant_fire_time_accumulator_ = 0;
|
||||
recoiling_time_accumulator_ = static_cast<float>(recoiling_state_duration_) / 60.0f * 1000.0f; // Convert to milliseconds
|
||||
|
||||
// Solo inicializar cooling si no está ya activo (para permitir disparos consecutivos)
|
||||
if (cooling_time_accumulator_ <= 0) {
|
||||
cooling_time_accumulator_ = static_cast<float>(COOLING_DURATION) / 60.0f * 1000.0f; // Convert to milliseconds
|
||||
}
|
||||
|
||||
recoiling_transition_done_ = false; // Reset flag
|
||||
}
|
||||
}
|
||||
|
||||
void Player::handleRecoilAndCooling() {
|
||||
if (recoiling_state_counter_ > 0) {
|
||||
--recoiling_state_counter_;
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
transitionToCooling();
|
||||
}
|
||||
--cooling_state_counter_;
|
||||
}
|
||||
|
||||
if (cooling_state_counter_ == COOLING_COMPLETE) {
|
||||
completeCooling();
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 2: Manejo del estado de enfriamiento (time-based)
|
||||
void Player::handleCoolingState(float deltaTime) {
|
||||
float coolingCompleteTime = static_cast<float>(COOLING_COMPLETE); // 0
|
||||
float coolingDurationTime = static_cast<float>(COOLING_DURATION) / 60.0f * 1000.0f; // Convert to milliseconds
|
||||
|
||||
if (cooling_time_accumulator_ > coolingCompleteTime) {
|
||||
// Transición a cooling cuando empezamos (equivalente a == COOLING_DURATION)
|
||||
if (!cooling_transition_done_ && cooling_time_accumulator_ >= coolingDurationTime - 16.67f) { // ~1 frame tolerance in ms
|
||||
transitionToCooling();
|
||||
cooling_transition_done_ = true;
|
||||
}
|
||||
cooling_time_accumulator_ -= deltaTime;
|
||||
}
|
||||
|
||||
if (cooling_time_accumulator_ <= coolingCompleteTime) {
|
||||
cooling_time_accumulator_ = coolingCompleteTime;
|
||||
completeCooling();
|
||||
cooling_transition_done_ = false; // Reset flag
|
||||
}
|
||||
}
|
||||
|
||||
void Player::transitionToRecoiling() {
|
||||
switch (firing_state_) {
|
||||
case State::FIRING_LEFT:
|
||||
setFiringState(State::RECOILING_LEFT);
|
||||
break;
|
||||
case State::FIRING_RIGHT:
|
||||
setFiringState(State::RECOILING_RIGHT);
|
||||
break;
|
||||
case State::FIRING_UP:
|
||||
setFiringState(State::RECOILING_UP);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::transitionToCooling() {
|
||||
switch (firing_state_) {
|
||||
case State::RECOILING_LEFT:
|
||||
setFiringState(State::COOLING_LEFT);
|
||||
break;
|
||||
case State::RECOILING_RIGHT:
|
||||
setFiringState(State::COOLING_RIGHT);
|
||||
break;
|
||||
case State::RECOILING_UP:
|
||||
setFiringState(State::COOLING_UP);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::completeCooling() {
|
||||
setFiringState(State::FIRING_NONE);
|
||||
cooling_state_counter_ = -1;
|
||||
}
|
||||
|
||||
// Actualiza al jugador a su posicion, animación y controla los contadores (frame-based)
|
||||
void Player::update() {
|
||||
move();
|
||||
setAnimation();
|
||||
shiftColliders();
|
||||
updateFireSystem(16.67f); // Usar nuevo sistema con deltaTime fijo (16.67ms ≈ 1/60s)
|
||||
updatePowerUp();
|
||||
updateInvulnerable();
|
||||
updateScoreboard();
|
||||
updateContinueCounter();
|
||||
updateEnterNameCounter();
|
||||
updateShowingName();
|
||||
}
|
||||
|
||||
// Fase 1-4: Método deltaTime completo
|
||||
// Actualiza al jugador con deltaTime (time-based)
|
||||
void Player::update(float deltaTime) {
|
||||
move(deltaTime); // Sistema de movimiento time-based
|
||||
setAnimation(deltaTime); // Animaciones time-based
|
||||
shiftColliders(); // Sin cambios (posicional)
|
||||
updateFireSystem(deltaTime); // NUEVO: Sistema de disparo de dos líneas
|
||||
updatePowerUp(deltaTime); // Fase 3: Sistema de power-up time-based
|
||||
updateInvulnerable(deltaTime); // Fase 3: Sistema de invulnerabilidad time-based
|
||||
updateFireSystem(deltaTime); // Sistema de disparo de dos líneas
|
||||
updatePowerUp(deltaTime); // Sistema de power-up time-based
|
||||
updateInvulnerable(deltaTime); // 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)
|
||||
updateContinueCounter(deltaTime); // Sistema de continue time-based
|
||||
updateEnterNameCounter(deltaTime); // Sistema de name entry time-based
|
||||
updateShowingName(deltaTime); // Sistema de showing name time-based
|
||||
}
|
||||
|
||||
void Player::passShowingName() {
|
||||
@@ -886,7 +712,6 @@ void Player::setPlayingState(State state) {
|
||||
}
|
||||
case State::CONTINUE: {
|
||||
// Inicializa el contador de continuar
|
||||
continue_ticks_ = SDL_GetTicks();
|
||||
continue_counter_ = 9;
|
||||
continue_time_accumulator_ = 0.0f; // Initialize time accumulator
|
||||
playSound("continue_clock.wav");
|
||||
@@ -919,7 +744,7 @@ void Player::setPlayingState(State state) {
|
||||
break;
|
||||
}
|
||||
case State::SHOWING_NAME: {
|
||||
showing_name_ticks_ = SDL_GetTicks();
|
||||
showing_name_time_accumulator_ = 0.0f; // Inicializar acumulador time-based
|
||||
setScoreboardMode(Scoreboard::Mode::SHOW_NAME);
|
||||
Scoreboard::get()->setRecordName(scoreboard_panel_, last_enter_name_);
|
||||
addScoreToScoreBoard();
|
||||
@@ -1026,37 +851,7 @@ void Player::setInvulnerable(bool value) {
|
||||
invulnerable_time_accumulator_ = invulnerable_ ? static_cast<float>(INVULNERABLE_COUNTER) / 60.0f * 1000.0f : 0.0f; // Convert frames to milliseconds
|
||||
}
|
||||
|
||||
// Monitoriza el estado (frame-based)
|
||||
void Player::updateInvulnerable() {
|
||||
if (playing_state_ == State::PLAYING && invulnerable_) {
|
||||
if (invulnerable_counter_ > 0) {
|
||||
--invulnerable_counter_;
|
||||
|
||||
// Frecuencia fija de parpadeo (como el original)
|
||||
constexpr int blink_speed = 8;
|
||||
|
||||
// Calcula proporción decreciente: menos textura blanca hacia el final
|
||||
// Al inicio: 50-50, hacia el final: 70-30 (menos blanco)
|
||||
float progress = 1.0f - (static_cast<float>(invulnerable_counter_) / INVULNERABLE_COUNTER);
|
||||
int white_frames = static_cast<int>((0.5f - progress * 0.2f) * blink_speed);
|
||||
|
||||
// Alterna entre texturas con proporción variable
|
||||
bool should_show_invulnerable = (invulnerable_counter_ % blink_speed) < white_frames;
|
||||
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
|
||||
setInvulnerable(false);
|
||||
player_sprite_->setActiveTexture(coffees_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 3: Monitoriza el estado (time-based)
|
||||
// Monitoriza el estado (time-based)
|
||||
void Player::updateInvulnerable(float deltaTime) {
|
||||
if (playing_state_ == State::PLAYING && invulnerable_) {
|
||||
if (invulnerable_time_accumulator_ > 0) {
|
||||
@@ -1095,17 +890,7 @@ void Player::setPowerUp() {
|
||||
power_up_time_accumulator_ = static_cast<float>(POWERUP_COUNTER) / 60.0f * 1000.0f; // Convert frames to milliseconds
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable (frame-based)
|
||||
void Player::updatePowerUp() {
|
||||
if (playing_state_ == State::PLAYING) {
|
||||
if (power_up_) {
|
||||
--power_up_counter_;
|
||||
power_up_ = power_up_counter_ > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 3: Actualiza el valor de la variable (time-based)
|
||||
// Actualiza el valor de la variable (time-based)
|
||||
void Player::updatePowerUp(float deltaTime) {
|
||||
if (playing_state_ == State::PLAYING) {
|
||||
if (power_up_) {
|
||||
@@ -1150,17 +935,7 @@ void Player::setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &text
|
||||
power_sprite_->setTexture(texture[1]);
|
||||
}
|
||||
|
||||
// Actualiza el contador de continue (frame-based)
|
||||
void Player::updateContinueCounter() {
|
||||
if (playing_state_ == State::CONTINUE) {
|
||||
constexpr int TICKS_SPEED = 1000;
|
||||
if (SDL_GetTicks() - continue_ticks_ > TICKS_SPEED) {
|
||||
decContinueCounter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 4: Actualiza el contador de continue (time-based)
|
||||
// Actualiza el contador de continue (time-based)
|
||||
void Player::updateContinueCounter(float deltaTime) {
|
||||
if (playing_state_ == State::CONTINUE) {
|
||||
continue_time_accumulator_ += deltaTime;
|
||||
@@ -1172,17 +947,7 @@ void Player::updateContinueCounter(float deltaTime) {
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
if (SDL_GetTicks() - name_entry_ticks_ > TICKS_SPEED) {
|
||||
decNameEntryCounter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 4: Actualiza el contador de entrar nombre (time-based)
|
||||
// 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;
|
||||
@@ -1194,11 +959,12 @@ void Player::updateEnterNameCounter(float deltaTime) {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el estado de SHOWING_NAME
|
||||
void Player::updateShowingName() {
|
||||
// Actualiza el estado de SHOWING_NAME (time-based)
|
||||
void Player::updateShowingName(float deltaTime) {
|
||||
if (playing_state_ == State::SHOWING_NAME) {
|
||||
constexpr int TICKS_SPEED = 5000;
|
||||
if (SDL_GetTicks() - name_entry_ticks_ > TICKS_SPEED) {
|
||||
showing_name_time_accumulator_ += deltaTime;
|
||||
constexpr float SHOWING_NAME_DURATION = 5000.0f; // 5 segundos en milisegundos
|
||||
if (showing_name_time_accumulator_ >= SHOWING_NAME_DURATION) {
|
||||
game_completed_ ? setPlayingState(State::LEAVING_SCREEN) : setPlayingState(State::CONTINUE);
|
||||
}
|
||||
}
|
||||
@@ -1206,7 +972,7 @@ void Player::updateShowingName() {
|
||||
|
||||
// Decrementa el contador de continuar
|
||||
void Player::decContinueCounter() {
|
||||
continue_ticks_ = SDL_GetTicks();
|
||||
continue_time_accumulator_ = 0.0f; // Reset time accumulator
|
||||
--continue_counter_;
|
||||
if (continue_counter_ < 0) {
|
||||
setPlayingState(State::CONTINUE_TIME_OUT);
|
||||
@@ -1217,18 +983,17 @@ 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_;
|
||||
++name_entry_total_counter_;
|
||||
// Incrementa acumuladores de tiempo (1 segundo = 1000ms)
|
||||
name_entry_idle_time_accumulator_ += 1000.0f;
|
||||
name_entry_total_time_accumulator_ += 1000.0f;
|
||||
|
||||
// Comprueba los contadores
|
||||
if ((name_entry_total_counter_ >= param.game.name_entry_total_time) ||
|
||||
(name_entry_idle_counter_ >= param.game.name_entry_idle_time)) {
|
||||
name_entry_total_counter_ = 0;
|
||||
name_entry_idle_counter_ = 0;
|
||||
// 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)) {
|
||||
name_entry_total_time_accumulator_ = 0.0f;
|
||||
name_entry_idle_time_accumulator_ = 0.0f;
|
||||
if (playing_state_ == State::ENTERING_NAME) {
|
||||
last_enter_name_ = getRecordName();
|
||||
setPlayingState(State::SHOWING_NAME);
|
||||
@@ -1291,10 +1056,10 @@ void Player::addCredit() {
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// IMPLEMENTACIÓN DEL NUEVO SISTEMA DE DOS LÍNEAS
|
||||
// SISTEMA DE DISPARO DE DOS LÍNEAS
|
||||
// ========================================
|
||||
|
||||
// Método principal del nuevo sistema de disparo
|
||||
// Método principal del sistema de disparo
|
||||
void Player::updateFireSystem(float deltaTime) {
|
||||
updateFunctionalLine(deltaTime); // Línea 1: CanFire
|
||||
updateVisualLine(deltaTime); // Línea 2: Animaciones
|
||||
@@ -1344,8 +1109,8 @@ void Player::updateVisualLine(float deltaTime) {
|
||||
}
|
||||
}
|
||||
|
||||
// Inicia un nuevo disparo en ambas líneas
|
||||
void Player::startFiringNewSystem(int cooldown_frames) {
|
||||
// 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
|
||||
can_fire_new_system_ = false;
|
||||
|
||||
@@ -109,7 +109,6 @@ class Player {
|
||||
|
||||
// --- Inicialización y ciclo de vida ---
|
||||
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
|
||||
|
||||
@@ -128,8 +127,6 @@ class Player {
|
||||
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 (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
|
||||
@@ -140,7 +137,6 @@ 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 (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
|
||||
@@ -165,7 +161,6 @@ class Player {
|
||||
|
||||
// Getters
|
||||
[[nodiscard]] auto canFire() const -> bool { return can_fire_new_system_; } // Usa nuevo sistema
|
||||
[[nodiscard]] auto canFireOld() const -> bool { return cant_fire_time_accumulator_ <= 0; } // Sistema anterior
|
||||
[[nodiscard]] auto hasExtraHit() const -> bool { return extra_hit_; }
|
||||
[[nodiscard]] auto isCooling() const -> bool { return firing_state_ == State::COOLING_LEFT || firing_state_ == State::COOLING_UP || firing_state_ == State::COOLING_RIGHT; }
|
||||
[[nodiscard]] auto isRecoiling() const -> bool { return firing_state_ == State::RECOILING_LEFT || firing_state_ == State::RECOILING_UP || firing_state_ == State::RECOILING_RIGHT; }
|
||||
@@ -195,7 +190,7 @@ class Player {
|
||||
|
||||
// Setters inline
|
||||
void setController(int index) { controller_index_ = index; }
|
||||
void startFiringNewSystem(int cooldown_frames); // Método público para iniciar disparo en nuevo sistema
|
||||
void startFiringSystem(int cooldown_frames); // Método público para iniciar disparo
|
||||
void setFiringState(State state) { firing_state_ = state; }
|
||||
void setInvulnerableCounter(int value) { invulnerable_counter_ = value; }
|
||||
void setName(const std::string &name) { name_ = name; }
|
||||
@@ -254,9 +249,6 @@ class Player {
|
||||
State firing_state_ = State::FIRING_NONE; // Estado del jugador al disparar
|
||||
State playing_state_ = State::WAITING; // Estado del jugador en el juego
|
||||
|
||||
Uint32 continue_ticks_ = 0; // Variable para poder cambiar el contador de continue en función del tiempo
|
||||
Uint32 name_entry_ticks_ = 0; // Variable para poder cambiar el contador de poner nombre en función del tiempo
|
||||
Uint32 showing_name_ticks_ = 0; // Tiempo en el que se entra al estado SHOWING_NAME
|
||||
float pos_x_ = 0.0F; // Posición en el eje X
|
||||
float default_pos_x_; // Posición inicial para el jugador
|
||||
float vel_x_ = 0.0F; // Cantidad de píxeles a desplazarse en el eje X
|
||||
@@ -264,17 +256,11 @@ 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 (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 (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 showing_name_time_accumulator_ = 0.0f; // Acumulador de tiempo para showing name (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)
|
||||
|
||||
@@ -299,9 +285,6 @@ class Player {
|
||||
float aiming_duration_ = 0.0f; // Duración del estado AIMING
|
||||
float recoiling_duration_ = 0.0f; // Duración del estado RECOILING
|
||||
|
||||
// Variables del sistema obsoleto (mantener para compatibilidad temporal)
|
||||
bool recoiling_transition_done_ = false; // Flag sistema obsoleto
|
||||
bool cooling_transition_done_ = false; // Flag sistema obsoleto
|
||||
|
||||
int invulnerable_counter_ = INVULNERABLE_COUNTER; // Contador para la invulnerabilidad
|
||||
int score_ = 0; // Puntos del jugador
|
||||
@@ -310,8 +293,8 @@ class Player {
|
||||
int power_up_x_offset_ = 0; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador
|
||||
int continue_counter_ = 10; // Contador para poder continuar
|
||||
int controller_index_ = 0; // Índice del array de mandos que utilizará para moverse
|
||||
int name_entry_idle_counter_ = 0; // Contador para poner nombre
|
||||
int name_entry_total_counter_ = 0; // Segundos totales que lleva acumulados poniendo nombre
|
||||
float name_entry_idle_time_accumulator_ = 0.0f; // Tiempo idle acumulado para poner nombre (milisegundos)
|
||||
float name_entry_total_time_accumulator_ = 0.0f; // Tiempo total acumulado poniendo nombre (milisegundos)
|
||||
int step_counter_ = 0; // Cuenta los pasos para los estados en los que camina automáticamente
|
||||
int credits_used_ = 0; // Indica el número de veces que ha continuado
|
||||
int waiting_counter_ = 0; // Contador para el estado de espera
|
||||
@@ -326,13 +309,10 @@ 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 (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 updateShowingName(float deltaTime); // Actualiza el estado SHOWING_NAME (time-based)
|
||||
void decNameEntryCounter(); // Decrementa el contador de entrar nombre
|
||||
void updateScoreboard(); // Actualiza el panel del marcador
|
||||
void setScoreboardMode(Scoreboard::Mode mode) const; // Cambia el modo del marcador
|
||||
|
||||
@@ -99,29 +99,6 @@ void Credits::run() {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables (frame-based)
|
||||
void Credits::update() {
|
||||
if (SDL_GetTicks() - last_time_ > param.game.speed) {
|
||||
last_time_ = SDL_GetTicks();
|
||||
const int REPEAT = want_to_pass_ ? 4 : 1;
|
||||
for (int i = 0; i < REPEAT; ++i) {
|
||||
tiled_bg_->update();
|
||||
cycleColors();
|
||||
balloon_manager_->update();
|
||||
updateTextureDstRects();
|
||||
throwBalloons();
|
||||
updatePlayers();
|
||||
updateAllFades();
|
||||
++counter_;
|
||||
}
|
||||
|
||||
Screen::get()->update();
|
||||
|
||||
fillCanvas();
|
||||
}
|
||||
Audio::update();
|
||||
}
|
||||
|
||||
// Actualiza las variables (time-based)
|
||||
void Credits::update(float deltaTime) {
|
||||
const float multiplier = want_to_pass_ ? 4.0f : 1.0f;
|
||||
@@ -674,13 +651,6 @@ void Credits::cycleColors() {
|
||||
tiled_bg_->setColor(color_);
|
||||
}
|
||||
|
||||
// Actualza los jugadores (frame-based)
|
||||
void Credits::updatePlayers() {
|
||||
for (auto &player : players_) {
|
||||
player->update();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualza los jugadores (time-based)
|
||||
void Credits::updatePlayers(float deltaTime) {
|
||||
for (auto &player : players_) {
|
||||
|
||||
@@ -27,7 +27,6 @@ class Credits {
|
||||
|
||||
private:
|
||||
// --- Métodos del bucle principal ---
|
||||
void update(); // Actualización principal de la lógica (frame-based)
|
||||
void update(float deltaTime); // Actualización principal de la lógica (time-based)
|
||||
auto calculateDeltaTime() -> float; // Calcula el deltatime
|
||||
|
||||
@@ -123,7 +122,6 @@ class Credits {
|
||||
void updateAllFades(); // Actualizar estados de fade (frame-based)
|
||||
void updateAllFades(float deltaTime); // Actualizar estados de fade (time-based)
|
||||
void cycleColors(); // Cambiar colores de fondo
|
||||
void updatePlayers(); // Actualza los jugadores (frame-based)
|
||||
void updatePlayers(float deltaTime); // Actualza los jugadores (time-based)
|
||||
|
||||
// --- Métodos de interfaz ---
|
||||
|
||||
@@ -1354,7 +1354,7 @@ void Game::handleFireInput(const std::shared_ptr<Player> &player, BulletType bul
|
||||
cant_fire_counter = NORMAL_COOLDOWN;
|
||||
}
|
||||
|
||||
player->startFiringNewSystem(cant_fire_counter); // Usar nuevo sistema de dos líneas
|
||||
player->startFiringSystem(cant_fire_counter); // Sistema de disparo de dos líneas
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user