Debug zombie spawner
This commit is contained in:
parent
116ebff0c2
commit
0fff33d196
69 changed files with 564 additions and 100 deletions
|
|
@ -8,7 +8,7 @@ namespace Newlon.Components.Level;
|
|||
// Is not pool in traditional sense, but named like that to prevent repetition
|
||||
//
|
||||
|
||||
public partial class PoolContainer : Node
|
||||
public partial class PoolContainer : Node2D
|
||||
{
|
||||
[Export]
|
||||
public Node2D Zombies { get; private set; }
|
||||
|
|
|
|||
63
scripts/components/level/zombe_spawners/ZombieSequencer.cs
Normal file
63
scripts/components/level/zombe_spawners/ZombieSequencer.cs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using Newlon;
|
||||
using Newlon.Components.Level;
|
||||
using Newlon.Components.Zombies;
|
||||
|
||||
public partial class ZombieSequencer : Node2D
|
||||
{
|
||||
public static ZombieSequencer Instance { get; private set; }
|
||||
private Queue<string> queue = [];
|
||||
private RandomNumberGenerator rng = new();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
rng.Randomize();
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
|
||||
private void FormSquad()
|
||||
{
|
||||
if (queue.Count == 0) return;
|
||||
int count = rng.RandiRange(1, queue.Count > 5 ? 5 : queue.Count);
|
||||
|
||||
if (count == 5)
|
||||
{
|
||||
Spawn(queue.Dequeue(), 1);
|
||||
Spawn(queue.Dequeue(), 2);
|
||||
Spawn(queue.Dequeue(), 3);
|
||||
Spawn(queue.Dequeue(), 4);
|
||||
Spawn(queue.Dequeue(), 5);
|
||||
}
|
||||
|
||||
List<int> list = [];
|
||||
while (list.Count < count)
|
||||
{
|
||||
int lane = rng.RandiRange(1, 5);
|
||||
if (list.Contains(lane) == true)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
list.Add(lane);
|
||||
}
|
||||
|
||||
foreach (int lane in list)
|
||||
{
|
||||
Spawn(queue.Dequeue(), lane);
|
||||
}
|
||||
}
|
||||
|
||||
private void Spawn(string id, int lane)
|
||||
{
|
||||
RuntimeZombieData zombie = GameRegistry.GetZombieByName(id).scene.Instantiate<RuntimeZombieData>();
|
||||
PoolContainer.Instance.Zombies.AddChild(zombie);
|
||||
|
||||
zombie.GlobalPosition = new Vector2(GlobalPosition.X, Utility.RightFieldBoundary.Y - (lane-1) * Utility.TileHeight);
|
||||
}
|
||||
|
||||
public void Add(string id)
|
||||
{
|
||||
queue.Enqueue(id);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://bsuw5lvnr3kol
|
||||
Loading…
Add table
Add a link
Reference in a new issue