Level runners
This commit is contained in:
parent
d52d4be5ff
commit
5010c61309
11 changed files with 398 additions and 110 deletions
37
scripts/level/LevelRunner.cs
Normal file
37
scripts/level/LevelRunner.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Components.Level;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class LevelRunner : Node
|
||||
{
|
||||
private AdventureLevelResource resource;
|
||||
[Export] private RowSpawner rowSpawner;
|
||||
[Export] private Timer waveTimer;
|
||||
private int waveIndex = -1;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
waveTimer.Timeout += SummonWave;
|
||||
}
|
||||
|
||||
public void SetLevelResource(AdventureLevelResource data)
|
||||
{
|
||||
resource = data;
|
||||
waveTimer.Stop();
|
||||
waveTimer.WaitTime = resource.initialWaveDelay;
|
||||
waveTimer.Start();
|
||||
|
||||
}
|
||||
|
||||
private void SummonWave()
|
||||
{
|
||||
waveIndex += 1;
|
||||
rowSpawner.Add(resource.waves[waveIndex].zombiesOrdered);
|
||||
|
||||
if (waveIndex == resource.waves.Count - 1) return;
|
||||
|
||||
waveTimer.WaitTime = resource.waves[waveIndex].customWaveDelay > 0 ? resource.waves[waveIndex].customWaveDelay : resource.standardWaveDelay;
|
||||
waveTimer.Start();
|
||||
}
|
||||
}
|
||||
1
scripts/level/LevelRunner.cs.uid
Normal file
1
scripts/level/LevelRunner.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://puqxp2xeg1r2
|
||||
|
|
@ -18,17 +18,25 @@ public partial class RuntimeLevelData : Node
|
|||
public float SunCount { get; private set; } = 0;
|
||||
[Export]
|
||||
public AdventureLevelResource levelResource;
|
||||
public event Action<LevelStates> OnLevelStateChanged;
|
||||
[Export]
|
||||
private LevelRunner levelRunner;
|
||||
[Export]
|
||||
private AnimationPlayer player;
|
||||
[Signal]
|
||||
public delegate void OnLevelStateChangedEventHandler(LevelStates state);
|
||||
|
||||
public static RuntimeLevelData Instance { get; private set; }
|
||||
|
||||
private LevelStates _currentState = LevelStates.ChooseYourSeeds;
|
||||
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
GetTree().Paused = true;
|
||||
Engine.TimeScale = 1.0;
|
||||
SetLevelState(LevelStates.ChooseYourSeeds);
|
||||
}
|
||||
|
||||
#region Sun
|
||||
|
|
@ -52,8 +60,31 @@ public partial class RuntimeLevelData : Node
|
|||
|
||||
public void SetLevelState(LevelStates state)
|
||||
{
|
||||
OnLevelStateChanged(state);
|
||||
EmitSignal(SignalName.OnLevelStateChanged, (int)state);
|
||||
|
||||
_currentState = state;
|
||||
|
||||
switch (_currentState)
|
||||
{
|
||||
case LevelStates.ChooseYourSeeds:
|
||||
player.Play("CYS_Sequence");
|
||||
break;
|
||||
case LevelStates.Pregame:
|
||||
player.Play("PG_Sequence");
|
||||
break;
|
||||
case LevelStates.Game:
|
||||
GetTree().Paused = false;
|
||||
levelRunner.SetLevelResource(levelResource);
|
||||
break;
|
||||
case LevelStates.Win:
|
||||
break;
|
||||
case LevelStates.Loose:
|
||||
break;
|
||||
}
|
||||
}
|
||||
public LevelStates GetLevelState()
|
||||
{
|
||||
return _currentState;
|
||||
}
|
||||
|
||||
//private Array<PlantResource> _selectedPlants;
|
||||
|
|
|
|||
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