Level runners
This commit is contained in:
parent
d52d4be5ff
commit
5010c61309
11 changed files with 398 additions and 110 deletions
51
scripts/level/zombe_spawners/RowSpawner.cs
Normal file
51
scripts/level/zombe_spawners/RowSpawner.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
1
scripts/level/zombe_spawners/RowSpawner.cs.uid
Normal file
1
scripts/level/zombe_spawners/RowSpawner.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://84gvlkflxdhk
|
||||
Loading…
Add table
Add a link
Reference in a new issue