novetat: canvi de color de les bales quan queda poc powerUp
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
#endif
|
||||
|
||||
// Constructor
|
||||
Player::Player(const Config &config)
|
||||
Player::Player(const Config& config)
|
||||
: player_sprite_(std::make_unique<AnimatedSprite>(config.texture.at(0), config.animations.at(0))),
|
||||
power_sprite_(std::make_unique<AnimatedSprite>(config.texture.at(4), config.animations.at(1))),
|
||||
enter_name_(std::make_unique<EnterName>()),
|
||||
@@ -396,24 +396,8 @@ void Player::updateStepCounter(float deltaTime) {
|
||||
|
||||
// Pinta el jugador en pantalla
|
||||
void Player::render() {
|
||||
if (power_up_ && isPlaying()) {
|
||||
// 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_S) {
|
||||
// En los primeros 75% del tiempo, siempre visible
|
||||
power_sprite_->render();
|
||||
} else {
|
||||
// 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_S) / BLINK_PERIOD_S;
|
||||
if (cycle_position >= VISIBLE_PROPORTION) {
|
||||
power_sprite_->render();
|
||||
}
|
||||
}
|
||||
if (power_sprite_visible_ && isPlaying()) {
|
||||
power_sprite_->render();
|
||||
}
|
||||
|
||||
if (isRenderable()) {
|
||||
@@ -774,6 +758,9 @@ void Player::setPowerUp() {
|
||||
power_up_ = true;
|
||||
power_up_counter_ = POWERUP_COUNTER;
|
||||
power_up_time_accumulator_ = static_cast<float>(POWERUP_COUNTER) / 60.0f; // Convert frames to seconds
|
||||
power_sprite_visible_ = true; // Inicialmente visible cuando se activa el power-up
|
||||
in_power_up_ending_phase_ = false; // Empezar en fase normal
|
||||
bullet_color_toggle_ = false; // Resetear toggle
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable (time-based)
|
||||
@@ -784,7 +771,36 @@ void Player::updatePowerUp(float deltaTime) {
|
||||
power_up_ = power_up_time_accumulator_ > 0;
|
||||
if (!power_up_) {
|
||||
power_up_time_accumulator_ = 0;
|
||||
power_sprite_visible_ = false;
|
||||
in_power_up_ending_phase_ = false;
|
||||
bullet_color_toggle_ = false;
|
||||
bullet_color_ = Bullet::Color::YELLOW;
|
||||
} else {
|
||||
// Calcular visibilidad del power sprite
|
||||
const float TOTAL_POWERUP_TIME_S = static_cast<float>(POWERUP_COUNTER) / 60.0f;
|
||||
const float QUARTER_TIME_S = TOTAL_POWERUP_TIME_S / 4.0f;
|
||||
|
||||
if (power_up_time_accumulator_ > QUARTER_TIME_S) {
|
||||
// En los primeros 75% del tiempo, siempre visible
|
||||
power_sprite_visible_ = true;
|
||||
in_power_up_ending_phase_ = false;
|
||||
bullet_color_ = Bullet::Color::GREEN;
|
||||
} else {
|
||||
// En el último 25%, parpadea cada 20 frames (≈0.333s)
|
||||
constexpr float BLINK_PERIOD_S = 20.0f / 60.0f;
|
||||
constexpr float VISIBLE_PROPORTION = 4.0f / 20.0f;
|
||||
|
||||
float cycle_position = fmod(power_up_time_accumulator_, BLINK_PERIOD_S) / BLINK_PERIOD_S;
|
||||
power_sprite_visible_ = cycle_position >= VISIBLE_PROPORTION;
|
||||
in_power_up_ending_phase_ = true; // Activar modo alternancia de colores de balas
|
||||
bullet_color_ = power_sprite_visible_ ? Bullet::Color::GREEN : Bullet::Color::YELLOW;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
power_sprite_visible_ = false;
|
||||
in_power_up_ending_phase_ = false;
|
||||
bullet_color_toggle_ = false;
|
||||
bullet_color_ = Bullet::Color::YELLOW;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -816,7 +832,7 @@ void Player::shiftColliders() {
|
||||
}
|
||||
|
||||
// Pone las texturas del jugador
|
||||
void Player::setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &texture) {
|
||||
void Player::setPlayerTextures(const std::vector<std::shared_ptr<Texture>>& texture) {
|
||||
player_sprite_->setTexture(texture[0]);
|
||||
power_sprite_->setTexture(texture[1]);
|
||||
}
|
||||
@@ -905,12 +921,12 @@ void Player::shiftSprite() {
|
||||
}
|
||||
|
||||
// Hace sonar un sonido
|
||||
void Player::playSound(const std::string &name) const {
|
||||
void Player::playSound(const std::string& name) const {
|
||||
if (demo_) {
|
||||
return;
|
||||
}
|
||||
|
||||
static auto *audio_ = Audio::get();
|
||||
static auto* audio_ = Audio::get();
|
||||
audio_->playSound(name);
|
||||
}
|
||||
|
||||
@@ -919,6 +935,17 @@ auto Player::isRenderable() const -> bool {
|
||||
return !isTitleHidden();
|
||||
};
|
||||
|
||||
// Devuelve el color para la próxima bala (alterna si está en modo toggle)
|
||||
auto Player::getNextBulletColor() -> Bullet::Color {
|
||||
if (in_power_up_ending_phase_) {
|
||||
// En fase final: alternar entre verde y amarillo
|
||||
bullet_color_toggle_ = !bullet_color_toggle_;
|
||||
return bullet_color_toggle_ ? Bullet::Color::GREEN : Bullet::Color::YELLOW;
|
||||
}
|
||||
// Modo normal: sin power-up = amarillo, con power-up = verde
|
||||
return bullet_color_;
|
||||
}
|
||||
|
||||
// Añade una puntuación a la tabla de records
|
||||
void Player::addScoreToScoreBoard() const {
|
||||
if (hi_score_table_ == nullptr) {
|
||||
|
||||
Reference in New Issue
Block a user