SupaLidlGame/Entities/UnwantedFrequency.cs

87 lines
2.7 KiB
C#
Raw Normal View History

using Godot;
namespace SupaLidlGame.Entities;
2023-07-31 01:12:47 -07:00
public partial class UnwantedFrequency : Projectile, Utils.ITarget
{
[Export]
2023-07-31 01:12:47 -07:00
public Characters.Character CharacterTarget { get; set; }
[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; }
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");
Trail = TrailPosition.GetNode<Utils.Trail>("Trail");
2023-08-14 14:07:57 -07:00
Trail2 = TrailPosition2.GetNode<Utils.Trail>("Trail");
DeferDeathTimer = GetNode<Timer>("DeferDeath");
DeathParticles = GetNode<GpuParticles2D>("DeathParticles");
2023-07-21 02:54:13 -07:00
SpawnParticles = GetNode<GpuParticles2D>("SpawnParticles");
SpawnParticles.Emitting = true;
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;
if (CharacterTarget is not null && IsInstanceValid(CharacterTarget))
{
2023-07-31 01:12:47 -07:00
var pos = CharacterTarget.GlobalPosition;
var desired = GlobalPosition.DirectionTo(pos);
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);
DeferDeathTimer.Timeout += () =>
{
QueueFree();
};
DeferDeathTimer.Start();
DeathParticles.Emitting = true;
2023-08-05 23:50:08 -07:00
SpawnParticles.Emitting = false;
GetNode<AudioStreamPlayer2D>("Sound").Stop();
GetNode<AnimationPlayer>("AnimationPlayer").Play("death");
}
}