Knockback tag implementation

This commit is contained in:
2024-09-18 16:45:00 -07:00
parent 884f283ead
commit d5c81d6587
11 changed files with 34 additions and 51 deletions

View File

@@ -0,0 +1,36 @@
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using GameJamDungeon;
using Godot;
[Meta(typeof(IAutoNode))]
public partial class ThrownItem : RigidBody3D
{
public override void _Notification(int what) => this.Notify(what);
[Dependency] public IGame Game => this.DependOn<IGame>();
[Node] public Sprite2D Sprite { get; set; } = default!;
private int _damage = 0;
public void OnResolved()
{
BodyEntered += ThrownItem_BodyEntered;
GlobalPosition = Game.Player.GlobalPosition + Vector3.Up;
AddCollisionExceptionWith((Node)Game.Player);
}
private void ThrownItem_BodyEntered(Node body)
{
if (body is IEnemy enemy)
enemy.EnemyLogic.Input(new EnemyLogic.Input.HitByPlayer(_damage));
QueueFree();
}
public void Throw(ThrowableItemStats throwableItemStats)
{
_damage = throwableItemStats.Damage;
ApplyCentralImpulse(Game.Player.GlobalBasis.Z.Normalized() * -20.0f);
}
}