using Godot; using testing.interfaces; // Match your namespace public partial class Enemy : CharacterBody2D, IDamageable { [Export] public float MoveSpeed { get; set; } = 150.0f; [Export] public float MaxHealth { get; set; } = 30.0f; private Node2D _player; public override void _Ready() { // Find the player automatically using the group we just set up _player = GetTree().GetFirstNodeInGroup("player") as Node2D; } public override void _PhysicsProcess(double delta) { if (_player == null) return; // Calculate direction vector pointing from the enemy to the player Vector2 direction = GlobalPosition.DirectionTo(_player.GlobalPosition); // Move towards the player Velocity = direction * MoveSpeed; MoveAndSlide(); } public void TakeDamage(float amount) { MaxHealth -= amount; GD.Print($"Enemy took {amount} damage! Health remaining: {MaxHealth}"); if (MaxHealth <= 0) { GD.Print("Enemy defeated!"); QueueFree(); // Removes the enemy from the game } } }