particles/MainMenu/MenuBackground.cs
2022-01-25 12:02:24 -05:00

52 lines
1.6 KiB
C#

using Godot;
using System;
public class MenuBackground : Node2D
{
private Node2D _particleNodes;
public override void _Ready()
{
//_particleNodes = GetNode<Node2D>("ParticlesNodes");
//var particleScene = GD.Load<PackedScene>("res://ParticleSimulation/ParticleNode.tscn");
//var particleNode = particleScene.Instance<ParticleNode>();
//_particleNodes.AddChild(particleNode);
}
public void SetParticleCount(int nParticles)
{
int currentCount = _particleNodes.GetChildCount();
if (currentCount < nParticles)
{
int addCount = nParticles - currentCount;
for (int i = 0; i < addCount; i++)
{
CreateParticle();
}
}
// TODO pick random particles to delete
}
private void CreateParticle()
{
var particlePackedScene = GD.Load<PackedScene>("res://ParticleSimulation/ParticleNode.tscn");
var particleNode = particlePackedScene.Instance<ParticleNode>();
_particleNodes.AddChild(particleNode);
var screenSize = GetViewportRect().Size;
var position = new Vector2(
(float) GD.RandRange(0, screenSize.x),
(float) GD.RandRange(0, screenSize.y));
particleNode.Position = position;
}
public override void _Process(float delta)
{
//var particleNodesArray = _particleNodes.GetChildren();
//foreach (ParticleNode particle in particleNodesArray)
//{
// particle.Position += new Vector2(0.1f, 0f);
//}
}
}