92 lines
2.1 KiB
C#
92 lines
2.1 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Entities/Follower.cs")]
|
|
public partial class Follower : Entity
|
|
{
|
|
[Export(PropertyHint.None, "")]
|
|
public int followIndex;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public Sprite2D DWOverlay;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public Sprite2D soul;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public Area2D soulHitbox;
|
|
|
|
private const int followDelay = 20;
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
base._EnterTree();
|
|
base.CollisionLayer = 524288u;
|
|
base.CollisionMask = 524288u;
|
|
Player instance = Player.instance;
|
|
if (instance != null)
|
|
{
|
|
List<Follower> followers = instance.followers;
|
|
if (((followers != null) ? new bool?(!followers.Contains(this)) : ((bool?)null)) == true)
|
|
{
|
|
Player.instance.followers.Add(this);
|
|
}
|
|
}
|
|
Room.current?.entities.Add(this);
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
base._Process(delta);
|
|
if (sprite != null)
|
|
{
|
|
if (Player.instance.dangerZoneCD > 0f)
|
|
{
|
|
sprite.SelfModulate = sprite.SelfModulate.Lerp(Main.colorDark, Main.deltaTime * 0.2f);
|
|
}
|
|
else
|
|
{
|
|
sprite.SelfModulate = sprite.SelfModulate.Lerp(Main.colorWhite, Main.deltaTime * 0.2f);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TryUpdateComponents(force: true);
|
|
}
|
|
if (Main.inEvent == null && Player.instance.splitEntity != this)
|
|
{
|
|
DoMovement();
|
|
}
|
|
}
|
|
|
|
public void DoMovement(bool force = false)
|
|
{
|
|
if (Player.instance.slide == null || base.GlobalPosition.Y > Player.instance.GlobalPosition.Y)
|
|
{
|
|
if (!Player.instance.waitForMove || force)
|
|
{
|
|
Vector2 vector = Player.instance.pos[100 - 20 * (followIndex + 1)];
|
|
if (base.GlobalPosition.DistanceSquaredTo(vector) > 0.2f)
|
|
{
|
|
LookAt(vector);
|
|
base.GlobalPosition = base.GlobalPosition.Lerp(vector, Main.deltaTime * 0.2f);
|
|
currentAnim = Animations.Walk;
|
|
}
|
|
else
|
|
{
|
|
currentAnim = Animations.Idle;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
currentAnim = Animations.Slide;
|
|
base.GlobalPosition = base.GlobalPosition.Lerp(Player.instance.GlobalPosition + Vector2.Up * 16f * (followIndex + 1), Main.deltaTime * 0.1f);
|
|
}
|
|
}
|
|
|
|
}
|