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

View File

@@ -1,23 +1,28 @@
using System;
using System.Collections.Generic;
using Godot;
using GodotUtilities;
using NodeWar.scripts;
namespace NodeWar;
public enum NoduleType
{
Base,
Connector,
}
[Scene]
public partial class Nodule : Area2D
{
private const float GrowthFactor = 0.01f;
[Export]
public float Radius { get; set; } = 120;
private NoduleType _noduleType;
[Export]
public float MaxRadius { get; set; } = 360;
[Export]
public CollisionShape2D Collision { get; set; }
[Export]
public bool BuildMode { get; set; } = false;
@@ -35,13 +40,30 @@ public partial class Nodule : Area2D
[Signal]
public delegate void BuildingCanceledEventHandler();
[Node]
private Node2D _gfx;
[Node]
private CollisionShape2D _baseCollision;
public override void _Ready()
{
Radius = Age * MaxRadius;
AreaEntered += OnAreaEntered;
AreaExited += OnAreaExited;
switch (_noduleType)
{
case NoduleType.Base:
_gfx.Scale = new Vector2(2, 2);
Modulate = Colors.Red;
_baseCollision.Disabled = false;
break;
case NoduleType.Connector:
break;
default:
throw new ArgumentOutOfRangeException();
}
QueueRedraw();
}
@@ -97,7 +119,6 @@ public partial class Nodule : Area2D
Age += GrowthFactor * delta.ToFloat();
Age = MathF.Min(Age, 1);
Radius = Age * MaxRadius;
QueueRedraw();
}
@@ -127,13 +148,22 @@ public partial class Nodule : Area2D
}
}
if (BuildMode)
var value = 200 * Age;
if (!BuildMode)
{
DrawCircle(Vector2.Zero, Radius, new Color(Colors.DarkOliveGreen, 0.2f));
DrawRect(
new Rect2(-value / 2, -value / 2, value, value),
new Color(Colors.WhiteSmoke, 0.4f)
);
}
else
}
public override void _Notification(int what)
{
if (what == NotificationSceneInstantiated)
{
DrawCircle(Vector2.Zero, Radius, new Color(Colors.WhiteSmoke, 0.4f));
WireNodes();
}
}
}