51 lines
1 KiB
C#
51 lines
1 KiB
C#
using Godot;
|
|
using System.Collections.Generic;
|
|
using Newlon.Components.Zombies;
|
|
using Godot.Collections;
|
|
|
|
namespace Newlon.Components.Level;
|
|
|
|
[GlobalClass]
|
|
public partial class RowSpawner : Node2D
|
|
{
|
|
private Queue<RowSpawn> queue = [];
|
|
[Export] private Timer delayTimer;
|
|
|
|
public override void _Ready()
|
|
{
|
|
delayTimer.Timeout += FormSquad;
|
|
}
|
|
|
|
private void FormSquad()
|
|
{
|
|
if (queue.Count == 0) return;
|
|
|
|
var row = queue.Dequeue();
|
|
|
|
for (int i = 0; i < row.zombies.Count; i++)
|
|
{
|
|
if (row.zombies[i] != null)
|
|
Spawn(row.zombies[i], i+1);
|
|
}
|
|
|
|
if (queue.Count == 0) delayTimer.Stop();
|
|
}
|
|
|
|
private void Spawn(ZombieResource resource, int lane)
|
|
{
|
|
RuntimeZombieData zombie = resource.Scene.Instantiate<RuntimeZombieData>();
|
|
PoolContainer.Instance.Zombies.AddChild(zombie);
|
|
|
|
zombie.GlobalPosition = new Vector2(GlobalPosition.X, Utility.LeftFieldBoundary.Y + lane * Utility.TileHeight);
|
|
}
|
|
|
|
public void Add(Array<RowSpawn> rowSpawns)
|
|
{
|
|
foreach (var spawn in rowSpawns)
|
|
{
|
|
queue.Enqueue(spawn);
|
|
}
|
|
|
|
delayTimer.Start();
|
|
}
|
|
}
|