modificat el efecte de invulnerabilitat per a que vaja menguant

This commit is contained in:
2025-08-17 17:21:03 +02:00
parent a95776e6c7
commit e774e0e8ad
3 changed files with 31 additions and 15 deletions

View File

@@ -778,17 +778,32 @@ void Player::setInvulnerable(bool value) {
// Monitoriza el estado
void Player::updateInvulnerable() {
if (playing_state_ == State::PLAYING) {
if (invulnerable_) {
if (playing_state_ == State::PLAYING && invulnerable_) {
if (invulnerable_counter_ > 0) {
--invulnerable_counter_;
invulnerable_counter_ % 8 > 3 ? player_sprite_->setActiveTexture(coffees_) : player_sprite_->setActiveTexture(3);
// 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_);
}
}
}
}
// Establece el valor de la variable

View File

@@ -195,10 +195,11 @@ class Player {
// --- Constantes ---
static constexpr int POWERUP_COUNTER = 1500; // Duración del estado PowerUp
static constexpr int INVULNERABLE_COUNTER = 200; // Duración del estado invulnerable
static constexpr size_t INVULNERABLE_TEXTURE = 3; // Textura usada durante invulnerabilidad
static constexpr float BASE_SPEED = 1.5F; // Velocidad base del jugador
static constexpr int COOLING_DURATION = 50;
static constexpr int COOLING_COMPLETE = 0;
static constexpr int WAITING_COUNTER = 1000;
static constexpr int COOLING_DURATION = 50; // Duración del enfriamiento tras disparar
static constexpr int COOLING_COMPLETE = 0; // Valor que indica enfriamiento completado
static constexpr int WAITING_COUNTER = 1000; // Tiempo de espera en estado de espera
// --- Objetos y punteros ---
std::unique_ptr<AnimatedSprite> player_sprite_; // Sprite para dibujar el jugador

View File

@@ -56,7 +56,7 @@ class Sprite {
void setTexture(std::shared_ptr<Texture> texture) { textures_.at(texture_index_) = std::move(texture); }
void addTexture(const std::shared_ptr<Texture>& texture) { textures_.push_back(texture); }
auto setActiveTexture(size_t index) -> bool; // Cambia la textura activa por índice
[[nodiscard]] auto getActiveTextureIndex() const -> size_t { return texture_index_; } // Obtiene el índice de la textura activa
[[nodiscard]] auto getActiveTexture() const -> size_t { return texture_index_; } // Alias para getActiveTextureIndex
[[nodiscard]] auto getTextureCount() const -> size_t { return textures_.size(); } // Obtiene el número total de texturas
protected: