This commit is contained in:
2026-05-13 18:52:00 +02:00
commit 2bb1acbece
404 changed files with 33353 additions and 0 deletions

103
scripts/Base.cs Normal file
View File

@@ -0,0 +1,103 @@
using System;
using Godot;
using NodeWar;
using NodeWar.Scripts;
public partial class Base : Area2D
{
private ProgressBar _progressBar;
private ProgressBar _healthBar;
private Node2D _selection;
private Node2D _gfx;
[Export]
public bool Selected = false;
[Export]
public Faction Faction = Faction.Neutral;
[Export]
public float Health { get; set; } = 50;
[Export]
public float MaxHealth { get; set; } = 50;
private float _buildSpeed = 28;
private float _buildProgress = 0;
private float _maxBuildProgress = 100;
private bool _mouseInside = false;
private PackedScene _pipScene = GD.Load<PackedScene>("res://pip.tscn");
public override void _Ready()
{
MouseEntered += OnMouseEntered;
MouseExited += OnMouseExited;
_healthBar = GetNode<ProgressBar>("HealthBar");
_progressBar = GetNode<ProgressBar>("ProgressBar");
_selection = GetNode<Node2D>("Selection");
_gfx = GetNode<Node2D>("Gfx");
_selection.Visible = false;
_progressBar.MaxValue = _maxBuildProgress;
_healthBar.MaxValue = MaxHealth;
_healthBar.Value = Health;
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.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;
}
}
private void UpdateColor()
{
_gfx.Modulate = Faction switch
{
Faction.Neutral => Colors.Gray,
Faction.Player => Colors.ForestGreen,
Faction.Computer => Colors.Red,
_ => throw new ArgumentOutOfRangeException(),
};
}
private void UpdateProgressBars()
{
_progressBar.Value = _buildProgress;
_healthBar.Value = Health;
}
private void OnMouseExited()
{
_mouseInside = false;
}
private void OnMouseEntered()
{
_mouseInside = true;
}
}

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

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

9
scripts/Extensions.cs Normal file
View File

@@ -0,0 +1,9 @@
namespace NodeWar;
public static class Extensions
{
public static float ToFloat(this double value)
{
return (float)value;
}
}

View File

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

8
scripts/Faction.cs Normal file
View File

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

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

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

38
scripts/Pip.cs Normal file
View File

@@ -0,0 +1,38 @@
using Godot;
namespace NodeWar.Scripts;
public partial class Pip : Area2D
{
[Export]
public Faction Faction;
[Export]
public Base Target;
[Export]
public float Speed { get; set; } = 100;
public override void _Ready()
{
AreaEntered += OnAreaEntered;
}
public override void _Process(double delta)
{
if (Target == null)
return;
var direction = Target.Position - GlobalPosition;
Position += direction.Normalized() * Speed * delta.ToFloat();
}
private void OnAreaEntered(Node2D body)
{
if (body is Base { Faction: Faction.Computer } enteredBase)
{
enteredBase.Health -= 1;
QueueFree();
}
}
}

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

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