spawning
This commit is contained in:
@@ -3,28 +3,34 @@ using Godot;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class Enemy : CharacterBody3D, IDamageable, IDamageMaker, IHealthable, IKillable
|
||||
public partial class Enemy : CharacterBody3D, IDamageable, IDamageMaker, IHealthable, IKillable, IMoveable
|
||||
{
|
||||
public event Action<IDamageable, float> DamageTaken;
|
||||
|
||||
public event Action<IHealthable, float> HealthChanged;
|
||||
public event Action<IHealthable> HealthDepleted;
|
||||
|
||||
[Export]
|
||||
public Node3D Target { get; set; }
|
||||
|
||||
[Export]
|
||||
public RDamage GetDamageDealt { get; set; }
|
||||
public Node3D Target { get; set; }
|
||||
|
||||
[Export]
|
||||
public Node CHealth { get; set; }
|
||||
[Export]
|
||||
public RHealth RHealth { get; set; }
|
||||
|
||||
public float CurrentHealth { get; set; }
|
||||
|
||||
[Export]
|
||||
public Node CDamage { get; set; }
|
||||
|
||||
[Export]
|
||||
public RDamage RDamage { get; set; }
|
||||
|
||||
[Export]
|
||||
public Node CMovement { get; set; }
|
||||
|
||||
[Export]
|
||||
public RMovement RMovement { get; set; }
|
||||
|
||||
|
||||
[Export]
|
||||
public RDeathEffect[] DeathEffects { get; set; }
|
||||
|
||||
@@ -38,13 +44,21 @@ public partial class Enemy : CharacterBody3D, IDamageable, IDamageMaker, IHealth
|
||||
if (CDamage is IDamageable damageable) damageable.DamageTaken += ReduceHealth;
|
||||
if (CHealth is IHealthable healthable) healthable.HealthDepleted += Kill;
|
||||
}
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
if (CMovement is IMoveable moveable && RMovement != null) moveable.RMovement = RMovement;
|
||||
if (CHealth is IHealthable healthable && RHealth != null)
|
||||
{
|
||||
healthable.RHealth = RHealth;
|
||||
healthable.CurrentHealth = RHealth.StartingHealth;
|
||||
}
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var targetPlanar = new Vector3(Target.GlobalPosition.X, GlobalPosition.Y, Target.GlobalPosition.Z);
|
||||
LookAt(targetPlanar);
|
||||
|
||||
if (CMovement is not IMoveable movement) return;
|
||||
|
||||
var inputs = new MovementInputs(
|
||||
Velocity: Velocity,
|
||||
@@ -53,15 +67,21 @@ public partial class Enemy : CharacterBody3D, IDamageable, IDamageMaker, IHealth
|
||||
gravity: GetGravity(),
|
||||
delta: delta
|
||||
);
|
||||
Velocity = movement!.ComputeVelocity(inputs);
|
||||
Velocity = ComputeVelocity(inputs);
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
public Vector3 ComputeVelocity(MovementInputs inputs)
|
||||
{
|
||||
if (CMovement is not IMoveable movement) return Vector3.Zero;
|
||||
return movement!.ComputeVelocity(inputs);
|
||||
}
|
||||
|
||||
public void OnDamageBoxTriggered(Node3D body)
|
||||
{
|
||||
GD.Print("Take this!");
|
||||
if (body is not IDamageable damageable) return;
|
||||
damageable.TakeDamage(GetDamageDealt);
|
||||
damageable.TakeDamage(RDamage);
|
||||
}
|
||||
|
||||
public float TakeDamage(RDamage damage)
|
||||
|
||||
Reference in New Issue
Block a user