💫 Smooth health bar

This commit is contained in:
2024-08-08 13:18:09 +08:00
parent 58caef0014
commit f14a29d4e3
3 changed files with 24 additions and 8 deletions

View File

@ -107,10 +107,18 @@ public partial class Player : CharacterBody2D
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
private void GotDamage(double damage)
{
Health -= damage;
var protection = GetNode<Timer>("ProtectionCountdown");
var bar = GetNode<ProgressBar>("HUD/HealthBar");
bar.Value = Health / MaxHealth * 100;
if (protection.IsStopped())
{
Health -= damage;
var tween = CreateTween();
var bar = GetNode<ProgressBar>("HUD/HealthBar");
tween.TweenProperty(bar, "value", Health / MaxHealth * 100, 0.3);
protection.Start();
}
var shakableCamera = GetNode<CameraShake>("Camera2D");
shakableCamera.AddTrauma(0.5f);