Survival mode ready

This commit is contained in:
Rendo 2025-06-26 20:18:19 +05:00
commit 7614b12076
50 changed files with 586 additions and 81 deletions

View file

@ -7,6 +7,9 @@ public partial class Previewport : SubViewport
{
private RuntimePlantData current_display;
[Export] private Label title;
[Export] private Label description;
public override void _Ready()
{
GetParent().GetViewport().GuiFocusChanged += OnFocusChanged;
@ -28,6 +31,8 @@ public partial class Previewport : SubViewport
current_display.QueueFree();
}
current_display = resource.Scene.Instantiate<RuntimePlantData>();
title.Text = resource.display_name;
description.Text = resource.display_description;
AddChild(current_display);
current_display.DisableBrain();
}

View file

@ -0,0 +1,12 @@
using Godot;
using Newlon;
public partial class LeftBoundaryMarker : Marker2D
{
public override void _Ready()
{
Utility.LeftFieldBoundary = (Vector2I)GlobalPosition;
QueueFree();
}
}

View file

@ -0,0 +1 @@
uid://d2dq6f0bk7pfx

View file

@ -0,0 +1,12 @@
using Godot;
using Newlon;
public partial class RightBoundaryMarker : Marker2D
{
public override void _Ready()
{
Utility.RightFieldBoundary = (Vector2I)GlobalPosition;
QueueFree();
}
}

View file

@ -0,0 +1 @@
uid://bymylx25skfot

View 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;
}
}

View file

@ -0,0 +1 @@
uid://nkb6i7lrkl8y

View file

@ -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();
}
}

View file

@ -8,7 +8,7 @@ public partial class PlantEyesightLimiter : CollisionShape2D
{
if (Shape is SegmentShape2D segment)
{
segment.B = new Vector2(Utility.RightFieldBoundary.X-GlobalPosition.X, 0);
segment.B = new Vector2(Utility.RightFieldBoundary.X - GlobalPosition.X, 0);
}
}
}

View file

@ -13,7 +13,7 @@ public partial class SunflowerBehaviour : Node
public void Timeout()
{
_tree.Set("parameters/conditions/produce",true);
_tree.Set("parameters/conditions/produce", true);
}
}

View file

@ -8,7 +8,7 @@ public partial class EatBox : Area2D
{
// Rewrite this class completely when field system will be introduced.
[Export] private FloatModifiers _damage;
[Export] public FloatModifiers _damage;
private RuntimePlantData plant;
public bool isEating = false;

View file

@ -6,12 +6,15 @@ public partial class ZombieMover : Node
{
[Export]
private FloatModifiers _speed;
[Export]
private float _speedControlMult;
private Node2D _zombie;
public override void _Ready()
{
_zombie = GetParent<Node2D>();
_speed = (FloatModifiers)_speed.Duplicate();
_speed.ChangePercentage((float)GD.RandRange(-0.05,0.05));
}
public override void _PhysicsProcess(double delta)
@ -20,7 +23,8 @@ public partial class ZombieMover : Node
* (float)delta
* Utility.TileWidth
* GetParent<RuntimeZombieData>().LocalTimescale
* _speed.GetValue();
* _speed.GetValue()
* _speedControlMult;
}
public void SetSpeedFlat(float speed)

View file

@ -13,5 +13,6 @@ public partial class HoboBehaviour : Node
canDestroyed = true;
((AnimationNodeStateMachinePlayback)_animationTree.Get("parameters/playback")).Travel("hobo_zombie_can_destroy");
_animationTree.Set("parameters/eat_Tree/blend/blend_amount", 1.0);
_eatBox._damage.SetMult(3.0f);
}
}