Enemies drop items with speed

This commit is contained in:
MaddoScientisto 2025-03-23 16:39:47 +01:00
commit 95837b75fe
8 changed files with 84 additions and 25 deletions

View file

@ -1,4 +1,5 @@
using Cirno.Scripts.Resources;
using Cirno.Scripts.Interactables;
using Cirno.Scripts.Resources;
using Godot;
namespace Cirno.Scripts.Components.FSM.Enemy;
@ -9,8 +10,12 @@ public partial class EnemyDropsProvider : Node2D
[Export] public float DropRadius { get; private set; } = 8f;
[Export] public float DropSpeed { get; set; } = 40f;
[Export]
public EnemyStorageModule StorageModule { get; private set; }
public EnemyStorageModule StorageModule { get; private set; }
private readonly StringName _dropPhysicsWrapperScene = "uid://d3hds3dbosfcm";
public void DropLoot()
{
@ -29,23 +34,30 @@ public partial class EnemyDropsProvider : Node2D
private void DropItem(LootItem item)
{
if (!string.IsNullOrWhiteSpace(item.DropScenePath))
{
GD.Print($"Dropped item: {item.ItemName}");
var scene = GD.Load<PackedScene>(item.DropScenePath);
var droppedItem = StorageModule.Root.CreateSibling<Node2D>(scene);
var dropScene = GD.Load<PackedScene>(_dropPhysicsWrapperScene);
var dropInstance = StorageModule.Root.CreateSibling<ItemDrop>(dropScene);
dropInstance.ItemToDrop = item;
dropInstance.StartingSpeed = DropSpeed;
// Generate random point within DropRadius
float angle = _rng.RandfRange(0, Mathf.Tau); // Random angle (0 to 2π)
float radius = _rng.RandfRange(0, DropRadius); // Random radius within range
// Convert polar to cartesian coordinates
float xOffset = radius * Mathf.Cos(angle);
float yOffset = radius * Mathf.Sin(angle);
Vector2 spawnPosition = StorageModule.Root.GlobalPosition + new Vector2(xOffset, yOffset);
droppedItem.GlobalPosition = spawnPosition;
// var scene = GD.Load<PackedScene>(item.DropScenePath);
// var droppedItem = StorageModule.Root.CreateSibling<Node2D>(scene);
//
// // Generate random point within DropRadius
// float angle = _rng.RandfRange(0, Mathf.Tau); // Random angle (0 to 2π)
// float radius = _rng.RandfRange(0, DropRadius); // Random radius within range
//
// // Convert polar to cartesian coordinates
// float xOffset = radius * Mathf.Cos(angle);
// float yOffset = radius * Mathf.Sin(angle);
//
// Vector2 spawnPosition = StorageModule.Root.GlobalPosition + new Vector2(xOffset, yOffset);
//
// droppedItem.GlobalPosition = spawnPosition;
}
else
{