Initial field spawns

This commit is contained in:
Rendo 2025-07-18 03:36:49 +05:00
commit 12b7435d19
28 changed files with 197 additions and 98 deletions

View file

@ -0,0 +1,19 @@
using Godot;
using Newlon.Components;
using Newlon.Components.Level;
[GlobalClass]
public partial class LevelStateBrainDisabler : Node
{
public override void _Ready()
{
RuntimeLevelData.Instance.OnLevelStateChanged += OnLevelStateChanged;
}
public void OnLevelStateChanged(RuntimeLevelData.LevelStates state)
{
if (state == RuntimeLevelData.LevelStates.Game)
{
GetParent<Entity>().EnableBrain();
}
}
}

View file

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

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

View file

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

View file

@ -24,7 +24,7 @@ public partial class PoolContainer : Node2D
public static PoolContainer Instance { get; private set; }
public Dictionary<Vector2, Entity>[] EntityField = { new(), new(), new() };
public override void _Ready()
public override void _EnterTree()
{
Instance = this;
}

View file

@ -9,6 +9,8 @@ namespace Newlon.Components.Plants;
public partial class RuntimePlantData : Entity
{
[Export]
public string internal_id;
public int Line { get; set; }
public PlantResource Resource;
private AudioStream eatenSound = ResourceLoader.Load<AudioStream>("res://assets/audio/sfx/gulp.mp3");