diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index 65097f0..00b47f3 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -1361,6 +1361,25 @@ void Player::render() { }); } + // Blink d'immunitat: cada `blink_period_ms` ms, el render alterna + // entre la paleta normal i la paleta plana. La fase es deriva del + // timer restant — al spawn (timer = duration) toca paleta plana + // perquè el feedback sigui immediat. La Surface pot ser compartida + // entre dos jugadors del mateix personatge: com que el render del + // joc és seqüencial, el save/restore al voltant del render del + // sprite és segur — quan acaba aquesta funció, la Surface torna a + // tenir la paleta normal i la pròxima crida pot fer el seu propi + // swap independentment. + const bool BLINK_ON = + immunity_remaining_ms_ > 0.0F && + immunity_config.blink_period_ms > 0 && + !immunity_config.palette_key.empty() && + surface_ != nullptr && + (static_cast(immunity_remaining_ms_) / immunity_config.blink_period_ms) % 2 == 0; + if (BLINK_ON) { + surface_->setPalette(Resource::Cache::get().getPalette(immunity_config.palette_key)); + } + if (jump_z_ == 0.0F) { AnimatedSprite::render(); } else { @@ -1370,6 +1389,8 @@ void Player::render() { pos_.y = SAVED_Y; } + if (BLINK_ON) { surface_->setPalette(normal_palette_); } + if (CLIP_HOLE) { Rendering::popClip(); } }