Level runners

This commit is contained in:
Rendo 2025-07-16 20:17:58 +05:00
commit 5010c61309
11 changed files with 398 additions and 110 deletions

View file

@ -0,0 +1,51 @@
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();
}
}

View file

@ -0,0 +1 @@
uid://84gvlkflxdhk