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

152 lines
3.6 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/Bullets/WrenchSpin.cs")]
public partial class WrenchSpin : Node2D
{
[Export(PropertyHint.None, "")]
private Sprite2D nut;
[Export(PropertyHint.None, "")]
private Sprite2D wrench;
[Export(PropertyHint.None, "")]
private Node2D bullet;
private float cd;
private float nextTarget;
private float wait;
private int state;
private Entity entity;
private Vector2 mid;
private Vector2 target = new Vector2(0f, -50f);
private bool flip;
private bool stop;
private const float startTime = 45f;
private const float speed = 2f;
private const float angle = 60f;
private List<Node> screws = new List<Node>();
public override void _EnterTree()
{
entity = BattleDR.current.activeBoard.caller.entity;
entity.Visible = false;
wrench.GlobalPosition = entity.GlobalPosition;
target += nut.GlobalPosition;
mid = wrench.GlobalPosition.Lerp(nut.GlobalPosition, 0.5f) + Vector2.Up * 100f;
Audio.PlaySound("snd_jump_ch1.wav");
}
public override void _ExitTree()
{
entity.Visible = true;
for (int i = 0; i < screws.Count; i++)
{
screws[i].QueueFree();
}
BattleDR.current.soul.TopLevel = true;
}
public override void _Process(double delta)
{
if (state == 0)
{
if (cd <= 45f)
{
float num = Mathf.Min(cd / 45f, 1f);
cd += Main.deltaTime;
wrench.RotationDegrees = Mathf.Lerp(0f, -180f, num);
wrench.GlobalPosition = Common.Beizier(entity.GlobalPosition, mid, target, num);
}
else
{
state = 1;
cd = 30f;
CameraController.Shake(10f);
Audio.PlaySound("snd_screenshake.wav");
wrench.Reparent(nut);
}
return;
}
if (state == 1)
{
if (cd > 0f)
{
cd -= Main.deltaTime;
return;
}
state = 2;
cd = 0f;
if (Mathf.Abs(BattleDR.current.soul.GlobalPosition.X - nut.GlobalPosition.X) <= 1f)
{
flip = Main.RandomRange(0, 100) > 50;
}
else
{
flip = BattleDR.current.soul.GlobalPosition.X < nut.GlobalPosition.X;
}
GetTarget();
return;
}
if (wait > 0f)
{
wait -= Main.deltaTime;
return;
}
if (cd < 60f)
{
cd += Main.deltaTime;
}
nut.RotationDegrees += Main.deltaTime * Mathf.Min(1f, cd / 60f) * (float)((!flip) ? 1 : (-1)) * 2f;
DWMenu.instance.bulletBoardPivot.RotationDegrees = (0f - nut.RotationDegrees) / 2f;
if ((!flip || !(nut.RotationDegrees <= nextTarget)) && (flip || !(nut.RotationDegrees >= nextTarget)) && !stop)
{
return;
}
if (!stop && Main.RandomRange(0, 100) >= 50)
{
stop = true;
GetTarget();
return;
}
Audio.PlaySound("snd_screenshake.wav");
stop = false;
CameraController.Shake(15f);
wait = 30f;
cd = 0f;
GetTarget();
for (int i = 0; i < 3; i++)
{
MoveAhead moveAhead = (MoveAhead)BattleDR.NewBullet(in bullet, Vector2.Zero, BattleDR.current);
moveAhead.ZIndex = 4096;
moveAhead.Scale *= 0.8f;
moveAhead.RotationDegrees = Main.RandomRange(0, 360);
float x = ((i != 0) ? ((!(wrench.GlobalPosition < nut.GlobalPosition)) ? Main.RandomRange((0f - BattleDR.current.activeBoard.boardSize.X) / 2.1f, 0f) : Main.RandomRange(0f, BattleDR.current.activeBoard.boardSize.X / 2.1f)) : Main.RandomRange((0f - BattleDR.current.activeBoard.boardSize.X) / 2.1f, BattleDR.current.activeBoard.boardSize.X / 2.1f));
moveAhead.GlobalPosition = base.GlobalPosition + new Vector2(x, -100 - 15 * i);
moveAhead.speed *= Main.RandomRange(0.9f, 1.1f);
screws.Add(moveAhead);
}
}
private void GetTarget()
{
nextTarget += (float)((!flip) ? 1 : (-1)) * 60f;
}
}