SupaLidlGame/UI/FloatingText.cs

51 lines
1.3 KiB
C#
Raw Normal View History

2022-11-25 09:11:46 -08:00
using Godot;
using System;
2023-06-03 18:21:46 -07:00
namespace SupaLidlGame.UI;
public partial class FloatingText : Node2D
2022-11-25 09:11:46 -08:00
{
2023-06-03 18:21:46 -07:00
private Label _label;
[Export]
public string Text { get; set; }
public override void _Ready()
2022-11-25 09:11:46 -08:00
{
2023-06-03 18:21:46 -07:00
_label = GetNode<Label>("Label");
_label.Text = Text;
2022-11-25 09:11:46 -08:00
2023-06-03 18:21:46 -07:00
Tween tween = GetTree().CreateTween()
.SetEase(Tween.EaseType.Out)
.SetTrans(Tween.TransitionType.Quint)
.SetParallel();
2022-11-25 09:11:46 -08:00
2023-06-03 18:21:46 -07:00
Random rng = new Random();
2022-11-25 09:11:46 -08:00
2023-06-03 18:21:46 -07:00
float randomFloat(float min, float max)
2022-11-25 09:11:46 -08:00
{
2023-06-03 18:21:46 -07:00
return (float)rng.NextDouble() * (max - min) + min;
2022-11-25 09:11:46 -08:00
}
2023-06-03 18:21:46 -07:00
GD.Print(GlobalPosition);
Position += new Vector2(randomFloat(-8, 8), 0);
var endPos = Position + new Vector2(0, randomFloat(-16, -8));
var endMod = new Color(1, 1, 1, 0);
var endScale = Scale * 0.5f;
tween.TweenProperty(this, "position", endPos, 0.5f);
tween.SetTrans(Tween.TransitionType.Linear);
tween.TweenProperty(this, "modulate", endMod, 0.5f).SetDelay(1.0f);
tween.TweenProperty(this, "scale", endScale, 0.5f).SetDelay(1.0f);
tween.TweenCallback(new Callable(this, nameof(OnTweenFinished)))
.SetDelay(2.5f);
base._Ready();
}
public void OnTweenFinished()
{
QueueFree();
2022-11-25 09:11:46 -08:00
}
}