particles/MainMenu/MenuBackground.cs

52 lines
1.6 KiB
C#
Raw Normal View History

2022-01-18 12:01:37 -05:00
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++)
{
2022-01-25 12:02:24 -05:00
CreateParticle();
2022-01-18 12:01:37 -05:00
}
}
2022-01-25 12:02:24 -05:00
// TODO pick random particles to delete
2022-01-18 12:01:37 -05:00
}
2022-01-25 12:02:24 -05:00
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)
2022-01-18 12:01:37 -05:00
{
//var particleNodesArray = _particleNodes.GetChildren();
//foreach (ParticleNode particle in particleNodesArray)
//{
// particle.Position += new Vector2(0.1f, 0f);
//}
}
}