mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 10:45:55 +00:00
Enemies drop items with speed
This commit is contained in:
parent
632b5cfa6b
commit
95837b75fe
8 changed files with 84 additions and 25 deletions
25
Scripts/Interactables/ItemDrop.cs
Normal file
25
Scripts/Interactables/ItemDrop.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
1
Scripts/Interactables/ItemDrop.cs.uid
Normal file
1
Scripts/Interactables/ItemDrop.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://q806qngbukt8
|
||||
|
|
@ -6,7 +6,7 @@ namespace Cirno.Scripts.Interactables;
|
|||
|
||||
public partial class ItemPickup : Interactable
|
||||
{
|
||||
[Export] public Array<LootItem> LootTable = new Array<LootItem>();
|
||||
[Export] public Array<LootItem> LootTable = [];
|
||||
|
||||
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue