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

168 lines
3.7 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/Bullets/BearingPush.cs")]
public partial class BearingPush : Node2D
{
[Export(PropertyHint.None, "")]
private MoveAhead bullet;
[Export(PropertyHint.None, "")]
private Blank hitbox;
[Export(PropertyHint.None, "")]
private AnimationPlayer bite;
[Export(PropertyHint.None, "")]
private float pushSpd = 0.05f;
[Export(PropertyHint.None, "")]
private float bulletCD = 120f;
private Entity entity;
private bool weak;
private bool started;
private bool end;
private float cd;
private float pushing;
private float hitcd;
private float sporeCD;
private Vector2 start;
private Vector2 mid;
private Vector2 targetp;
private readonly Vector2 offset = new Vector2(20f, -40f);
private const float maxX = 120f;
private const float bulletAngle = 30f;
public override void _EnterTree()
{
entity = BattleDR.current.enemies[0].entity;
entity.Modulate = Main.colorWhite;
weak = entity.battleData.HPPercent() <= 0.5f || entity.battleData.spare >= 50;
if (weak)
{
pushSpd *= 1.1f;
bulletCD *= 0.75f;
hitbox.HP = Mathf.RoundToInt((float)hitbox.HP * 1.15f);
}
entity.Reparent(DWMenu.instance.bulletBoard);
cd = 30f;
Blank blank = hitbox;
blank.onShot = (Action<Node>)Delegate.Combine(blank.onShot, new Action<Node>(Shot));
start = entity.Position;
mid = start + Vector2.Right * 20f;
targetp = new Vector2(BattleDR.current.activeBoard.boardSize.X * 1.5f, BattleDR.current.activeBoard.boardSize.Y - 10f);
entity.anim.Play("Walk");
CallDeferred("reparent", DWMenu.instance);
}
public override void _Process(double delta)
{
if (!GodotObject.IsInstanceValid(BattleDR.current.activeBoard))
{
QueueFree();
return;
}
entity.Modulate = entity.Modulate.Lerp(Main.colorWhite, Main.deltaTime * 0.1f);
if (cd > 0f)
{
cd -= Main.deltaTime;
}
if (hitcd > 0f)
{
hitcd -= Main.deltaTime;
}
if (sporeCD > 0f)
{
sporeCD -= Main.deltaTime;
}
if (!started)
{
entity.Position = Common.Beizier(start, mid, targetp, 1f - cd / 30f);
if (cd <= 0f)
{
entity.Position = targetp;
Audio.PlaySound("snd_impact_ch1.wav");
entity.anim.Play("Push");
cd = bulletCD / 2f;
started = true;
}
return;
}
if (end)
{
entity.GlobalPosition = entity.GlobalPosition.Lerp(mid, Main.deltaTime * 0.1f);
return;
}
if (hitcd <= 0f && pushing > (0f - pushSpd) * 3f)
{
pushing -= pushSpd * Main.deltaTime * ((hitcd > 0f) ? 0.75f : 1f);
}
hitbox.GlobalPosition = entity.GlobalPosition;
BattleDR.current.activeBoard.timer = 100f;
if (DWMenu.instance.bulletBoard.Position.X > -120f && DWMenu.instance.bulletBoard.Position.X < 120f)
{
DWMenu.instance.bulletBoard.Position += Vector2.Right * pushing * Main.deltaTime;
}
if (cd <= 0f)
{
SpawnBullet();
}
}
public override void _ExitTree()
{
entity.Reparent(BattleDR.current);
}
private void SpawnBullet()
{
if (sporeCD <= 0f)
{
cd = bulletCD;
Node2D type = bullet;
MoveAhead obj = (MoveAhead)BattleDR.NewBullet(in type, entity.GlobalPosition + offset, this);
obj.speed = obj.speed.Rotated(Mathf.DegToRad(Main.RandomRange(-15f, 30f)));
obj.RotationDegrees = Main.RandomRange(0, 360);
sporeCD = 15f;
}
}
private void Shot(Node node)
{
entity.Modulate = Main.colorGlow;
if (hitcd <= 10f)
{
SpawnBullet();
}
hitcd = 20f;
if (((IBullet)node).HP <= 0)
{
end = true;
entity.anim.Play("Hurt");
bite.Play("Stop");
mid = entity.GlobalPosition + Vector2.Right * 40f;
entity.Modulate = Main.colorWhite;
entity.CallDeferred("reparent", BattleDR.current);
}
}
}