diff --git a/Main.cs b/Main.cs index 28f86c0..7f4c6f3 100644 --- a/Main.cs +++ b/Main.cs @@ -1,34 +1,35 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Godot; -using Particles; +using Particles.ParticleSimulation; +// ReSharper disable once CheckNamespace +// ReSharper disable once ClassNeverInstantiated.Global public class Main : Node2D { + private Node2D _particleNodes; private ParticleSimulation _particleSimulation; - private Node2D _particleNodes; + public float PhysicsInterpolationFraction; + public override void _Ready() { _particleNodes = GetNode("ParticlesNodes"); GD.Randomize(); + var randomSeed = GD.Randi(); + GD.Seed(randomSeed); + GD.Print("Last Seed: " + randomSeed); _particleSimulation = new ParticleSimulation { - ScreenSize = GetViewportRect().Size + SpaceSize = GetViewportRect().Size * 1.15f }; _particleSimulation.Initialize(); - foreach (var id in _particleSimulation.LastParticlesAdded) - { - CreateParticleNode(id); - } + foreach (var id in _particleSimulation.LastParticlesAdded) CreateParticleNode(id); } public override void _Process(float delta) { if (Input.IsActionJustPressed("quit")) GetTree().Quit(); if (Input.IsActionJustPressed("reset")) GetTree().ReloadCurrentScene(); + PhysicsInterpolationFraction = Engine.GetPhysicsInterpolationFraction(); } public override void _PhysicsProcess(float delta) @@ -39,17 +40,18 @@ public class Main : Node2D var particleNode = _particleNodes.GetNode(id.ToString()); particleNode.Free(); } - foreach (var id in _particleSimulation.LastParticlesAdded) - { - CreateParticleNode(id); - } + + foreach (var id in _particleSimulation.LastParticlesAdded) CreateParticleNode(id); var particleNodes = _particleNodes.GetChildren(); foreach (ParticleNode particleNode in particleNodes) { var simulationParticle = _particleSimulation.GetParticle(particleNode.SimulationId); - particleNode.Position = simulationParticle.Position; - particleNode.SetColor(simulationParticle.Type.Hue, simulationParticle.Health); + particleNode.LastSimulationPosition = particleNode.Position; + particleNode.CurrentSimulationPosition = simulationParticle.Position; + particleNode.SetColor(simulationParticle.Type.Hue, simulationParticle.Health, + Mathf.Clamp(simulationParticle.AverageSpeed / 1.5f, 1f, 1f)); + particleNode.ScreenWrappedLast = simulationParticle.ScreenWrappedLast; } } diff --git a/Main.tscn b/Main.tscn index 4017b61..820ba09 100644 --- a/Main.tscn +++ b/Main.tscn @@ -6,3 +6,8 @@ script = ExtResource( 1 ) [node name="ParticlesNodes" type="Node2D" parent="."] + +[node name="Camera2D" type="Camera2D" parent="."] +anchor_mode = 0 +current = true +zoom = Vector2( 1.15, 1.15 ) diff --git a/ParticleNode.cs b/ParticleNode.cs index 369ccf5..403d2d0 100644 --- a/ParticleNode.cs +++ b/ParticleNode.cs @@ -1,10 +1,15 @@ using Godot; +// ReSharper disable once CheckNamespace +// ReSharper disable once ClassNeverInstantiated.Global public class ParticleNode : Node2D { - private Sprite _spriteNode; private Label _labelNode; - + private Sprite _spriteNode; + public Vector2 CurrentSimulationPosition = new Vector2(); + + public Vector2 LastSimulationPosition; + public bool ScreenWrappedLast = false; public int SimulationId; public override void _Ready() @@ -13,13 +18,21 @@ public class ParticleNode : Node2D _labelNode = GetNode