modificat el efecte de invulnerabilitat per a que vaja menguant
This commit is contained in:
@@ -778,15 +778,30 @@ void Player::setInvulnerable(bool value) {
|
|||||||
|
|
||||||
// Monitoriza el estado
|
// Monitoriza el estado
|
||||||
void Player::updateInvulnerable() {
|
void Player::updateInvulnerable() {
|
||||||
if (playing_state_ == State::PLAYING) {
|
if (playing_state_ == State::PLAYING && invulnerable_) {
|
||||||
if (invulnerable_) {
|
if (invulnerable_counter_ > 0) {
|
||||||
if (invulnerable_counter_ > 0) {
|
--invulnerable_counter_;
|
||||||
--invulnerable_counter_;
|
|
||||||
invulnerable_counter_ % 8 > 3 ? player_sprite_->setActiveTexture(coffees_) : player_sprite_->setActiveTexture(3);
|
// Frecuencia fija de parpadeo (como el original)
|
||||||
} else {
|
constexpr int blink_speed = 8;
|
||||||
setInvulnerable(false);
|
|
||||||
player_sprite_->setActiveTexture(coffees_);
|
// 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_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,12 +193,13 @@ class Player {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// --- Constantes ---
|
// --- Constantes ---
|
||||||
static constexpr int POWERUP_COUNTER = 1500; // Duración del estado PowerUp
|
static constexpr int POWERUP_COUNTER = 1500; // Duración del estado PowerUp
|
||||||
static constexpr int INVULNERABLE_COUNTER = 200; // Duración del estado invulnerable
|
static constexpr int INVULNERABLE_COUNTER = 200; // Duración del estado invulnerable
|
||||||
static constexpr float BASE_SPEED = 1.5F; // Velocidad base del jugador
|
static constexpr size_t INVULNERABLE_TEXTURE = 3; // Textura usada durante invulnerabilidad
|
||||||
static constexpr int COOLING_DURATION = 50;
|
static constexpr float BASE_SPEED = 1.5F; // Velocidad base del jugador
|
||||||
static constexpr int COOLING_COMPLETE = 0;
|
static constexpr int COOLING_DURATION = 50; // Duración del enfriamiento tras disparar
|
||||||
static constexpr int WAITING_COUNTER = 1000;
|
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 ---
|
// --- Objetos y punteros ---
|
||||||
std::unique_ptr<AnimatedSprite> player_sprite_; // Sprite para dibujar el jugador
|
std::unique_ptr<AnimatedSprite> player_sprite_; // Sprite para dibujar el jugador
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class Sprite {
|
|||||||
void setTexture(std::shared_ptr<Texture> texture) { textures_.at(texture_index_) = std::move(texture); }
|
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); }
|
void addTexture(const std::shared_ptr<Texture>& texture) { textures_.push_back(texture); }
|
||||||
auto setActiveTexture(size_t index) -> bool; // Cambia la textura activa por índice
|
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
|
[[nodiscard]] auto getTextureCount() const -> size_t { return textures_.size(); } // Obtiene el número total de texturas
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
Reference in New Issue
Block a user