complete project reorganization
This commit is contained in:
35
scenes/components/health/CHealth.cs
Normal file
35
scenes/components/health/CHealth.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/white/icon_heart.png")]
|
||||
public partial class CHealth : Node, IHealthable
|
||||
{
|
||||
public event Action<IHealthable, HealthChangedRecord> HealthChanged;
|
||||
public event Action<IHealthable> HealthDepleted;
|
||||
|
||||
[Export]
|
||||
public RHealth RHealth { get; set; }
|
||||
|
||||
public float CurrentHealth { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
CurrentHealth = RHealth.StartingHealth;
|
||||
}
|
||||
|
||||
public HealthChangedRecord ReduceHealth(IDamageable source, DamageRecord damageRecord)
|
||||
{
|
||||
var previousHealth = CurrentHealth;
|
||||
CurrentHealth -= damageRecord.Damage.DamageDealt;
|
||||
var record = new HealthChangedRecord(CurrentHealth, previousHealth, RHealth.StartingHealth);
|
||||
HealthChanged?.Invoke(this, record);
|
||||
|
||||
if (CurrentHealth <= 0)
|
||||
{
|
||||
CurrentHealth = 0;
|
||||
HealthDepleted?.Invoke(this);
|
||||
}
|
||||
return record;
|
||||
}
|
||||
}
|
||||
1
scenes/components/health/CHealth.cs.uid
Normal file
1
scenes/components/health/CHealth.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bjwrpv3jpsc1e
|
||||
6
scenes/components/health/CHealth.tscn
Normal file
6
scenes/components/health/CHealth.tscn
Normal file
@@ -0,0 +1,6 @@
|
||||
[gd_scene format=3 uid="uid://c4ikbhojckpnc"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bjwrpv3jpsc1e" path="res://scenes/components/health/CHealth.cs" id="1_75uyt"]
|
||||
|
||||
[node name="CHealth" type="Node" unique_id=1940090217]
|
||||
script = ExtResource("1_75uyt")
|
||||
14
scenes/components/health/CHealthbar.cs
Normal file
14
scenes/components/health/CHealthbar.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_heart.png")]
|
||||
public partial class CHealthbar : Sprite3D
|
||||
{
|
||||
private Healthbar _healthbar;
|
||||
public Healthbar Healthbar => _healthbar;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_healthbar = GetNode<Healthbar>("%Healthbar");
|
||||
}
|
||||
}
|
||||
1
scenes/components/health/CHealthbar.cs.uid
Normal file
1
scenes/components/health/CHealthbar.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://chfb3cjo6exga
|
||||
32
scenes/components/health/CHealthbar.tscn
Normal file
32
scenes/components/health/CHealthbar.tscn
Normal file
@@ -0,0 +1,32 @@
|
||||
[gd_scene format=3 uid="uid://bwx2um43k0ou4"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://chfb3cjo6exga" path="res://scenes/components/health/CHealthbar.cs" id="1_w5itk"]
|
||||
[ext_resource type="PackedScene" uid="uid://cyw8p0p6a78tl" path="res://scenes/ui/healthbar/healthbar.tscn" id="2_w5itk"]
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_jkj2g"]
|
||||
viewport_path = NodePath("SubViewport")
|
||||
|
||||
[node name="CHealthBar" type="Sprite3D" unique_id=1527974573]
|
||||
billboard = 1
|
||||
double_sided = false
|
||||
no_depth_test = true
|
||||
texture = SubResource("ViewportTexture_jkj2g")
|
||||
script = ExtResource("1_w5itk")
|
||||
|
||||
[node name="SubViewport" type="SubViewport" parent="." unique_id=791051331]
|
||||
transparent_bg = true
|
||||
size = Vector2i(520, 20)
|
||||
|
||||
[node name="Healthbar" parent="SubViewport" unique_id=739464079 instance=ExtResource("2_w5itk")]
|
||||
unique_name_in_owner = true
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -120.0
|
||||
offset_top = -4.0
|
||||
offset_right = 120.0
|
||||
offset_bottom = 4.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
12
scenes/components/health/RDeathEffect.cs
Normal file
12
scenes/components/health/RDeathEffect.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/control/icon_thunder.png")]
|
||||
public partial class RDeathEffect : Resource, IKillable
|
||||
{
|
||||
public void Kill(IHealthable source)
|
||||
{
|
||||
GD.Print($"Death Effect triggered on {source}");
|
||||
}
|
||||
}
|
||||
1
scenes/components/health/RDeathEffect.cs.uid
Normal file
1
scenes/components/health/RDeathEffect.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b4cwruitopcee
|
||||
16
scenes/components/health/RHealth.cs
Normal file
16
scenes/components/health/RHealth.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/white/icon_heart.png")]
|
||||
public partial class RHealth : Resource
|
||||
{
|
||||
[Export]
|
||||
public float StartingHealth { get; set;}
|
||||
|
||||
public RHealth() : this(100.0f) {}
|
||||
public RHealth(float startingHealth)
|
||||
{
|
||||
StartingHealth = startingHealth;
|
||||
}
|
||||
}
|
||||
1
scenes/components/health/RHealth.cs.uid
Normal file
1
scenes/components/health/RHealth.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://baiapod3csndf
|
||||
Reference in New Issue
Block a user