Traveller/scripts/damage/DamageNumber.cs
2024-04-28 21:55:19 +08:00

49 lines
1.1 KiB
C#

using ColdMint.scripts.debug;
using Godot;
namespace ColdMint.scripts.damage;
/// <summary>
/// <para>DamageNumber</para>
/// <para>伤害数字</para>
/// </summary>
public partial class DamageNumber : CharacterBody2D
{
private VisibleOnScreenNotifier2D _visibleOnScreenNotifier2D;
public override void _Ready()
{
_visibleOnScreenNotifier2D = GetNode<VisibleOnScreenNotifier2D>("VisibleOnScreenNotifier2D");
_visibleOnScreenNotifier2D.ScreenExited += ScreenExited;
}
private void ScreenExited()
{
//When the damage number leaves the screen, destroy the damage number
//当伤害数字离开屏幕时,销毁伤害数字
QueueFree();
}
private float gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle();
private bool enableGravity;
public void SetVelocity(Vector2 velocity)
{
Velocity = velocity;
enableGravity = true;
}
public override void _PhysicsProcess(double delta)
{
var velocity = Velocity;
if (enableGravity)
{
velocity.Y += gravity * (float)delta;
}
Velocity = velocity;
MoveAndSlide();
}
}