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 7771d9db54
commit 6f5a2f402c
7 changed files with 114 additions and 43 deletions

View file

@ -29,9 +29,11 @@ var gravity : Vector3 = g * ProjectSettings.get_setting("physics/3d/default_gra
@onready var camera = $SpringArm3D/Camera3D
@onready var hud = $HUD
@onready var iff = $ThirdPerson/IFF
@onready var shape_cast = $ShapeCast3D
@onready var weapon = $SpringArm3D/Inventory/SpaceGun
@onready var animation_player : AnimationPlayer = $AnimationPlayer
@onready var health_component = $HealthComponent
@onready var spring_arm_height = $SpringArm3D.position.y
@ -44,12 +46,15 @@ var _jumping = false
func _ready():
energy_changed.connect(hud._on_energy_changed)
$HealthComponent.health_changed.connect(hud._on_health_changed)
$HealthComponent.health_zeroed.connect(_die)
health_component.health_changed.connect(hud._on_health_changed)
health_component.health_changed.connect(iff._on_health_changed)
health_component.health_changed.emit(health_component.health)
health_component.health_zeroed.connect(_die)
if player_id == multiplayer.get_unique_id():
camera.current = true
remove_child($ThirdPerson)
else:
$HUD.hide()
remove_child($HUD)
input.fired_primary.connect(_fire_primary)
input.jumped.connect(_jump)
@ -91,7 +96,10 @@ func _handle_jetpack(delta, direction):
func _process(_delta):
if player_state == PlayerState.PLAYER_DEAD:
iff.hide()
return
else:
iff.show()
%SpringArm3D.global_transform.basis = Basis.from_euler(Vector3(input.camera_rotation.y, input.camera_rotation.x, 0.0))
if animation_player.current_animation == "shoot":
@ -147,6 +155,6 @@ func _die():
func respawn(location):
linear_velocity = Vector3()
$HealthComponent.heal_full()
health_component.heal_full()
position = location
player_state = PlayerState.PLAYER_ALIVE

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=17 format=3 uid="uid://cbhx1xme0sb7k"]
[gd_scene load_steps=18 format=3 uid="uid://cbhx1xme0sb7k"]
[ext_resource type="Script" path="res://characters/player/player.gd" id="1_ymjub"]
[ext_resource type="PackedScene" uid="uid://bcv81ku26xo" path="res://interfaces/hud/hud.tscn" id="2_5qvi2"]
@ -6,6 +6,7 @@
[ext_resource type="Shape3D" uid="uid://dkwljsgaflf31" path="res://characters/player/collision_shape.res" id="2_y6kgj"]
[ext_resource type="PackedScene" uid="uid://bof3mg7wgxrmn" path="res://components/health_component.tscn" id="5_dlsxj"]
[ext_resource type="Script" path="res://characters/player/player_input.gd" id="6_xwlxv"]
[ext_resource type="PackedScene" uid="uid://dsysi2rd3bu76" path="res://interfaces/hud/iff.tscn" id="7_8hc80"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_clur0"]
resource_local_to_scene = true
@ -69,6 +70,33 @@ tracks/3/keys = {
"values": [Vector3(0, 0, 0)]
}
[sub_resource type="Animation" id="Animation_yqgrk"]
resource_name = "death"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("SpringArm3D:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector3(0, 0.5, 0), Vector3(0, -0.114794, 0)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("SpringArm3D:rotation")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.5),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector3(0, 0, 0), Vector3(-1.35254, 0, 0)]
}
[sub_resource type="Animation" id="Animation_as2v0"]
resource_name = "idle"
length = 3.0
@ -125,33 +153,6 @@ tracks/1/keys = {
"values": [Vector3(-0.0584511, 3.14159, 8.83593e-09), Vector3(0, 3.14159, 0)]
}
[sub_resource type="Animation" id="Animation_yqgrk"]
resource_name = "death"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("SpringArm3D:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector3(0, 0.5, 0), Vector3(0, -0.114794, 0)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("SpringArm3D:rotation")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.5),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector3(0, 0, 0), Vector3(-1.35254, 0, 0)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_hg307"]
_data = {
"RESET": SubResource("Animation_cb46l"),
@ -244,3 +245,10 @@ replication_config = SubResource("SceneReplicationConfig_rqdp6")
root_path = NodePath(".")
replication_config = SubResource("SceneReplicationConfig_5j4ew")
script = ExtResource("6_xwlxv")
[node name="IFFAttachment" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.27457, 0)
[node name="ThirdPerson" type="Node" parent="."]
[node name="IFF" parent="ThirdPerson" instance=ExtResource("7_8hc80")]

View file

@ -0,0 +1,4 @@
[gd_resource type="StyleBoxFlat" format=3 uid="uid://cl7dmo2bg4153"]
[resource]
bg_color = Color(1, 0.356863, 0.145098, 1)

View file

@ -1,5 +1,7 @@
[gd_scene load_steps=6 format=3 uid="uid://bcv81ku26xo"]
[ext_resource type="StyleBox" uid="uid://cl7dmo2bg4153" path="res://interfaces/hud/healthbar_fill_style.tres" id="1_gh51l"]
[sub_resource type="GDScript" id="GDScript_2vxif"]
script/source = "extends CanvasLayer
class_name HUD
@ -8,27 +10,24 @@ class_name HUD
@onready var _energy_bar = $EnergyBar
func _ready():
_update_health_label(100)
_update_energy_label(100)
_update_health_bar(100)
_update_energy_bar(100)
func _update_energy_label(energy) -> void:
func _update_energy_bar(energy) -> void:
_energy_bar.value = energy
func _on_energy_changed(new_energy) -> void:
_update_energy_label(new_energy)
_update_energy_bar(new_energy)
func _update_health_label(health) -> void:
func _update_health_bar(health) -> void:
_health_bar.value = health
func _on_health_changed(new_health) -> void:
_update_health_label(new_health)
_update_health_bar(new_health)
"
[sub_resource type="Theme" id="Theme_irfqb"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_8ju42"]
bg_color = Color(1, 0.356863, 0.145098, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_f23s3"]
bg_color = Color(0, 0.454902, 0.992157, 1)
@ -60,7 +59,7 @@ offset_bottom = 40.0
size_flags_horizontal = 0
mouse_filter = 2
theme = SubResource("Theme_irfqb")
theme_override_styles/fill = SubResource("StyleBoxFlat_8ju42")
theme_override_styles/fill = ExtResource("1_gh51l")
value = 60.0
show_percentage = false

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)

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

@ -0,0 +1,26 @@
[gd_scene load_steps=3 format=3 uid="uid://dsysi2rd3bu76"]
[ext_resource type="Script" path="res://interfaces/hud/iff.gd" id="1_75yi1"]
[ext_resource type="StyleBox" uid="uid://cl7dmo2bg4153" path="res://interfaces/hud/healthbar_fill_style.tres" id="2_x7k8o"]
[node name="IFF" type="Node2D"]
script = ExtResource("1_75yi1")
[node name="Offset" type="Node2D" parent="."]
position = Vector2(0, -32)
[node name="VBoxContainer" type="VBoxContainer" parent="Offset"]
offset_right = 100.0
offset_bottom = 40.0
mouse_filter = 2
[node name="PlayerNameLabel" type="Label" parent="Offset/VBoxContainer"]
layout_mode = 2
metadata/_edit_use_anchors_ = true
[node name="HealthBar" type="ProgressBar" parent="Offset/VBoxContainer"]
layout_mode = 2
mouse_filter = 2
theme_override_styles/fill = ExtResource("2_x7k8o")
value = 60.0
show_percentage = false

View file

@ -10,7 +10,7 @@ func _ready():
fire.emitting = true
func _physics_process(_delta):
var bodies = area_damage.get_overlapping_bodies()
var bodies = area_damage.get_overlapping_bodies() if area_damage.monitoring else []
for body in bodies:
if body is RigidBody3D:
var direction = (body.global_position - global_position).normalized()