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

132 lines
2.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/Bullets/AxisSphere.cs")]
public partial class AxisSphere : Node2D
{
public partial class Sphere
{
public AxisSphereSphere obj;
public Area2D area;
public bool inside;
}
[Export(PropertyHint.None, "")]
private Node2D sphere;
private List<Sphere> spheres = new List<Sphere>();
private Entity entity;
private float cd;
private bool weak;
private bool done;
private Coroutine shoot;
private Rect2 rect;
private const float spd = 1.1f;
public override void _EnterTree()
{
rect = new Rect2(base.GlobalPosition, BattleDR.current.activeBoard.boardSize * 0.9f);
entity = BattleDR.current.enemies[0].entity;
weak = entity.battleData.HPPercent() <= 0.5f || entity.battleData.spare >= 50;
entity.Modulate = Main.colorWhite;
if (weak)
{
BattleDR.current.activeBoard.timer *= 1.35f;
}
}
public override void _Process(double delta)
{
if (done)
{
return;
}
Coroutine coroutine = shoot;
if (coroutine == null || coroutine.done)
{
if (cd > 0f)
{
cd -= Main.deltaTime;
}
else
{
shoot = Coroutine.Start(Shoot());
}
}
}
private IEnumerator Shoot()
{
Audio.PlaySound("snd_electric_talk.wav");
entity.anim.Play("Shoot1");
for (float a = 0f; a < 30f; a += Main.deltaTime)
{
yield return null;
}
Audio.PlaySound("snd_swing.wav");
entity.anim.Play("Shoot2");
for (float a = 0f; a < 7f; a += Main.deltaTime)
{
yield return null;
}
NewSphere(spheres.Count > 0);
for (float a = 0f; a < 20f; a += Main.deltaTime)
{
yield return null;
}
if (spheres.Count == ((!weak) ? 1 : 2))
{
done = true;
}
else
{
cd = 25f;
}
entity.anim.Play("Idle");
}
private void SphereHit(Node other)
{
Audio.PlaySound("snd_ceroba_shield_impact.wav", 1f, 0.9f);
spheres[0].obj.speed = -spheres[0].obj.GlobalPosition.DirectionTo(spheres[1].obj.GlobalPosition);
spheres[1].obj.speed = -spheres[1].obj.GlobalPosition.DirectionTo(spheres[0].obj.GlobalPosition);
}
private void NewSphere(bool blue = false)
{
AxisSphereSphere axisSphereSphere = (AxisSphereSphere)BattleDR.NewBullet(in this.sphere, entity.GlobalPosition + new Vector2(-10f, -35f), this);
Sphere sphere = new Sphere
{
obj = axisSphereSphere,
area = axisSphereSphere.GetChild<Area2D>(0)
};
sphere.area.BodyEntered += axisSphereSphere.WallHit;
axisSphereSphere.data = sphere;
if (spheres.Count == 0)
{
sphere.area.AreaEntered += SphereHit;
}
spheres.Add(sphere);
axisSphereSphere.speed = Vector2.Left.Rotated(Mathf.DegToRad(Main.RandomRange(-25, 25))) * 1.1f * ((!blue) ? 1.2f : 1f);
if (blue)
{
axisSphereSphere.Modulate = Main.colorCyan;
axisSphereSphere.type = IBullet.Type.Blue;
}
}
}