2025-05-13 19:22:01 +08:00

101 lines
2.4 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/Bullets/StapleBite.cs")]
public partial class StapleBite : Node2D
{
[Export(PropertyHint.None, "")]
private Blank[] mouth;
[Export(PropertyHint.None, "")]
private Node2D staple;
private int state;
private float cd;
private float y;
private float rot;
private Vector2 gpos;
private const float mouthPos = 32f;
public override void _Process(double delta)
{
float weight = Main.deltaTime * 0.1f;
switch (state)
{
case 0:
{
base.Rotation = Mathf.LerpAngle(base.Rotation, 0f, weight);
base.GlobalPosition = new Vector2(Mathf.Lerp(base.GlobalPosition.X, BattleDR.current.soul.GlobalPosition.X, weight), base.GlobalPosition.Y);
for (int k = 0; k < 2; k++)
{
mouth[k].Position = new Vector2(0f, Mathf.Lerp(mouth[k].Position.Y, (float)((k != 0) ? 1 : (-1)) * (32f + Mathf.Abs(Common.SinOverTime(0.5f) * 6f)), weight));
}
if (cd < 45f)
{
cd += Main.deltaTime;
break;
}
rot = Mathf.DegToRad(Main.RandomRange(-5, 5));
cd = 0f;
state = 1;
y = ToLocal(BattleDR.current.soul.GlobalPosition).Y;
gpos = BattleDR.current.soul.GlobalPosition;
Audio.PlaySound("snd_spearappear_ch1.wav");
for (int l = 0; l < 2; l++)
{
mouth[l].GetChild(0).GetChild<CollisionPolygon2D>(0).SetDeferred("disabled", false);
mouth[l].grazed = false;
}
break;
}
case 1:
{
base.Rotation = Mathf.LerpAngle(base.Rotation, rot, weight);
for (int m = 0; m < 2; m++)
{
mouth[m].Position = new Vector2(0f, Mathf.Lerp(mouth[m].Position.Y, (float)((m != 0) ? 1 : (-1)) * 52f, weight));
}
if (cd < 30f)
{
cd += Main.deltaTime;
break;
}
cd = 0f;
state = 2;
Audio.PlaySound("snd_spearrise_ch1.wav");
break;
}
case 2:
{
for (int i = 0; i < 2; i++)
{
mouth[i].Position = new Vector2(0f, Mathf.Lerp(mouth[i].Position.Y, (float)(((i != 0) ? 1 : (-1)) * 3) + y, Main.deltaTime * 0.15f));
}
if (cd < 25f)
{
cd += Main.deltaTime;
break;
}
Audio.PlaySound("snd_switchpull_n.wav");
BattleDR.NewBullet(in staple, gpos, GetParent<Node2D>()).Rotation = base.Rotation;
cd = 0f;
state = 0;
for (int j = 0; j < 2; j++)
{
mouth[j].GetChild(0).GetChild<CollisionPolygon2D>(0).SetDeferred("disabled", true);
}
break;
}
}
}
}