diff options
| author | alex <[email protected]> | 2026-07-25 16:46:32 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-25 16:46:32 +0200 |
| commit | 023c4f003d58c27cd2677307abe2c65bb09c2681 (patch) | |
| tree | d4e67206dadaf5a6433669297bef406b45056afc /scripts | |
| parent | 91fd5d80808fd177f97c4cc7e78b704efb5d6ce3 (diff) | |
| download | godot-testing-023c4f003d58c27cd2677307abe2c65bb09c2681.tar.xz godot-testing-023c4f003d58c27cd2677307abe2c65bb09c2681.zip | |
added enemy scene and piercing booleans for bullets, will be later refactored to work based on player stats
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/Enemy.cs | 40 | ||||
| -rw-r--r-- | scripts/Enemy.cs.uid | 1 |
2 files changed, 41 insertions, 0 deletions
diff --git a/scripts/Enemy.cs b/scripts/Enemy.cs new file mode 100644 index 0000000..cdbcd38 --- /dev/null +++ b/scripts/Enemy.cs @@ -0,0 +1,40 @@ +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 + } + } +}
\ No newline at end of file diff --git a/scripts/Enemy.cs.uid b/scripts/Enemy.cs.uid new file mode 100644 index 0000000..dd3ea0c --- /dev/null +++ b/scripts/Enemy.cs.uid @@ -0,0 +1 @@ +uid://cml2xy7flhfn6 |
