nice crooked connections und energy UI

This commit is contained in:
2026-05-21 22:41:05 +02:00
parent 661e62e8b8
commit 9c7c414bc9
7 changed files with 185 additions and 29 deletions

36
Root.cs
View File

@@ -1,4 +1,6 @@
using System.Linq;
using Godot;
using GodotSharp.SourceGenerators;
using GodotUtilities;
namespace NodeWar;
@@ -7,17 +9,45 @@ namespace NodeWar;
public partial class Root : Node2D
{
[Node]
private Line2D line2D;
private Line2D _line2D;
private Nodule a;
private Nodule b;
public override void _Ready()
{
GD.Print(line2D);
GD.Print(_line2D);
}
public void ConnectNodules(Nodule a, Nodule b)
{
this.a = a;
this.b = b;
GlobalPosition = a.GlobalPosition;
line2D.Points = [Vector2.Zero, b.GlobalPosition - a.GlobalPosition];
GenerateLinePoints();
}
private void GenerateLinePoints()
{
var direction = b.GlobalPosition - a.GlobalPosition;
var sectionLength = direction.Length() / 5;
var points = new Vector2[5];
for (var i = 0; i < 5; i++)
{
var randomOffset = new Vector2(MathUtil.RNG.Randf(), MathUtil.RNG.Randf());
points[i] = i switch
{
0 => Vector2.Zero,
4 => direction,
_ => (direction.Normalized() + (randomOffset * 0.1f)).Normalized()
* sectionLength
* i,
};
}
_line2D.Points = points;
}
public override void _Notification(int what)