2025-03-23 16:39:47 +01:00
|
|
|
|
using Cirno.Scripts.Resources;
|
|
|
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Cirno.Scripts.Interactables;
|
|
|
|
|
|
|
|
|
|
|
|
public partial class ItemDrop : RigidBody2D
|
|
|
|
|
|
{
|
|
|
|
|
|
[Export] public LootItem ItemToDrop { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[Export] public float StartingSpeed { get; set; } = 40f;
|
|
|
|
|
|
|
|
|
|
|
|
private RandomNumberGenerator _rng = new();
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
|
|
{
|
|
|
|
|
|
PackedScene dropScene = GD.Load<PackedScene>(ItemToDrop.DropScenePath);
|
|
|
|
|
|
Node dropInstance = dropScene.Instantiate();
|
|
|
|
|
|
AddChild(dropInstance);
|
2025-03-28 19:47:10 +01:00
|
|
|
|
|
|
|
|
|
|
dropInstance.Owner = this;
|
2025-03-23 16:39:47 +01:00
|
|
|
|
|
|
|
|
|
|
float angle = _rng.RandfRange(0, Mathf.Tau); // 0 to 2π
|
|
|
|
|
|
Vector2 direction = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)).Normalized();
|
|
|
|
|
|
|
|
|
|
|
|
// Apply impulse in that direction
|
|
|
|
|
|
ApplyImpulse(direction * StartingSpeed);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|