mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-08 23:05:53 +00:00
Fix drops on enemies and treasure rooms
This commit is contained in:
parent
2c72f36108
commit
8d71a59d84
25 changed files with 81 additions and 40 deletions
|
|
@ -308,9 +308,11 @@ public partial class RogueliteRoom : Node2D
|
|||
|
||||
GD.Print($"Spawning {item.ItemKey} in treasure spot");
|
||||
|
||||
var dropInstance = item.Spawn(marker);
|
||||
|
||||
// Spawn
|
||||
var dropScene = GD.Load<PackedScene>(item.DropScenePath);
|
||||
var dropInstance = marker.CreateChild<Node2D>(dropScene);
|
||||
// var dropScene = GD.Load<PackedScene>(item.DropScenePath);
|
||||
// var dropInstance = marker.CreateChild<Node2D>(dropScene);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ public partial class ItemDrop : RigidBody2D
|
|||
private RandomNumberGenerator _rng = new();
|
||||
public override void _Ready()
|
||||
{
|
||||
PackedScene dropScene = GD.Load<PackedScene>(ItemToDrop.DropScenePath);
|
||||
Node dropInstance = dropScene.Instantiate();
|
||||
AddChild(dropInstance);
|
||||
|
||||
dropInstance.Owner = this;
|
||||
var dropInstance = ItemToDrop.Spawn(this, true);
|
||||
|
||||
//Node dropInstance = dropScene.Instantiate();
|
||||
//AddChild(dropInstance);
|
||||
CallDeferred(MethodName.DelayedAddOwner, dropInstance);
|
||||
|
||||
float angle = _rng.RandfRange(0, Mathf.Tau); // 0 to 2π
|
||||
Vector2 direction = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)).Normalized();
|
||||
|
|
@ -24,4 +24,9 @@ public partial class ItemDrop : RigidBody2D
|
|||
// Apply impulse in that direction
|
||||
ApplyImpulse(direction * StartingSpeed);
|
||||
}
|
||||
|
||||
private void DelayedAddOwner(Node2D node)
|
||||
{
|
||||
node.Owner = this;
|
||||
}
|
||||
}
|
||||
|
|
@ -29,11 +29,11 @@ public partial class LootItem : Resource
|
|||
//[Export] public PackedScene HudItemScene;
|
||||
[Export(PropertyHint.File)] public StringName DropScenePath { get; private set; } // Has to be a string path to avoid recursion issues
|
||||
|
||||
public ItemPickup Spawn(Node2D parent)
|
||||
public ItemPickup Spawn(Node2D sibling, bool dropAsChild = false)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(DropScenePath)) return null;
|
||||
var itemScene = GD.Load<PackedScene>(DropScenePath);
|
||||
var spawnedItem = parent.CreateSibling<ItemPickup>(itemScene);
|
||||
var spawnedItem = dropAsChild ? sibling.CreateChild<ItemPickup>(itemScene) : sibling.CreateSibling<ItemPickup>(itemScene);
|
||||
|
||||
spawnedItem.Name = this.ItemKey;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue