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
|
|
|
|
{
|
2024-05-08 10:22:04 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2024-05-08 10:22:04 +00:00
|
|
|
private float _gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle();
|
2024-04-28 13:55:19 +00:00
|
|
|
|
2024-05-08 10:22:04 +00:00
|
|
|
private bool _enableGravity;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
|
|
|
public void SetVelocity(Vector2 velocity)
|
|
|
|
{
|
|
|
|
Velocity = velocity;
|
2024-05-08 10:22:04 +00:00
|
|
|
_enableGravity = true;
|
2024-04-28 13:55:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void _PhysicsProcess(double delta)
|
|
|
|
{
|
|
|
|
var velocity = Velocity;
|
2024-05-08 10:22:04 +00:00
|
|
|
if (_enableGravity)
|
2024-04-28 13:55:19 +00:00
|
|
|
{
|
2024-05-08 10:22:04 +00:00
|
|
|
velocity.Y += _gravity * (float)delta;
|
2024-04-28 13:55:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Velocity = velocity;
|
|
|
|
MoveAndSlide();
|
|
|
|
}
|
|
|
|
}
|