Add DamageNumberManager and DamageNumber for displaying damage feedback

This commit is contained in:
2025-08-31 02:30:42 +02:00
parent 4b7c38397c
commit 021e984877
10 changed files with 134 additions and 5 deletions

View File

@@ -0,0 +1,41 @@
using System.Globalization;
using Godot;
namespace Mr.BrickAdventures.scripts.UI;
[GlobalClass]
public partial class DamageNumber : Label
{
[Export] public float Duration { get; set; } = 0.8f;
[Export] public float FallDistance { get; set; } = 40f;
[Export] public float HorizontalDrift { get; set; } = 15f;
public void ShowDamage(float damageAmount, Vector2 position)
{
Text = Mathf.Round(damageAmount * 100f).ToString(CultureInfo.InvariantCulture);
GlobalPosition = position;
var rng = new RandomNumberGenerator();
var horizontalOffset = rng.RandfRange(-HorizontalDrift, HorizontalDrift);
var startPosition = GlobalPosition;
var endPosition = GlobalPosition + new Vector2(horizontalOffset, FallDistance);
var startColor = Colors.White;
startColor.A = 1f;
Modulate = startColor;
var tween = CreateTween();
tween.SetParallel();
tween.TweenProperty(this, "global_position", endPosition, Duration)
.SetTrans(Tween.TransitionType.Quad)
.SetEase(Tween.EaseType.In);
tween.Chain().TweenProperty(this, "modulate:a", 0f, Duration * 0.5f)
.SetTrans(Tween.TransitionType.Sine)
.SetEase(Tween.EaseType.Out);
tween.TweenCallback(Callable.From(QueueFree));
}
}