Zombie preview before game
This commit is contained in:
parent
ed747bea9e
commit
84396d8393
4 changed files with 67 additions and 4 deletions
56
scripts/gui/ZombieLevelPreviewer.cs
Normal file
56
scripts/gui/ZombieLevelPreviewer.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
1
scripts/gui/ZombieLevelPreviewer.cs.uid
Normal file
1
scripts/gui/ZombieLevelPreviewer.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bc3s06ejbotma
|
||||
Loading…
Add table
Add a link
Reference in a new issue