Basic implementation of IFF indicators showing player names and health bars

This commit is contained in:
Squinternator 2024-04-11 22:13:21 +00:00
parent 424c01bc02
commit 7e52ededc0
7 changed files with 114 additions and 43 deletions

26
interfaces/hud/iff.gd Normal file
View file

@ -0,0 +1,26 @@
extends Node2D
@onready var _player = $"../.."
@onready var _player_name_label = $Offset/VBoxContainer/PlayerNameLabel
@onready var _iff_attachment = $"../../IFFAttachment"
@onready var _health_bar = $Offset/VBoxContainer/HealthBar
@onready var _v_box_container = $Offset/VBoxContainer
func _process(_delta):
var camera : Camera3D = get_viewport().get_camera_3d()
if camera.is_position_behind(_iff_attachment.global_position):
_v_box_container.hide()
else:
_v_box_container.show()
_player_name_label.text = _player.name
position = camera.unproject_position(_iff_attachment.global_position)
var viewport_size : Vector2 = get_viewport_rect().size
position.x = clampf(position.x, 0, viewport_size.x - _v_box_container.size.x)
position.y = clampf(position.y, _v_box_container.size.y, viewport_size.y)
func _update_health_bar(health) -> void:
_health_bar.value = health
func _on_health_changed(new_health) -> void:
_update_health_bar(new_health)