This commit is contained in:
2026-05-14 13:17:23 +02:00
parent 37f4ea3b4e
commit 70bba45b8a
18 changed files with 293 additions and 71 deletions

13
Gui.cs Normal file
View File

@@ -0,0 +1,13 @@
using Godot;
using NodeWar.scripts;
public partial class Gui : Control
{
private Label _infoLabel;
public override void _Ready()
{
_infoLabel = GetNode<Label>("%InfoLabel");
EventBus.Instance.SelectionChanged += text => _infoLabel.Text = text;
}
}

1
Gui.cs.uid Normal file
View File

@@ -0,0 +1 @@
uid://7jql2b33svuv

View File

@@ -2,10 +2,12 @@
[ext_resource type="Script" uid="uid://demgvopfvjmql" path="res://scripts/Base.cs" id="1_21bcp"]
[ext_resource type="Texture2D" uid="uid://du7ejwu1yo0j1" path="res://assets/icon.svg" id="1_rpg24"]
[ext_resource type="PackedScene" uid="uid://c2blpf56yvidh" path="res://scripts/components/SpawnerComponent.tscn" id="2_42dj3"]
[ext_resource type="Script" uid="uid://de3jpss66xjfh" path="res://addons/curved_lines_2d/scalable_vector_shape_2d.gd" id="3_21bcp"]
[ext_resource type="Script" uid="uid://dlbv4pit17dnu" path="res://addons/curved_lines_2d/scalable_arc.gd" id="4_tpea4"]
[ext_resource type="Script" uid="uid://dl1t88tthmwts" path="res://addons/curved_lines_2d/scalable_arc_list.gd" id="5_42dj3"]
[ext_resource type="PackedScene" uid="uid://dn6jqa3wj40ir" path="res://scripts/components/health_component.tscn" id="6_tpea4"]
[ext_resource type="PackedScene" uid="uid://c24a65g4ixikh" path="res://scheppes_x.tscn" id="8_56f15"]
[sub_resource type="Curve2D" id="Curve2D_56f15"]
resource_local_to_scene = true
@@ -18,18 +20,39 @@ point_count = 5
resource_local_to_scene = true
script = ExtResource("5_42dj3")
[sub_resource type="Curve2D" id="Curve2D_cho24"]
resource_local_to_scene = true
_data = {
"points": PackedVector2Array(0, 0, 0, 0, 39.776398, -42.15619, 0, 0, 0, 0, -45.14743, 49.220245, 0, 0, 0, 0, -2.6800537, 3.5144196, 0, 0, 0, 0, -45.14743, -41.986115, 0, 0, 0, 0, 40.02704, 49.35132)
}
point_count = 5
[sub_resource type="Resource" id="Resource_dlkme"]
resource_local_to_scene = true
script = ExtResource("5_42dj3")
[sub_resource type="LabelSettings" id="LabelSettings_rpg24"]
font_size = 33
outline_size = 8
outline_color = Color(0, 0, 0, 1)
[node name="Base" type="Area2D" unique_id=1354578205]
[node name="Base" type="Area2D" unique_id=1354578205 node_paths=PackedStringArray("Target", "HealthComponent", "SpawnerComponent")]
script = ExtResource("1_21bcp")
Target = NodePath("Selection/Target")
HealthComponent = NodePath("HealthComponent")
SpawnerComponent = NodePath("SpawnerComponent")
[node name="SpawnerComponent" parent="." unique_id=1304757964 instance=ExtResource("2_42dj3")]
[node name="HealthComponent" parent="." unique_id=1360050278 instance=ExtResource("6_tpea4")]
offset_left = -99.0
offset_right = -72.0
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="." unique_id=1632145743]
polygon = PackedVector2Array(59.1, -64, -59, -64, -63.8, -59, -64, 61, -60.3, 64, 59.6, 64, 63.9, 59, 64, -61.1)
[node name="Selection" type="Node2D" parent="." unique_id=544477539 node_paths=PackedStringArray("line")]
visible = false
script = ExtResource("3_21bcp")
stroke_color = Color(0.36841604, 0.683675, 0.26152232, 1)
stroke_width = 4.0
@@ -41,7 +64,6 @@ shape_type = 2
size = Vector2(203.81091, 203.81091)
rx = 101.90546
ry = 101.90546
metadata/_select_hint_ = true
[node name="Stroke" type="Line2D" parent="Selection" unique_id=1625752545]
points = PackedVector2Array(101.90546, 0, 101.37935, 10.4194975, 99.83516, 20.537949, 97.32412, 30.304142, 93.89744, 39.66686, 89.60633, 48.574883, 84.50201, 56.976994, 78.635704, 64.821976, 72.058624, 72.058624, 64.821976, 78.63571, 56.97699, 84.502014, 48.574883, 89.60633, 39.666855, 93.89744, 30.304142, 97.32412, 20.537949, 99.83516, 10.419497, 101.37935, 0, 101.90546, -10.4194975, 101.37935, -20.537949, 99.83516, -30.304142, 97.32412, -39.66686, 93.89744, -48.574883, 89.60633, -56.976994, 84.50201, -64.821976, 78.635704, -72.058624, 72.058624, -78.63571, 64.821976, -84.502014, 56.97699, -89.60633, 48.574883, -93.89744, 39.666855, -97.32412, 30.304142, -99.83516, 20.537949, -101.37935, 10.419497, -101.90546, 0, -101.37935, -10.4194975, -99.83516, -20.537949, -97.32412, -30.304142, -93.89744, -39.66686, -89.60633, -48.574883, -84.50201, -56.976994, -78.635704, -64.821976, -72.058624, -72.058624, -64.821976, -78.63571, -56.97699, -84.502014, -48.574883, -89.60633, -39.666855, -93.89744, -30.304142, -97.32412, -20.537949, -99.83516, -10.419497, -101.37935, 0, -101.90546, 10.4194975, -101.37935, 20.537949, -99.83516, 30.304142, -97.32412, 39.66686, -93.89744, 48.574883, -89.60633, 56.976994, -84.50201, 64.821976, -78.635704, 72.058624, -72.058624, 78.63571, -64.821976, 84.502014, -56.97699, 89.60633, -48.574883, 93.89744, -39.666855, 97.32412, -30.304142, 99.83516, -20.537949, 101.37935, -10.419497)
@@ -52,10 +74,15 @@ sharp_limit = 90.0
antialiased = true
metadata/_edit_lock_ = true
[node name="Target" parent="Selection" unique_id=868654776 instance=ExtResource("8_56f15")]
curve = SubResource("Curve2D_cho24")
arc_list = SubResource("Resource_dlkme")
[node name="Gfx" type="Sprite2D" parent="." unique_id=1646140640]
texture = ExtResource("1_rpg24")
[node name="Label" type="Label" parent="." unique_id=1802037971]
visible = false
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
@@ -67,17 +94,5 @@ grow_horizontal = 2
text = "Base"
label_settings = SubResource("LabelSettings_rpg24")
[node name="ProgressBar" type="ProgressBar" parent="." unique_id=266338603]
offset_left = -70.0
offset_top = -97.0
offset_right = 70.0
offset_bottom = -70.0
max_value = 10.0
show_percentage = false
[node name="HealthComponent" parent="." unique_id=1360050278 instance=ExtResource("6_tpea4")]
offset_left = -99.0
offset_right = -72.0
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]

43
gui.tscn Normal file
View File

@@ -0,0 +1,43 @@
[gd_scene format=3 uid="uid://b1a13w4ckxnub"]
[ext_resource type="Script" uid="uid://7jql2b33svuv" path="res://Gui.cs" id="1_80edf"]
[sub_resource type="LabelSettings" id="LabelSettings_k6omp"]
line_spacing = -2.0
font_size = 14
[node name="GUI" type="Control" unique_id=1209092314]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_80edf")
[node name="PanelContainer" type="PanelContainer" parent="." unique_id=2071011957]
layout_mode = 1
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_left = 3.0
offset_top = -140.0
offset_right = 153.0
offset_bottom = -3.0
grow_vertical = 0
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer" unique_id=14334117]
layout_mode = 2
theme_override_constants/margin_left = 4
theme_override_constants/margin_top = 4
theme_override_constants/margin_right = 4
theme_override_constants/margin_bottom = 4
[node name="InfoLabel" type="Label" parent="PanelContainer/MarginContainer" unique_id=1653366042]
unique_name_in_owner = true
custom_minimum_size = Vector2(100, 100)
layout_mode = 2
size_flags_vertical = 1
label_settings = SubResource("LabelSettings_k6omp")
autowrap_mode = 3
text_overrun_behavior = 3

View File

@@ -3,7 +3,9 @@
[ext_resource type="Script" uid="uid://rirna2vebukw" path="res://addons/strategy_cam/strategy_camera.gd" id="2_0xm2m"]
[ext_resource type="PackedScene" uid="uid://dxfhhf4qu42bb" path="res://base.tscn" id="2_h2yge"]
[ext_resource type="Script" uid="uid://de3jpss66xjfh" path="res://addons/curved_lines_2d/scalable_vector_shape_2d.gd" id="3_lquwl"]
[ext_resource type="Script" uid="uid://bibq3e4nkwiwv" path="res://scripts/EventBus.cs" id="4_5vw27"]
[ext_resource type="Script" uid="uid://dlbv4pit17dnu" path="res://addons/curved_lines_2d/scalable_arc.gd" id="4_7mycd"]
[ext_resource type="PackedScene" uid="uid://b1a13w4ckxnub" path="res://gui.tscn" id="4_272bh"]
[ext_resource type="Script" uid="uid://dl1t88tthmwts" path="res://addons/curved_lines_2d/scalable_arc_list.gd" id="5_272bh"]
[ext_resource type="PackedScene" uid="uid://4b8osd3h3xbm" path="res://pip.tscn" id="6_7mycd"]
@@ -20,6 +22,14 @@ script = ExtResource("5_272bh")
[node name="Main" type="Node2D" unique_id=866253780]
[node name="EventBus" type="Node" parent="." unique_id=239508674]
script = ExtResource("4_5vw27")
[node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1010925224]
[node name="GUI" parent="CanvasLayer" unique_id=1209092314 instance=ExtResource("4_272bh")]
mouse_filter = 1
[node name="Stuff" type="Node" parent="." unique_id=1050239390]
[node name="Rectangle" type="Node2D" parent="Stuff" unique_id=742624159 node_paths=PackedStringArray("polygon", "line")]
@@ -55,10 +65,10 @@ position = Vector2(-680, -353)
Faction = 1
[node name="NeutralBase" parent="." unique_id=1354578205 instance=ExtResource("2_h2yge")]
position = Vector2(86, -199)
position = Vector2(365, -382)
[node name="NeutralBase2" parent="." unique_id=98685585 instance=ExtResource("2_h2yge")]
position = Vector2(-80, 226)
position = Vector2(-189, 396)
[node name="EnemyBase" parent="." unique_id=2059599822 groups=["enemyBase"] instance=ExtResource("2_h2yge")]
position = Vector2(707, 439)

View File

@@ -3,7 +3,6 @@
[ext_resource type="Script" uid="uid://cdbkkb2cpwkn1" path="res://scripts/Pip.cs" id="1_2foya"]
[ext_resource type="Texture2D" uid="uid://dkpk1ubnmbl68" path="res://assets/pip.png" id="2_46jm3"]
[ext_resource type="PackedScene" uid="uid://dn6jqa3wj40ir" path="res://scripts/components/health_component.tscn" id="3_46jm3"]
[ext_resource type="Script" uid="uid://bfi1cm0m4wuk2" path="res://Damager.cs" id="4_6fdkq"]
[node name="Pip" type="Area2D" unique_id=1889156888]
script = ExtResource("1_2foya")
@@ -16,13 +15,13 @@ polygon = PackedVector2Array(-18.5, -18.5, -18.5, 18.5, 18.5, 18.5, 18.5, -18.5)
texture = ExtResource("2_46jm3")
[node name="HealthComponent" parent="." unique_id=1360050278 node_paths=PackedStringArray("Gfx") instance=ExtResource("3_46jm3")]
visible = false
offset_left = -35.0
offset_top = -18.0
offset_right = -8.0
offset_bottom = 110.0
scale = Vector2(0.28840518, 0.28840518)
Gfx = NodePath("../Gfx")
Health = 5.0
MaxHealth = 5.0
[node name="Damager" type="Timer" parent="." unique_id=1839733483]
autostart = true
script = ExtResource("4_6fdkq")
[connection signal="area_entered" from="." to="." method="_on_area_entered"]

View File

@@ -20,6 +20,10 @@ run/main_scene="uid://bf7croj2rk4q6"
config/features=PackedStringArray("4.6", "C#", "Forward Plus")
config/icon="res://assets/icon.svg"
[autoload]
EventBus="*res://scripts/EventBus.cs"
[dotnet]
project/assembly_name="Node War"

34
scheppes_x.tscn Normal file
View File

@@ -0,0 +1,34 @@
[gd_scene format=3 uid="uid://c24a65g4ixikh"]
[ext_resource type="Script" uid="uid://de3jpss66xjfh" path="res://addons/curved_lines_2d/scalable_vector_shape_2d.gd" id="1_ritjc"]
[ext_resource type="Script" uid="uid://dlbv4pit17dnu" path="res://addons/curved_lines_2d/scalable_arc.gd" id="2_31jy3"]
[ext_resource type="Script" uid="uid://dl1t88tthmwts" path="res://addons/curved_lines_2d/scalable_arc_list.gd" id="3_q0qps"]
[sub_resource type="Curve2D" id="Curve2D_nusja"]
resource_local_to_scene = true
_data = {
"points": PackedVector2Array(0, 0, 0, 0, 39.776398, -42.15619, 0, 0, 0, 0, -45.14743, 49.220245, 0, 0, 0, 0, -2.6800537, 3.5144196, 0, 0, 0, 0, -45.14743, -41.986115, 0, 0, 0, 0, 40.02704, 49.35132)
}
point_count = 5
[sub_resource type="Resource" id="Resource_5qe8n"]
resource_local_to_scene = true
script = ExtResource("3_q0qps")
[node name="Path" type="Node2D" unique_id=868654776 node_paths=PackedStringArray("line")]
script = ExtResource("1_ritjc")
begin_cap_mode = 2
end_cap_mode = 2
line_joint_mode = 2
line = NodePath("Stroke")
curve = SubResource("Curve2D_nusja")
update_curve_at_runtime = true
arc_list = SubResource("Resource_5qe8n")
[node name="Stroke" type="Line2D" parent="." unique_id=845910700]
points = PackedVector2Array(39.776398, -42.15619, -45.14743, 49.220245, -2.6800537, 3.5144196, -45.14743, -41.986115, 40.02704, 49.35132)
joint_mode = 2
begin_cap_mode = 2
end_cap_mode = 2
sharp_limit = 90.0
metadata/_edit_lock_ = true

View File

@@ -1,27 +1,33 @@
using System;
using Godot;
using NodeWar;
using NodeWar.Scripts;
using NodeWar.scripts.components;
namespace NodeWar.scripts;
public partial class Base : Area2D
{
private ProgressBar _progressBar;
public HealthComponent HealthComponent;
private Node2D _selection;
private Node2D _gfx;
public Vector2 TargetPosition { get; set; }
[Export]
public Node2D Target;
[Export]
public HealthComponent HealthComponent;
[Export]
public SpawnerComponent SpawnerComponent;
[Export]
public bool Selected = false;
[Export]
public Faction Faction = Faction.Neutral;
private float _buildSpeed = 28;
private float _buildProgress = 0;
private float _maxBuildProgress = 100;
private bool _mouseInside = false;
private bool _selected = false;
private PackedScene _pipScene = GD.Load<PackedScene>("res://pip.tscn");
@@ -30,44 +36,46 @@ public partial class Base : Area2D
MouseEntered += OnMouseEntered;
MouseExited += OnMouseExited;
HealthComponent = GetNode<HealthComponent>("HealthComponent");
_progressBar = GetNode<ProgressBar>("ProgressBar");
_selection = GetNode<Node2D>("Selection");
_gfx = GetNode<Node2D>("Gfx");
_selection.Visible = false;
_progressBar.MaxValue = _maxBuildProgress;
HealthComponent.MaxHealth = 100;
HealthComponent.Health = 100;
SpawnerComponent.Faction = Faction;
UpdateColor();
}
public override void _Process(double delta)
{
if (Faction == Faction.Neutral)
return;
_buildProgress += _buildSpeed * delta.ToFloat();
if (_buildProgress >= _maxBuildProgress)
{
_buildProgress = 0;
var pip = _pipScene.Instantiate<Pip>();
GetParent().AddChild(pip);
pip.Faction = Faction;
pip.GlobalPosition = GlobalPosition;
pip.Target = GetTree().GetFirstNodeInGroup("enemyBase") as Base;
}
UpdateProgressBars();
}
public override void _UnhandledInput(InputEvent @event)
{
if (@event is InputEventMouseButton { Pressed: true, ButtonIndex: MouseButton.Left })
{
_selection.Visible = _mouseInside;
_selected = _mouseInside;
if (_selected)
{
_selection.Visible = true;
// TODO: super ugly
EventBus.Instance.EmitSignal(
EventBus.SignalName.SelectionChanged,
"This is a Base"
);
}
else
{
_selection.Visible = false;
}
}
if (
@event is InputEventMouseButton { Pressed: true, ButtonIndex: MouseButton.Right }
&& _selected
)
{
// TODO: 3 Stellen eine Sache zu speichern?
TargetPosition = GetGlobalMousePosition();
Target.GlobalPosition = TargetPosition;
SpawnerComponent.Target = TargetPosition;
}
}
@@ -82,11 +90,6 @@ public partial class Base : Area2D
};
}
private void UpdateProgressBars()
{
_progressBar.Value = _buildProgress;
}
private void OnMouseExited()
{
_mouseInside = false;

23
scripts/EventBus.cs Normal file
View File

@@ -0,0 +1,23 @@
using Godot;
namespace NodeWar.scripts;
public partial class EventBus : Node
{
[Signal]
public delegate void GameStartedEventHandler();
[Signal]
public delegate void GameEndedEventHandler(bool win);
[Signal]
public delegate void SelectionChangedEventHandler(string infoText);
public static EventBus Instance { get; private set; }
public override void _EnterTree()
{
Instance ??= this;
}
}

1
scripts/EventBus.cs.uid Normal file
View File

@@ -0,0 +1 @@
uid://bibq3e4nkwiwv

View File

@@ -1,8 +1,8 @@
namespace NodeWar;
namespace NodeWar.scripts;
public enum Faction
{
Neutral,
Player,
Computer
}
Computer,
}

View File

@@ -1,5 +1,6 @@
using System;
using Godot;
using NodeWar.scripts;
namespace NodeWar.Scripts;
@@ -9,7 +10,7 @@ public partial class Pip : Area2D
public Faction Faction;
[Export]
public Base Target;
public Vector2 Target;
[Export]
public float Speed { get; set; } = 100;
@@ -33,16 +34,13 @@ public partial class Pip : Area2D
public override void _Process(double delta)
{
if (Target == null)
return;
var direction = Target.Position - GlobalPosition;
var direction = Target - GlobalPosition;
Position += direction.Normalized() * Speed * delta.ToFloat();
}
private void OnAreaEntered(Node2D body)
{
if (body is Base { Faction: Faction.Computer } enteredBase)
if (body is Base enteredBase && enteredBase.Faction != Faction)
{
enteredBase.HealthComponent.TakeDamage(1);
QueueFree();

10
scripts/TODO.md Normal file
View File

@@ -0,0 +1,10 @@
# TODO
- [ ] dummy
- [ ] dummy
# DONE
14/05/26
- [x] Base spawns only Pips of its faction
- [x] Ability to set a waypoint for pips (a la Buggos or Flow Fields?)

View File

@@ -1,3 +1,4 @@
using System;
using System.Threading.Tasks;
using Godot;
@@ -5,11 +6,25 @@ namespace NodeWar.scripts.components;
public partial class HealthComponent : ProgressBar
{
private float _health = 100;
[Export]
public Sprite2D Gfx { get; set; }
[Export]
public float Health { get; set; } = 100;
public float Health
{
get => _health;
set
{
if (value >= MaxHealth)
{
_health = MaxHealth;
}
_health = value;
}
}
[Export]
public float MaxHealth { get; set; } = 100;
@@ -55,6 +70,8 @@ public partial class HealthComponent : ProgressBar
public override void _Process(double delta)
{
Visible = Math.Abs(Health - MaxHealth) > 0.001f;
Value = Health;
}
}

View File

@@ -0,0 +1,42 @@
using Godot;
using NodeWar.Scripts;
namespace NodeWar.scripts.components;
public partial class SpawnerComponent : Node
{
[Export]
public PackedScene Spawnee;
[Export]
public Faction Faction;
[Export]
public float BuildSpeed = 28;
[Export]
public float BuildProgress = 0;
[Export]
public float MaxBuildProgress = 100;
public Vector2 Target { get; set; }
public override void _Ready() { }
public override void _Process(double delta)
{
BuildProgress += BuildSpeed * delta.ToFloat();
if (BuildProgress >= MaxBuildProgress)
{
BuildProgress = 0;
var pip = Spawnee.Instantiate<Pip>();
pip.Faction = Faction;
pip.Target = Target;
GetParent().AddChild(pip);
pip.GlobalPosition = GetParent<Node2D>().GlobalPosition;
}
}
}

View File

@@ -0,0 +1 @@
uid://bkjuvw4kmtnq4

View File

@@ -0,0 +1,8 @@
[gd_scene format=3 uid="uid://c2blpf56yvidh"]
[ext_resource type="Script" uid="uid://bkjuvw4kmtnq4" path="res://scripts/components/SpawnerComponent.cs" id="1_6hmx4"]
[ext_resource type="PackedScene" uid="uid://4b8osd3h3xbm" path="res://pip.tscn" id="2_x4vwu"]
[node name="SpawnerComponent" type="Node" unique_id=1304757964]
script = ExtResource("1_6hmx4")
Spawnee = ExtResource("2_x4vwu")