113 lines
2.8 KiB
C#
113 lines
2.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.Collections;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Events/SchoolDWChase.cs")]
|
|
public partial class SchoolDWChase : Node2D
|
|
{
|
|
[Export(PropertyHint.None, "")]
|
|
public Node2D[] bullets;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public Node2D[] pos;
|
|
|
|
private float cd;
|
|
|
|
private SignalAwaiter playerHurt;
|
|
|
|
private readonly StringName hurtAnim = "Hurt";
|
|
|
|
private readonly StringName surpriseAnim = "Surprise";
|
|
|
|
private IEnumerator Push()
|
|
{
|
|
Party.StopMoving(idleAnim: false);
|
|
yield return null;
|
|
Player.instance.anim.Play(hurtAnim);
|
|
Player.instance.followers[0].anim.Play(surpriseAnim);
|
|
Vector2 p = Player.instance.GlobalPosition;
|
|
Vector2 l = p;
|
|
float b = 12.5f;
|
|
Vector2 t;
|
|
Common.RayCast rayCast;
|
|
do
|
|
{
|
|
t = l + Vector2.Left * 20f;
|
|
rayCast = Common.DoRaycast(l, t, 1u, new Array<Rid>
|
|
{
|
|
Player.instance.GetRid(),
|
|
Player.instance.followers[0].GetRid()
|
|
});
|
|
l = t;
|
|
b += 2.5f;
|
|
}
|
|
while (rayCast != null);
|
|
Vector2 m = p.Lerp(t, 0.5f) + Vector2.Up * 15f;
|
|
l = Player.instance.followers[0].GlobalPosition;
|
|
for (float a = 0f; a <= b; a += Main.deltaTime)
|
|
{
|
|
float t2 = Mathf.Min(a / b, 1f);
|
|
Player.instance.followers[0].GlobalPosition = Common.Beizier(l, m, t + Vector2.Up, t2);
|
|
Player.instance.GlobalPosition = Common.Beizier(p, m, t, t2);
|
|
yield return null;
|
|
}
|
|
Player.instance.ResetFollowStep();
|
|
}
|
|
|
|
public void DoPush()
|
|
{
|
|
Main.inEvent = Coroutine.Start(Push());
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (Main.inEvent != null)
|
|
{
|
|
return;
|
|
}
|
|
if (playerHurt == null)
|
|
{
|
|
playerHurt = Player.instance.ToSignal(Player.instance, Player.SignalName.WasHurt);
|
|
}
|
|
if (playerHurt.GetResult() != null)
|
|
{
|
|
if (Mathf.Abs(Player.instance.GlobalPosition.X - base.GlobalPosition.X) < 40f)
|
|
{
|
|
DoPush();
|
|
}
|
|
playerHurt = null;
|
|
return;
|
|
}
|
|
base.GlobalPosition = base.GlobalPosition.Lerp(new Vector2(Mathf.Clamp(base.GlobalPosition.X - Main.deltaTime * 7f, -9999f, CameraController.instance.GlobalPosition.X + 100f), base.GlobalPosition.Y), Main.deltaTime * 0.1f);
|
|
if (cd > 0f)
|
|
{
|
|
cd -= Main.deltaTime;
|
|
}
|
|
for (int i = 0; i < bullets.Length; i++)
|
|
{
|
|
if (bullets[i].Visible)
|
|
{
|
|
bullets[i].Modulate = bullets[i].Modulate.Lerp(Main.colorWhite, 0.1f);
|
|
bullets[i].GlobalPosition += Vector2.Left * 3.25f * Main.deltaTime;
|
|
if (bullets[i].GlobalPosition.X < CameraController.instance.GlobalPosition.X - 200f)
|
|
{
|
|
bullets[i].Visible = false;
|
|
}
|
|
}
|
|
else if (cd <= 0f)
|
|
{
|
|
Audio.PlaySound("snd_arrow.wav");
|
|
cd = Main.RandomRange(30, 100);
|
|
bullets[i].GlobalPosition = base.GlobalPosition + new Vector2(40f, Main.RandomRange(-50, 50));
|
|
bullets[i].Visible = true;
|
|
bullets[i].Modulate = Main.colorClear;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|