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

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")