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

129 lines
3.0 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/Bullets/WaveBullets.cs")]
public partial class WaveBullets : Node2D
{
[Export(PropertyHint.None, "")]
private Node2D[] bullets;
[Export(PropertyHint.None, "")]
private NodePath holder;
[Export(PropertyHint.None, "")]
public float delay = 30f;
[Export(PropertyHint.None, "")]
public float variance = 5f;
[Export(PropertyHint.None, "")]
public float maxAngle = 35f;
[Export(PropertyHint.None, "")]
public float angleVariance;
[Export(PropertyHint.None, "")]
public float speed = 1f;
[Export(PropertyHint.None, "")]
public int skip = 2;
[Export(PropertyHint.None, "")]
public int skipVariance = 1;
[Export(PropertyHint.None, "")]
private int bulletsPerWave = 10;
[Export(PropertyHint.None, "")]
private Vector2 direction;
[Export(PropertyHint.None, "")]
private bool usePlayerDirection = true;
[Export(PropertyHint.None, "")]
private bool initialDelay;
[Export(PropertyHint.None, "")]
private AudioStream sound;
[Export(PropertyHint.None, "")]
private float soundVolume = 1f;
private List<Node2D> bulletObjs = new List<Node2D>();
private Node2D actualHolder;
private float cd;
private float angle;
public override void _EnterTree()
{
if (initialDelay)
{
cd = delay;
}
angle = (float)Math.PI * 2f / maxAngle;
if (holder == null || holder.IsEmpty || holder.ToString().Length < 1)
{
actualHolder = this;
}
else
{
actualHolder = GetNode<Node2D>(holder);
}
}
public override void _Process(double delta)
{
if (cd > 0f)
{
cd -= Main.deltaTime;
return;
}
cd = delay + Main.RandomRange(0f - variance, variance);
if (usePlayerDirection)
{
direction = base.GlobalPosition.DirectionTo(DWMenu.instance.soulBody.GlobalPosition);
}
int num = Main.RandomRange(0, skipVariance);
int num2 = Main.RandomRange(0, bulletsPerWave);
float num3 = Main.RandomRange(0f - angleVariance, angleVariance);
if (sound != null)
{
Audio.PlaySound(sound, soundVolume);
}
int i = 0;
int num4 = skip + num;
for (; i < bulletsPerWave + skip; i++)
{
if (num4 > 0 && i >= num2)
{
num4--;
continue;
}
int num5 = Main.RandomRange(0, bullets.Length - 1);
float weight = (float)i / (float)bulletsPerWave;
Vector2 vector = direction.Rotated(Mathf.DegToRad(Mathf.Lerp(0f, maxAngle, weight) - maxAngle / 2f + num3));
bulletObjs.Add((Node2D)bullets[num5].Duplicate());
Node2D node2D = actualHolder;
List<Node2D> list = bulletObjs;
node2D.AddChild(list[list.Count - 1], forceReadableName: false, InternalMode.Disabled);
List<Node2D> list2 = bulletObjs;
list2[list2.Count - 1].GlobalPosition = base.GlobalPosition;
List<Node2D> list3 = bulletObjs;
Main.SetActive(list3[list3.Count - 1], state: true);
List<Node2D> list4 = bulletObjs;
if (list4[list4.Count - 1] is MoveAhead moveAhead)
{
moveAhead.speed = vector * speed;
}
}
}
}