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/PenniltonSimple.cs")]
public partial class PenniltonSimple : Node2D
{
public partial class Coins
{
public Node2D obj;
public bool bounce;
public Vector2 bounceS;
public Vector2 bounceM;
public Vector2 bounceE;
public float bounceTime;
}
[Export(PropertyHint.None, "")]
private Node2D[] coins;
[Export(PropertyHint.None, "")]
private AudioStream sound;
[Export(PropertyHint.None, "")]
private float delay = 50f;
[Export(PropertyHint.None, "")]
private float variance = 5f;
[Export(PropertyHint.None, "")]
private float spawnX = 200f;
[Export(PropertyHint.None, "")]
private float speed = 1f;
[Export(PropertyHint.None, "")]
private float bounceTime = 80f;
[Export(PropertyHint.None, "")]
private float bounceDistance = 30f;
[Export(PropertyHint.None, "")]
private bool weak;
private float limit;
private float cd;
private List<Coins> objs = new List<Coins>();
public override void _EnterTree()
{
limit = 0f - BattleDR.current.activeBoard.boardSize.X / 2f + 4f;
cd = delay / 2f;
if (weak)
{
base.RotationDegrees = -90f;
}
}
public static void PennyCoinLogic(Node2D parent, in List<Coins> objs, AudioStream sound = null, float bounceTime = 80f, float limit = -1f, float speed = 1f, float bounceDistance = 30f)
{
if (sound == null)
{
sound = GD.Load<AudioStream>("res://Audio/Sounds/snd_feisty_mooch_coin_grab.wav");
}
if (limit == -1f)
{
limit = 0f - BattleDR.current.activeBoard.boardSize.X / 2f + 4f;
}
for (int num = objs.Count - 1; num >= 0; num--)
{
if (!GodotObject.IsInstanceValid(objs[num].obj))
{
objs.RemoveAt(num);
}
else if (objs[num].bounce)
{
float num2 = objs[num].bounceTime / bounceTime;
if (num2 >= 1f)
{
objs[num].obj.QueueFree();
objs.RemoveAt(num);
}
else
{
objs[num].obj.Position = Common.Beizier(objs[num].bounceS, objs[num].bounceM, objs[num].bounceE, num2);
if (num2 >= 0.8f)
{
objs[num].obj.Modulate = objs[num].obj.Modulate.Lerp(Main.colorClear, 0.2f * Main.deltaTime);
}
objs[num].bounceTime += Main.deltaTime;
}
}
else if (objs[num].obj.Position.X < limit)
{
if (sound != null)
{
Audio.PlaySound(sound);
}
objs[num].bounce = true;
objs[num].bounceS = objs[num].obj.Position;
objs[num].bounceM = parent.ToLocal(BattleDR.current.soul.GlobalPosition) + Vector2.Right * BattleDR.current.activeBoard.boardSize.X / 2f;
if (BattleDR.current.soul.GlobalPosition.Y > objs[num].obj.GlobalPosition.Y)
{
objs[num].bounceE = new Vector2(limit, objs[num].obj.Position.Y + bounceDistance);
}
else
{
objs[num].bounceE = new Vector2(limit, objs[num].obj.Position.Y - bounceDistance);
}
}
else
{
objs[num].obj.Position += Vector2.Left * Main.deltaTime * speed;
}
}
}
public override void _Process(double delta)
{
PennyCoinLogic(this, in objs, sound, bounceTime, limit, speed, bounceDistance);
if (cd > 0f)
{
cd -= Main.deltaTime;
return;
}
cd = delay + Main.RandomRange(0f - variance, variance);
objs.Add(new Coins
{
obj = BattleDR.NewBullet(in coins[Main.RandomRange(0, coins.Length - 1)], new Vector2(spawnX, Main.RandomRange(0f - BattleDR.current.activeBoard.boardSize.Y, BattleDR.current.activeBoard.boardSize.Y) * 0.4f), this, local: true)
});
if (weak)
{
List<Coins> list = objs;
list[list.Count - 1].obj.RotationDegrees = -90f;
}
if (sound != null)
{
Audio.PlaySound(sound);
}
}
}