2023-07-19 00:17:25 -07:00
|
|
|
using Godot;
|
|
|
|
|
|
|
|
namespace SupaLidlGame.Entities;
|
|
|
|
|
2023-07-31 01:12:47 -07:00
|
|
|
public partial class UnwantedFrequency : Projectile, Utils.ITarget
|
2023-07-19 00:17:25 -07:00
|
|
|
{
|
|
|
|
[Export]
|
2023-07-31 01:12:47 -07:00
|
|
|
public Characters.Character CharacterTarget { get; set; }
|
2023-07-19 00:17:25 -07:00
|
|
|
|
|
|
|
[Export]
|
|
|
|
public float HomingVelocity { get; set; } = 1;
|
|
|
|
|
2023-08-05 23:50:08 -07:00
|
|
|
public Utils.Trail Trail { get; private set; }
|
|
|
|
|
2023-08-14 14:07:57 -07:00
|
|
|
public Utils.Trail Trail2 { get; private set; }
|
|
|
|
|
2023-08-05 23:50:08 -07:00
|
|
|
public Node2D TrailRotation { get; private set; }
|
|
|
|
|
|
|
|
public Node2D TrailPosition { get; private set; }
|
|
|
|
|
2023-08-14 14:07:57 -07:00
|
|
|
public Node2D TrailPosition2 { get; private set; }
|
|
|
|
|
2023-08-05 23:50:08 -07:00
|
|
|
public GpuParticles2D DeathParticles { get; private set; }
|
|
|
|
|
|
|
|
public GpuParticles2D SpawnParticles { get; private set; }
|
|
|
|
|
|
|
|
public Timer DeferDeathTimer { get; private set; }
|
|
|
|
|
|
|
|
public SceneTreeTimer DeferNeutralTeamTimer { get; private set; }
|
2023-07-19 00:17:25 -07:00
|
|
|
|
|
|
|
private double _currentLifetime = 0;
|
|
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
{
|
|
|
|
TrailRotation = GetNode<Node2D>("TrailRotation");
|
|
|
|
TrailPosition = TrailRotation.GetNode<Node2D>("TrailPosition");
|
2023-08-14 14:07:57 -07:00
|
|
|
TrailPosition2 = TrailRotation.GetNode<Node2D>("TrailPosition2");
|
2023-07-19 00:17:25 -07:00
|
|
|
Trail = TrailPosition.GetNode<Utils.Trail>("Trail");
|
2023-08-14 14:07:57 -07:00
|
|
|
Trail2 = TrailPosition2.GetNode<Utils.Trail>("Trail");
|
2023-07-19 00:17:25 -07:00
|
|
|
DeferDeathTimer = GetNode<Timer>("DeferDeath");
|
|
|
|
DeathParticles = GetNode<GpuParticles2D>("DeathParticles");
|
2023-07-21 02:54:13 -07:00
|
|
|
SpawnParticles = GetNode<GpuParticles2D>("SpawnParticles");
|
|
|
|
SpawnParticles.Emitting = true;
|
2023-07-19 00:17:25 -07:00
|
|
|
Hitbox.Hit += (BoundingBoxes.BoundingBox box) =>
|
|
|
|
{
|
|
|
|
if (box is BoundingBoxes.Hurtbox && box.Faction != Hitbox.Faction)
|
|
|
|
{
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
base._Ready();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void _Process(double delta)
|
|
|
|
{
|
|
|
|
_currentLifetime += delta;
|
|
|
|
float radians = (float)_currentLifetime * 24;
|
|
|
|
TrailRotation.Rotation = Direction.Angle();
|
|
|
|
TrailPosition.Position = new Vector2(0, 4 * Mathf.Sin(radians));
|
2023-08-14 14:07:57 -07:00
|
|
|
TrailPosition2.Position = -TrailPosition.Position;
|
2023-07-19 00:17:25 -07:00
|
|
|
|
2024-06-24 16:07:15 -07:00
|
|
|
if (CharacterTarget is not null && IsInstanceValid(CharacterTarget))
|
2023-07-19 00:17:25 -07:00
|
|
|
{
|
2023-07-31 01:12:47 -07:00
|
|
|
var pos = CharacterTarget.GlobalPosition;
|
|
|
|
var desired = GlobalPosition.DirectionTo(pos);
|
2023-07-19 00:17:25 -07:00
|
|
|
Direction += (desired - Direction) * HomingVelocity * (float)delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
base._Process(delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Die()
|
|
|
|
{
|
2023-08-14 14:07:57 -07:00
|
|
|
IsDead = Trail.IsDead = Trail2.IsDead = true;
|
2023-07-21 02:54:13 -07:00
|
|
|
Hitbox.SetDeferred("monitoring", false);
|
2023-07-19 00:17:25 -07:00
|
|
|
DeferDeathTimer.Timeout += () =>
|
|
|
|
{
|
|
|
|
QueueFree();
|
|
|
|
};
|
|
|
|
DeferDeathTimer.Start();
|
|
|
|
DeathParticles.Emitting = true;
|
2023-08-05 23:50:08 -07:00
|
|
|
SpawnParticles.Emitting = false;
|
2023-07-19 00:17:25 -07:00
|
|
|
GetNode<AudioStreamPlayer2D>("Sound").Stop();
|
|
|
|
GetNode<AnimationPlayer>("AnimationPlayer").Play("death");
|
|
|
|
}
|
|
|
|
}
|