37 lines
956 B
C#
37 lines
956 B
C#
using Godot;
|
|
using Newlon.Systems.Effects;
|
|
|
|
namespace Newlon.Components;
|
|
|
|
//
|
|
// Projectile that travels from left to right
|
|
//
|
|
|
|
public partial class LinearProjectile : Area2D, IProjectile
|
|
{
|
|
[Export(hintString: "suffix:tile/sec")]
|
|
private float _speed;
|
|
[Export]
|
|
private int _damage;
|
|
[Export]
|
|
private Effect _impactEffect;
|
|
private int _line;
|
|
public int Line { get => _line; set { _line = value; } }
|
|
|
|
public override void _PhysicsProcess(double delta)
|
|
{
|
|
Translate(Vector2.Right * _speed * (float)delta * Utility.TileWidth);
|
|
}
|
|
|
|
public void OnAreaEntered(Area2D area)
|
|
{
|
|
var entity = area.GetParent<IEntity>();
|
|
if (entity != null && entity.Line == _line)
|
|
{
|
|
entity.TakeDamage(_damage);
|
|
if (entity is IEffectHandler effectHandler && _impactEffect != null)
|
|
effectHandler.GiveEffect(_impactEffect);
|
|
QueueFree();
|
|
}
|
|
}
|
|
}
|