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; [Export] public bool PierceEntity { get; set; } = false; [Export] public bool PierceTerrain { get; set; } = false; 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) { Position += Direction * Speed * (float)delta; } // This method is triggered automatically when the bullet hits a physics body private void OnBodyEntered(Node2D body) { if (body is IDamageable target) { // If it does, deal damage! target.TakeDamage(Damage); if(!PierceEntity){QueueFree();} } else{if(!PierceTerrain){QueueFree();}} } }