Rework enemy behavior (still in progress but shouldn't crash)
This commit is contained in:
48
Zennysoft.Game.Ma/src/enemy/Enemy2D.cs
Normal file
48
Zennysoft.Game.Ma/src/enemy/Enemy2D.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public abstract partial class Enemy2D : Enemy
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
public override IEnemyModelView EnemyModelView => _enemyModelView;
|
||||
|
||||
[Node] private EnemyModelView2D _enemyModelView { get; set; } = default!;
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
_enemyModelView.SetCurrentDirection(GlobalBasis, -_player.CurrentBasis.Z);
|
||||
}
|
||||
|
||||
protected void PlayerDetector_BodyEntered(Node3D node)
|
||||
{
|
||||
if (node is IPlayer)
|
||||
_enemyLogic.Input(new EnemyLogic.Input.ReachedPlayer());
|
||||
}
|
||||
|
||||
protected void PlayerDetector_BodyExited(Node3D node)
|
||||
{
|
||||
if (node is IPlayer)
|
||||
_enemyLogic.Input(new EnemyLogic.Input.Follow());
|
||||
}
|
||||
|
||||
protected void OnVelocityComputed(Vector3 safeVelocity)
|
||||
{
|
||||
Velocity = safeVelocity;
|
||||
LookAtTarget(safeVelocity);
|
||||
if (Velocity > Vector3.Zero)
|
||||
_enemyLogic.Input(new EnemyLogic.Input.Move());
|
||||
else
|
||||
_enemyLogic.Input(new EnemyLogic.Input.Idle());
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
protected void EngagePlayerBehavior_TakeAction() => EnemyModelView.PlayPrimaryAttackAnimation();
|
||||
|
||||
protected void EngagePlayerBehavior_AcquireTarget() => LookAt(new Vector3(_player.CurrentPosition.X, GlobalPosition.Y, _player.CurrentPosition.Z), Vector3.Up, true);
|
||||
}
|
||||
Reference in New Issue
Block a user