130 lines
2.8 KiB
C#
130 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/BearingCart.cs")]
|
|
public partial class BearingCart : Node2D
|
|
{
|
|
[Export(PropertyHint.None, "")]
|
|
private Node2D cartBase;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Node2D entityPos;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Node2D cartPos;
|
|
|
|
private Entity entity;
|
|
|
|
private int amt;
|
|
|
|
private int state;
|
|
|
|
private float delay;
|
|
|
|
private float cartSpeed;
|
|
|
|
private bool allDone;
|
|
|
|
private const float fallTime = 35f;
|
|
|
|
private Coroutine routine;
|
|
|
|
private List<Node2D> carts = new List<Node2D>();
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
entity = BattleDR.current.enemies[0].entity;
|
|
entity.Modulate = Main.colorWhite;
|
|
entity.GlobalPosition = entityPos.GlobalPosition;
|
|
float progress = entity.battleData.GetProgress();
|
|
amt = ((progress > 0.5f) ? 5 : 3);
|
|
delay = ((progress > 0.5f) ? 20 : 40);
|
|
cartSpeed = ((progress > 0.5f) ? 2.75f : 2f);
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
BattleDR.current.activeBoard.timer = 999999f;
|
|
for (int num = carts.Count - 1; num >= 0; num--)
|
|
{
|
|
carts[num].GlobalPosition += Vector2.Left * Main.deltaTime * cartSpeed;
|
|
if (carts[num].Position.X < -200f)
|
|
{
|
|
carts[num].QueueFree();
|
|
carts.RemoveAt(num);
|
|
}
|
|
}
|
|
if (!GodotObject.IsInstanceValid(BattleDR.current.activeBoard))
|
|
{
|
|
QueueFree();
|
|
}
|
|
else
|
|
{
|
|
if (routine != null && !routine.done)
|
|
{
|
|
return;
|
|
}
|
|
if (allDone)
|
|
{
|
|
if (carts.Count == 0)
|
|
{
|
|
BattleDR.current.activeBoard.timer = 0f;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
routine = Coroutine.Start(CartPunch());
|
|
}
|
|
}
|
|
}
|
|
|
|
private IEnumerator CartPunch()
|
|
{
|
|
Vector2 cs = cartPos.GlobalPosition + Vector2.Up * 300f;
|
|
Node2D cart = BattleDR.NewBullet(in cartBase, cs, this);
|
|
int idx = Main.RandomRange(2, 4);
|
|
IBullet child = cart.GetChild<IBullet>(idx);
|
|
child.node.Modulate = Main.colorYellow;
|
|
child.type = IBullet.Type.Yellow;
|
|
Audio.PlaySound("snd_arrow.wav");
|
|
float a = 0f;
|
|
for (float b = 35f; a <= b; a += Main.deltaTime)
|
|
{
|
|
cart.GlobalPosition = cs.Lerp(cartPos.GlobalPosition, a / b);
|
|
yield return null;
|
|
}
|
|
cart.GlobalPosition = cartPos.GlobalPosition;
|
|
Audio.PlaySound("snd_bump_ch1.wav");
|
|
for (float b = 0f; b < 5f; b += Main.deltaTime)
|
|
{
|
|
yield return null;
|
|
}
|
|
Audio.PlaySound("snd_noise.wav").Bus = "Reverb";
|
|
entity.anim.Play("Punch0");
|
|
entity.Shake(delay);
|
|
while (entity.shake > 0f)
|
|
{
|
|
yield return null;
|
|
}
|
|
entity.anim.Play("Punch1");
|
|
Audio.PlaySound("snd_impact_ch1.wav");
|
|
CameraController.Shake();
|
|
carts.Add(cart);
|
|
for (float b = 0f; b < 20f; b += Main.deltaTime)
|
|
{
|
|
yield return null;
|
|
}
|
|
entity.anim.Play("Idle");
|
|
amt--;
|
|
if (amt <= 0)
|
|
{
|
|
allDone = true;
|
|
}
|
|
}
|
|
|
|
}
|