Zombie preview before game

This commit is contained in:
Rendo 2025-07-17 03:58:05 +05:00
commit 84396d8393
4 changed files with 67 additions and 4 deletions

View file

@ -0,0 +1,56 @@
using Godot;
using Newlon.Components.Zombies;
using System.Collections.Generic;
namespace Newlon.Components.Level;
public partial class ZombieLevelPreviewer : Node2D
{
public void OnLevelStateChanged(RuntimeLevelData.LevelStates state)
{
switch (state)
{
case RuntimeLevelData.LevelStates.ChooseYourSeeds:
SetupZombies();
break;
case RuntimeLevelData.LevelStates.Pregame:
break;
default:
QueueFree();
break;
}
}
public void SetupZombies()
{
var to_spawn = FindUnique();
foreach (var zombie in to_spawn)
{
var rng_x = (float)GD.RandRange(0.0, 2.0);
var rng_y = (float)GD.RandRange(1.0, 5.0);
var spawned = zombie.Scene.Instantiate<RuntimeZombieData>();
spawned.DisableBrain();
AddChild(spawned);
spawned.Position += new Vector2(rng_x*Utility.TileWidth, rng_y*Utility.TileHeight);
}
}
public List<ZombieResource> FindUnique()
{
List<ZombieResource> zombies = new();
foreach (var wave in RuntimeLevelData.Instance.levelResource.waves)
{
foreach (var spawn in wave.zombiesOrdered)
{
foreach (var zombie in spawn.zombies)
{
if (zombie == null || zombies.Contains(zombie)) continue;
zombies.Add(zombie);
}
}
}
return zombies;
}
}

View file

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