particles/Main.cs

38 lines
1.1 KiB
C#
Raw Normal View History

2021-12-26 14:58:58 -05:00
using Godot;
2022-01-17 23:52:42 -05:00
using System;
2022-01-25 12:33:18 -05:00
using Particles.ParticleSimulation;
2021-12-26 14:58:58 -05:00
2022-01-17 23:52:42 -05:00
public class Main : Node
2021-12-26 14:58:58 -05:00
{
2021-12-27 14:58:33 -05:00
2022-01-25 12:33:18 -05:00
public int Seed;
private int _nParticles;
public void StartSimulation(int nParticles)
2021-12-27 16:10:07 -05:00
{
2022-01-25 12:33:18 -05:00
_nParticles = nParticles;
2022-01-18 12:01:37 -05:00
var particleSimulationPackedScene = GD.Load<PackedScene>("res://ParticleSimulation/ParticleSimulationScene.tscn");
2022-01-17 23:52:42 -05:00
var particleSimulationScene = particleSimulationPackedScene.Instance<ParticleSimulationScene>();
2022-01-25 12:33:18 -05:00
particleSimulationScene.Name = Seed.ToString();
2022-01-17 23:52:42 -05:00
AddChild(particleSimulationScene);
2022-01-25 12:33:18 -05:00
particleSimulationScene.Initialize(nParticles);
2022-01-17 23:52:42 -05:00
GetNode<Control>("MainMenu").Hide();
2021-12-26 21:16:28 -05:00
}
2022-01-25 12:02:24 -05:00
public void ExitToMenu()
{
2022-01-25 12:33:18 -05:00
GetNode(Seed.ToString()).QueueFree();
2022-01-25 12:02:24 -05:00
GetNode<Control>("MainMenu").Show();
2022-01-25 12:33:18 -05:00
GetNode<MainMenu>("MainMenu").RefreshSeedText();
}
public void RestartSimulation()
{
GetNode<ParticleSimulationScene>(Seed.ToString()).Hide();
GetNode(Seed.ToString()).QueueFree();
Seed = (int) GD.Randi();
StartSimulation(_nParticles);
2022-01-25 12:02:24 -05:00
}
2022-01-17 23:52:42 -05:00
}