Initial field spawns
This commit is contained in:
parent
fdff25d451
commit
12b7435d19
28 changed files with 197 additions and 98 deletions
59
scripts/level/InitialPackedSceneSpawner.cs
Normal file
59
scripts/level/InitialPackedSceneSpawner.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
using Godot;
|
||||
using Newlon.Components;
|
||||
using Newlon.Components.Level;
|
||||
using Newlon.Components.Plants;
|
||||
using Newlon.Components.Zombies;
|
||||
|
||||
public partial class InitialPackedSceneSpawner : Node
|
||||
{
|
||||
public void OnLevelStateChanged(RuntimeLevelData.LevelStates state)
|
||||
{
|
||||
if (state == RuntimeLevelData.LevelStates.ChooseYourSeeds)
|
||||
{
|
||||
for (int i = 0; i < RuntimeLevelData.LevelResource.initialScenes.Count; i++)
|
||||
{
|
||||
var packed = RuntimeLevelData.LevelResource.initialScenes[i];
|
||||
if (packed == null) continue;
|
||||
var scene = packed.Instantiate();
|
||||
|
||||
if (scene is Node2D node)
|
||||
{
|
||||
int x = i % 9;
|
||||
int y = i / 9;
|
||||
var position = FieldParams.LeftFieldBoundary + new Vector2((x + 0.5f) * FieldParams.TileWidth, (y + 0.5f) * FieldParams.TileHeight);
|
||||
|
||||
if (node is Entity entity)
|
||||
{
|
||||
var brainDisabler = new LevelStateBrainDisabler();
|
||||
entity.DisableBrain();
|
||||
entity.AddChild(brainDisabler);
|
||||
|
||||
if (entity is RuntimeZombieData)
|
||||
{
|
||||
PoolContainer.Instance.Structures.AddChild(node);
|
||||
node.GlobalPosition = position;
|
||||
}
|
||||
else if (entity is RuntimePlantData plant)
|
||||
{
|
||||
PoolContainer.Instance.Plants.AddChild(plant);
|
||||
node.GlobalPosition = position;
|
||||
PoolContainer.Instance.EntityField[GameRegistry.GetPlantByName(plant.internal_id).Layer].Add(plant.GlobalPosition, plant);
|
||||
}
|
||||
else
|
||||
{
|
||||
PoolContainer.Instance.Structures.AddChild(entity);
|
||||
node.GlobalPosition = position;
|
||||
PoolContainer.Instance.EntityField[1].Add(entity.GlobalPosition, entity);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PoolContainer.Instance.Structures.AddChild(node);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue