newlon/scripts/components/LinearProjectile.cs
2025-06-28 02:44:42 +05:00

49 lines
1.3 KiB
C#

using Godot;
using Newlon.Components.Level;
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;
[Export]
private Utility.DamageTypes _damageType = Utility.DamageTypes.PHYSICAL;
[Export]
private PackedScene particles;
private int _line;
private bool used = false;
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)
{
if (used == true) return;
var entity = area.GetParent<IEntity>();
if (entity != null)
{
entity.TakeDamage(_damage,this,_damageType);
used = true;
if (entity is IEffectHandler effectHandler && _impactEffect != null)
effectHandler.GiveEffect(_impactEffect);
PoolContainer.Instance.SpawnParticles(particles, GlobalPosition);
QueueFree();
}
}
}