Knockback tag implementation
This commit is contained in:
36
src/items/thrown/ThrownItem.cs
Normal file
36
src/items/thrown/ThrownItem.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user