better healthbars and one for the player as well
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 42s
Create tag and build when new code gets to main / Test (push) Successful in 6m13s
Create tag and build when new code gets to main / Export (push) Successful in 7m5s

This commit is contained in:
2026-01-26 18:09:29 +01:00
parent 2fdc9c7ca8
commit ddf1bd019b
12 changed files with 190 additions and 49 deletions

View File

@@ -1,26 +1,14 @@
using Godot;
using System;
using Movementtests.interfaces;
[GlobalClass]
public partial class CHealthbar : Node3D
public partial class CHealthbar : Sprite3D
{
private Sprite3D _currentHealth;
private float _initialXScale;
private Healthbar _healthbar;
public Healthbar Healthbar => _healthbar;
public override void _Ready()
{
Visible = false;
_currentHealth = GetNode<Sprite3D>("Health");
_initialXScale = _currentHealth.Scale.X;
}
public void OnHealthChanged(HealthChangedRecord healthChanged)
{
if (healthChanged.MaxHealth == 0) return;
Visible = true;
var healthPercentage = healthChanged.CurrentHealth / healthChanged.MaxHealth;
_currentHealth.Scale = new Vector3(_initialXScale * healthPercentage, _currentHealth.Scale.Y, _currentHealth.Scale.Z);
_healthbar = GetNode<Healthbar>("%Healthbar");
}
}

View File

@@ -1 +1 @@
uid://dve6vg6yvg4y8
uid://chfb3cjo6exga

View File

@@ -1,27 +1,32 @@
[gd_scene load_steps=3 format=3 uid="uid://bwx2um43k0ou4"]
[gd_scene load_steps=4 format=3 uid="uid://bwx2um43k0ou4"]
[ext_resource type="Texture2D" uid="uid://vpcxswwn1mt6" path="res://assets/ui/white-square-100px.png" id="1_jlvej"]
[ext_resource type="Script" uid="uid://dve6vg6yvg4y8" path="res://components/health/CHealthbar.cs" id="1_w5itk"]
[ext_resource type="Script" uid="uid://chfb3cjo6exga" path="res://components/health/CHealthbar.cs" id="1_w5itk"]
[ext_resource type="PackedScene" uid="uid://cyw8p0p6a78tl" path="res://scenes/ui/healthbar.tscn" id="2_w5itk"]
[node name="CHealthBar" type="Node3D"]
[sub_resource type="ViewportTexture" id="ViewportTexture_jkj2g"]
viewport_path = NodePath("SubViewport")
[node name="CHealthBar" type="Sprite3D"]
billboard = 1
double_sided = false
no_depth_test = true
texture = SubResource("ViewportTexture_jkj2g")
script = ExtResource("1_w5itk")
[node name="Bar" type="Sprite3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.1, 0, 0, 0, 1, 0, 0, 0)
cast_shadow = 0
billboard = 1
transparent = false
double_sided = false
no_depth_test = true
texture = ExtResource("1_jlvej")
[node name="SubViewport" type="SubViewport" parent="."]
transparent_bg = true
size = Vector2i(520, 20)
[node name="Health" type="Sprite3D" parent="."]
transform = Transform3D(0.99, 0, 0, 0, 0.09, 0, 0, 0, 1, 0, 0, 0)
cast_shadow = 0
modulate = Color(0.7191989, 0.19340843, 1.92523e-07, 1)
billboard = 1
transparent = false
double_sided = false
no_depth_test = true
render_priority = 10
texture = ExtResource("1_jlvej")
[node name="Healthbar" parent="SubViewport" 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