Exploding barrels

This commit is contained in:
MaddoScientisto 2024-06-09 00:34:36 +02:00
commit 71eeb3f1d1
12 changed files with 132 additions and 20 deletions

View file

@ -7,6 +7,9 @@ public partial class Bullet : Area2D
[Export]
public float Speed = 1900f;
[Export]
public float Damage = 1f;
private Vector2 _direction = Vector2.Right;
//public delegate void BulletHitEventHandler(Node Body);
@ -53,15 +56,28 @@ public partial class Bullet : Area2D
{
if (body.IsInGroup("Solid"))
{
Debug.WriteLine("Collision");
//Debug.WriteLine("Collision");
QueueFree();
}
else if (body.IsInGroup("Destroyable"))
{
Debug.WriteLine("Collision with destroyable object body");
QueueFree();
}
}
private void _on_area_entered(Area2D area)
{
// Replace with function body.
if (area.IsInGroup("Destroyable") && area is IDestructible destructible)
{
//Debug.WriteLine("Collision with destroyable object area");
destructible.Hit(Damage);
QueueFree();
}
}
}

6
Scripts/IDestructible.cs Normal file
View file

@ -0,0 +1,6 @@
public interface IDestructible
{
public void Hit(float damage);
public bool IsDestroyed();
}