Refactor Player class to use components, also use components in Enemy class types and fiddle with boss structure
This commit is contained in:
@@ -10,10 +10,19 @@ public abstract partial class Enemy2D : Enemy
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Node] private Area3D LineOfSight { get; set; } = default!;
|
||||
|
||||
[Node] private RayCast3D Raycast { get; set; } = default!;
|
||||
|
||||
public override IEnemyModelView EnemyModelView => _enemyModelView;
|
||||
|
||||
[Node] private EnemyModelView2D _enemyModelView { get; set; } = default!;
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
LineOfSight.BodyEntered += LineOfSight_BodyEntered;
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
_enemyModelView.SetCurrentDirection(GlobalBasis, -_player.CurrentBasis.Z);
|
||||
@@ -45,4 +54,21 @@ public abstract partial class Enemy2D : Enemy
|
||||
protected void EngagePlayerBehavior_TakeAction() => EnemyModelView.PlayPrimaryAttackAnimation();
|
||||
|
||||
protected void EngagePlayerBehavior_AcquireTarget() => LookAt(new Vector3(_player.CurrentPosition.X, GlobalPosition.Y, _player.CurrentPosition.Z), Vector3.Up, true);
|
||||
|
||||
private void LineOfSight_BodyEntered(Node3D body)
|
||||
{
|
||||
var overlappingBodies = LineOfSight.GetOverlappingBodies();
|
||||
foreach (var _ in overlappingBodies)
|
||||
{
|
||||
if (Raycast.GlobalPosition != _player.CurrentPosition)
|
||||
Raycast.LookAt(_player.CurrentPosition, Vector3.Up);
|
||||
Raycast.ForceRaycastUpdate();
|
||||
if (Raycast.IsColliding())
|
||||
{
|
||||
var collider = Raycast.GetCollider();
|
||||
if (collider is IPlayer)
|
||||
_enemyLogic.Input(new EnemyLogic.Input.Follow());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user