summaryrefslogtreecommitdiff
path: root/Bullet.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Bullet.cs')
-rw-r--r--Bullet.cs12
1 files changed, 9 insertions, 3 deletions
diff --git a/Bullet.cs b/Bullet.cs
index e613849..4ca9520 100644
--- a/Bullet.cs
+++ b/Bullet.cs
@@ -1,14 +1,17 @@
using Godot;
-
+using testing.interfaces;
public partial class Bullet : Area2D
{
[Export] public float Speed { get; set; } = 600.0f;
+ [Export] public float Damage { get; set; } = 10.0f;
public Vector2 Direction { get; set; } = Vector2.Zero;
public override void _Ready()
{
// Subscribe to the built-in BodyEntered event when the bullet is spawned
BodyEntered += OnBodyEntered;
+
+ Rotation = Direction.Angle();
}
public override void _PhysicsProcess(double delta)
@@ -19,7 +22,10 @@ public partial class Bullet : Area2D
// This method is triggered automatically when the bullet hits a physics body
private void OnBodyEntered(Node2D body)
{
- // QueueFree safely deletes this node and all its children at the end of the current frame
- QueueFree();
+ if (body is IDamageable target)
+ {
+ // If it does, deal damage!
+ target.TakeDamage(Damage);
+ }
}
}