Survival mode ready
This commit is contained in:
parent
0fff33d196
commit
7614b12076
50 changed files with 586 additions and 81 deletions
12
scripts/components/level/LeftBoundaryMarker.cs
Normal file
12
scripts/components/level/LeftBoundaryMarker.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using Godot;
|
||||
using Newlon;
|
||||
|
||||
public partial class LeftBoundaryMarker : Marker2D
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
Utility.LeftFieldBoundary = (Vector2I)GlobalPosition;
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
}
|
||||
1
scripts/components/level/LeftBoundaryMarker.cs.uid
Normal file
1
scripts/components/level/LeftBoundaryMarker.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://d2dq6f0bk7pfx
|
||||
12
scripts/components/level/RightBoundaryMarker.cs
Normal file
12
scripts/components/level/RightBoundaryMarker.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using Godot;
|
||||
using Newlon;
|
||||
|
||||
public partial class RightBoundaryMarker : Marker2D
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
Utility.RightFieldBoundary = (Vector2I)GlobalPosition;
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
}
|
||||
1
scripts/components/level/RightBoundaryMarker.cs.uid
Normal file
1
scripts/components/level/RightBoundaryMarker.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bymylx25skfot
|
||||
170
scripts/components/level/zombe_spawners/SurvivalZombieSpawner.cs
Normal file
170
scripts/components/level/zombe_spawners/SurvivalZombieSpawner.cs
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
public partial class SurvivalZombieSpawner : Node
|
||||
{
|
||||
// Zombie pools
|
||||
// Points from pools go in that order: support -> tank -> horde -> bank
|
||||
// Horde pool is allowed to shrink during runtime
|
||||
[Export] private Array<string> supportPool;
|
||||
[Export] private Array<string> tankPool;
|
||||
[Export] private Array<string> hordePool;
|
||||
|
||||
private List<ZombieResource> cachedSupportPool;
|
||||
private List<ZombieResource> cachedTankPool;
|
||||
private List<ZombieResource> cachedHordePool;
|
||||
|
||||
private float minSupportPoints;
|
||||
private float minTankPoints;
|
||||
private float minHordePoints;
|
||||
|
||||
[Export] private float points = 0;
|
||||
[Export] private float huge_wave_points;
|
||||
[Export] private Curve velocity_curve;
|
||||
private float velocity = 0;
|
||||
[Export] private double time = 0.0;
|
||||
private float fin_a;
|
||||
private RandomNumberGenerator rng = new();
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
rng.Randomize();
|
||||
|
||||
cachedSupportPool = LoadFromRegistry(supportPool);
|
||||
cachedTankPool = LoadFromRegistry(tankPool);
|
||||
cachedHordePool = LoadFromRegistry(hordePool);
|
||||
|
||||
cachedTankPool.Sort((x, y) =>
|
||||
{
|
||||
return (int)(x.cost - y.cost);
|
||||
});
|
||||
cachedHordePool.Sort((x, y) =>
|
||||
{
|
||||
return (int)(x.cost - y.cost);
|
||||
});
|
||||
|
||||
minSupportPoints = cachedSupportPool[0].cost;
|
||||
minTankPoints = cachedTankPool[0].cost;
|
||||
minHordePoints = cachedHordePool[0].cost;
|
||||
|
||||
fin_a = (velocity_curve.Sample(velocity_curve.MaxDomain) - velocity_curve.Sample(velocity_curve.MaxDomain - 0.001f)) / 0.001f;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
points += velocity * (float)delta;
|
||||
|
||||
if (time > velocity_curve.MaxDomain)
|
||||
{
|
||||
velocity += fin_a * (float)delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity = velocity_curve.Sample((float)time);
|
||||
}
|
||||
time += delta;
|
||||
}
|
||||
|
||||
public void SummonWave()
|
||||
{
|
||||
bool big_wave = false;
|
||||
if ((int)time % 300 == 0)
|
||||
{
|
||||
points += velocity/velocity_curve.Sample((float)time)*huge_wave_points;
|
||||
big_wave = true;
|
||||
}
|
||||
|
||||
float support_points = points * 0.2f;
|
||||
float tank_points = points * 0.5f;
|
||||
float horde_points = points * 0.3f;
|
||||
points = 0;
|
||||
|
||||
List<ZombieResource> wave = [];
|
||||
var remaining = SummonTank(tank_points, wave);
|
||||
support_points += remaining * 0.8f;
|
||||
horde_points += remaining * 0.2f;
|
||||
horde_points += SummonSupport(support_points, wave);
|
||||
points += SummonHorde(horde_points, wave, big_wave);
|
||||
|
||||
wave.Sort((x, y) => { return rng.RandiRange(-1, 1); });
|
||||
|
||||
foreach (var zom in wave)
|
||||
{
|
||||
ZombieSequencer.Instance.Add(zom.internal_id);
|
||||
}
|
||||
|
||||
big_wave = false;
|
||||
}
|
||||
|
||||
private float SummonSupport(float given_points, List<ZombieResource> wave)
|
||||
{
|
||||
if (cachedSupportPool.Count == 0)
|
||||
{
|
||||
return given_points;
|
||||
}
|
||||
while (given_points >= minSupportPoints)
|
||||
{
|
||||
var chosen_zombie = cachedSupportPool[rng.RandiRange(0, cachedSupportPool.Count - 1)];
|
||||
if (given_points - chosen_zombie.cost >= 0)
|
||||
{
|
||||
wave.Add(chosen_zombie);
|
||||
given_points -= chosen_zombie.cost;
|
||||
}
|
||||
}
|
||||
return given_points;
|
||||
}
|
||||
private float SummonTank(float given_points, List<ZombieResource> wave)
|
||||
{
|
||||
if (cachedTankPool.Count == 0)
|
||||
{
|
||||
return given_points;
|
||||
}
|
||||
int zombieIndex = cachedTankPool.Count - 1;
|
||||
while (given_points >= minSupportPoints && zombieIndex > -1)
|
||||
{
|
||||
if (cachedTankPool[zombieIndex].cost > given_points)
|
||||
{
|
||||
zombieIndex--;
|
||||
continue;
|
||||
}
|
||||
var chosen_zombie = cachedTankPool[zombieIndex];
|
||||
wave.Add(chosen_zombie);
|
||||
given_points -= chosen_zombie.cost;
|
||||
}
|
||||
return given_points;
|
||||
}
|
||||
private float SummonHorde(float given_points, List<ZombieResource> wave, bool is_big)
|
||||
{
|
||||
if (cachedHordePool.Count == 0)
|
||||
{
|
||||
return given_points;
|
||||
}
|
||||
while (is_big == false && cachedHordePool.Count > 1 && cachedHordePool[1].cost * 15 <= given_points)
|
||||
{
|
||||
cachedHordePool.RemoveAt(0);
|
||||
minHordePoints = cachedHordePool[0].cost;
|
||||
}
|
||||
while (given_points >= minHordePoints)
|
||||
{
|
||||
var chosen_zombie = cachedHordePool[rng.RandiRange(0, cachedHordePool.Count - 1)];
|
||||
if (given_points - chosen_zombie.cost >= 0)
|
||||
{
|
||||
wave.Add(chosen_zombie);
|
||||
given_points -= chosen_zombie.cost;
|
||||
}
|
||||
}
|
||||
return given_points;
|
||||
}
|
||||
|
||||
private List<ZombieResource> LoadFromRegistry(Array<string> pool)
|
||||
{
|
||||
List<ZombieResource> list = [];
|
||||
foreach (var res in pool)
|
||||
{
|
||||
list.Add(GameRegistry.GetZombieByName(res));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://nkb6i7lrkl8y
|
||||
|
|
@ -9,11 +9,18 @@ public partial class ZombieSequencer : Node2D
|
|||
public static ZombieSequencer Instance { get; private set; }
|
||||
private Queue<string> queue = [];
|
||||
private RandomNumberGenerator rng = new();
|
||||
private bool turbo = false;
|
||||
|
||||
[Export] private Timer spawnTimer;
|
||||
[Export] private Timer waveTimer;
|
||||
|
||||
private double startSpawnTime;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
rng.Randomize();
|
||||
Instance = this;
|
||||
startSpawnTime = spawnTimer.WaitTime;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -44,7 +51,8 @@ public partial class ZombieSequencer : Node2D
|
|||
|
||||
foreach (int lane in list)
|
||||
{
|
||||
Spawn(queue.Dequeue(), lane);
|
||||
if (queue.Count > 0)
|
||||
Spawn(queue.Dequeue(), lane);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -53,11 +61,30 @@ public partial class ZombieSequencer : Node2D
|
|||
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);
|
||||
zombie.GlobalPosition = new Vector2(GlobalPosition.X, Utility.RightFieldBoundary.Y - (lane - 1) * Utility.TileHeight);
|
||||
}
|
||||
|
||||
public void Add(string id)
|
||||
{
|
||||
queue.Enqueue(id);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (turbo == false && queue.Count > waveTimer.WaitTime / startSpawnTime * 5.0)
|
||||
{
|
||||
spawnTimer.WaitTime = waveTimer.WaitTime / queue.Count;
|
||||
turbo = true;
|
||||
}
|
||||
else if(turbo && queue.Count == 0)
|
||||
{
|
||||
spawnTimer.WaitTime = startSpawnTime;
|
||||
turbo = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void DebugClearQueue()
|
||||
{
|
||||
queue.Clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue