using Godot; public class Main : Node2D { public override void _Ready() { GD.Randomize(); InitializeParticles(); } public override void _Process(float delta) { if (Input.IsActionJustPressed("quit")) GetTree().Quit(); if (Input.IsActionJustPressed("reset")) GetTree().ReloadCurrentScene(); } private void InitializeParticles() { var particleScene = GD.Load("res://Particle.tscn"); for (var i = 0; i < 50; i++) { var particle = particleScene.Instance(); GetNode("Particles").AddChild(particle); particle.Position = GetRandomParticlePosition(); particle.Hue = (float) GD.RandRange(0, 1); } } private Vector2 GetRandomParticlePosition() { const int padding = 32; var viewportRect = GetViewportRect(); var position = new Vector2((float) GD.RandRange(padding, viewportRect.Size.x - padding), (float) GD.RandRange(padding, viewportRect.Size.y - padding)); return position; } }