Traveller/scripts/damage/DamageNumber.cs

48 lines
1.0 KiB
C#
Raw Normal View History

2024-04-28 13:55:19 +00:00
using Godot;
namespace ColdMint.scripts.damage;
/// <summary>
/// <para>DamageNumber</para>
/// <para>伤害数字</para>
/// </summary>
public partial class DamageNumber : CharacterBody2D
{
private VisibleOnScreenNotifier2D? _visibleOnScreenNotifier2D;
2024-04-28 13:55:19 +00:00
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();
2024-04-28 13:55:19 +00:00
private bool _enableGravity;
2024-04-28 13:55:19 +00:00
2024-08-15 14:58:28 +00:00
public new void SetVelocity(Vector2 velocity)
2024-04-28 13:55:19 +00:00
{
Velocity = velocity;
_enableGravity = true;
2024-04-28 13:55:19 +00:00
}
public override void _PhysicsProcess(double delta)
{
var velocity = Velocity;
if (_enableGravity)
2024-04-28 13:55:19 +00:00
{
velocity.Y += _gravity * (float)delta;
2024-04-28 13:55:19 +00:00
}
Velocity = velocity;
MoveAndSlide();
}
}