Added health bars
This commit is contained in:
parent
ba978049a5
commit
6727be5cd0
@ -8,8 +8,6 @@
|
||||
|
||||
[node name="Follow" type="Marker3D"]
|
||||
script = ExtResource("1_48rtd")
|
||||
interpolate = true
|
||||
speed = 10.0
|
||||
|
||||
[node name="Pivot" type="Marker3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.4, 0)
|
||||
|
@ -1,3 +0,0 @@
|
||||
class_name Attack
|
||||
|
||||
var damage: float
|
@ -1,2 +0,0 @@
|
||||
class_name Character
|
||||
extends CharacterBody3D
|
@ -1,15 +0,0 @@
|
||||
class_name HealthComponent
|
||||
extends Node
|
||||
|
||||
@export var max_health: float
|
||||
|
||||
var health: float
|
||||
|
||||
func _ready():
|
||||
health = max_health
|
||||
|
||||
func take_damage(attack: Attack):
|
||||
health -= attack.damage
|
||||
|
||||
if health <= 0:
|
||||
get_parent().queue_free()
|
@ -1,2 +1,2 @@
|
||||
class_name Enemy
|
||||
extends Character
|
||||
extends CharacterBody3D
|
||||
|
@ -1,9 +1,10 @@
|
||||
[gd_scene load_steps=9 format=3 uid="uid://cb2t7bvvf3gwh"]
|
||||
[gd_scene load_steps=10 format=3 uid="uid://cb2t7bvvf3gwh"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://b358op5h1y83m" path="res://assets/slime/Slime.blend" id="1_1h1hj"]
|
||||
[ext_resource type="Script" path="res://enemy/Enemy.gd" id="1_r5888"]
|
||||
[ext_resource type="PackedScene" uid="uid://2bbycjulf00g" path="res://character/health/HealthComponent.tscn" id="2_fsqxc"]
|
||||
[ext_resource type="PackedScene" uid="uid://x102pryt2s5a" path="res://character/movement/MovementComponent.tscn" id="3_2phqx"]
|
||||
[ext_resource type="PackedScene" uid="uid://2bbycjulf00g" path="res://player/health/HealthComponent.tscn" id="2_fsqxc"]
|
||||
[ext_resource type="PackedScene" uid="uid://x102pryt2s5a" path="res://player/movement/MovementComponent.tscn" id="3_2phqx"]
|
||||
[ext_resource type="PackedScene" uid="uid://6jpnl6c4fdvo" path="res://player/hud/HUDComponent.tscn" id="3_4jtio"]
|
||||
|
||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_ub3kk"]
|
||||
height = 0.5
|
||||
@ -48,6 +49,10 @@ script = ExtResource("1_r5888")
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0452515, 0.3, 0)
|
||||
shape = SubResource("CylinderShape3D_ub3kk")
|
||||
|
||||
[node name="HUD" parent="." node_paths=PackedStringArray("health") instance=ExtResource("3_4jtio")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.986405, 0)
|
||||
health = NodePath("../Health")
|
||||
|
||||
[node name="Animation" type="AnimationPlayer" parent="."]
|
||||
root_node = NodePath("../Model")
|
||||
libraries = {
|
||||
|
@ -4,8 +4,10 @@ extends CharacterBody3D
|
||||
signal attacked
|
||||
signal dashed
|
||||
signal jumped
|
||||
signal name_changed(new_name: String)
|
||||
signal direction_changed
|
||||
|
||||
var id: String
|
||||
var controller: Controller
|
||||
|
||||
func attack():
|
||||
@ -20,10 +22,6 @@ func jump():
|
||||
func set_direction(direction: Vector3):
|
||||
direction_changed.emit(direction)
|
||||
|
||||
# TODO: Remove this:
|
||||
|
||||
var id: String
|
||||
|
||||
func set_character_name(new_name: String):
|
||||
func set_player_name(new_name: String):
|
||||
name = new_name
|
||||
$Label.text = name
|
||||
name_changed.emit(new_name)
|
||||
|
@ -1,16 +1,18 @@
|
||||
[gd_scene load_steps=13 format=3 uid="uid://2lcnu3dy54lx"]
|
||||
[gd_scene load_steps=15 format=3 uid="uid://2lcnu3dy54lx"]
|
||||
|
||||
[ext_resource type="Script" path="res://player/Player.gd" id="1_8gebs"]
|
||||
[ext_resource type="PackedScene" uid="uid://c8j7t4yg7anb0" path="res://assets/female/Female.blend" id="2_8nah6"]
|
||||
[ext_resource type="PackedScene" uid="uid://2bbycjulf00g" path="res://character/health/HealthComponent.tscn" id="2_np5ag"]
|
||||
[ext_resource type="PackedScene" uid="uid://2bbycjulf00g" path="res://player/health/HealthComponent.tscn" id="2_np5ag"]
|
||||
[ext_resource type="PackedScene" uid="uid://cgqbkj8wbcatv" path="res://assets/hair/PonyTail.blend" id="3_umw6q"]
|
||||
[ext_resource type="FontFile" uid="uid://b7mov13kwi8u8" path="res://assets/font/ubuntu_nf_regular.ttf" id="4_76ehj"]
|
||||
[ext_resource type="Skin" uid="uid://bbqyiue1vj37f" path="res://assets/hoodie/Hoodie_Skin.tres" id="4_b1tg1"]
|
||||
[ext_resource type="ArrayMesh" uid="uid://dbmluwi2atit" path="res://assets/hoodie/Hoodie_Mesh.res" id="5_mkrgn"]
|
||||
[ext_resource type="PackedScene" uid="uid://x102pryt2s5a" path="res://character/movement/MovementComponent.tscn" id="8_25qd0"]
|
||||
[ext_resource type="PackedScene" uid="uid://d0onbq0ad1ap4" path="res://character/rotation/RotationComponent.tscn" id="9_agxqu"]
|
||||
[ext_resource type="PackedScene" uid="uid://bivxnxwi863o0" path="res://character/animation/AnimationComponent.tscn" id="10_bcaeg"]
|
||||
[ext_resource type="PackedScene" uid="uid://6jpnl6c4fdvo" path="res://player/hud/HUDComponent.tscn" id="7_fwgtd"]
|
||||
[ext_resource type="PackedScene" uid="uid://x102pryt2s5a" path="res://player/movement/MovementComponent.tscn" id="8_25qd0"]
|
||||
[ext_resource type="PackedScene" uid="uid://d0onbq0ad1ap4" path="res://player/rotation/RotationComponent.tscn" id="9_agxqu"]
|
||||
[ext_resource type="PackedScene" uid="uid://bivxnxwi863o0" path="res://player/animation/AnimationComponent.tscn" id="10_bcaeg"]
|
||||
[ext_resource type="AnimationLibrary" uid="uid://d4n0puibh4hyt" path="res://assets/animations/human.blend" id="11_d0e6r"]
|
||||
[ext_resource type="PackedScene" uid="uid://b8xf4ltqyorjv" path="res://player/skills/SkillsComponent.tscn" id="14_6idcf"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_2f50n"]
|
||||
radius = 0.3
|
||||
@ -52,6 +54,7 @@ shape = SubResource("CapsuleShape3D_2f50n")
|
||||
|
||||
[node name="Label" type="Label3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0)
|
||||
visible = false
|
||||
pixel_size = 0.0005
|
||||
billboard = 1
|
||||
double_sided = false
|
||||
@ -62,12 +65,17 @@ font = ExtResource("4_76ehj")
|
||||
font_size = 256
|
||||
outline_size = 32
|
||||
|
||||
[node name="HUD" parent="." node_paths=PackedStringArray("health") instance=ExtResource("7_fwgtd")]
|
||||
health = NodePath("../Health")
|
||||
|
||||
[node name="Attractor" type="GPUParticlesAttractorSphere3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||
strength = 15.0
|
||||
radius = 2.0
|
||||
|
||||
[node name="Health" parent="." instance=ExtResource("2_np5ag")]
|
||||
unique_name_in_owner = true
|
||||
max_value = 100.0
|
||||
|
||||
[node name="Movement" parent="." instance=ExtResource("8_25qd0")]
|
||||
|
||||
@ -82,5 +90,7 @@ libraries = {
|
||||
"human": ExtResource("11_d0e6r")
|
||||
}
|
||||
|
||||
[node name="Skills" parent="." instance=ExtResource("14_6idcf")]
|
||||
|
||||
[editable path="Model/Female"]
|
||||
[editable path="Animation"]
|
||||
|
@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://bivxnxwi863o0"]
|
||||
|
||||
[ext_resource type="Script" path="res://character/animation/AnimationComponent.gd" id="1_lenw3"]
|
||||
[ext_resource type="Script" path="res://player/animation/AnimationComponent.gd" id="1_lenw3"]
|
||||
|
||||
[node name="Animation" type="Node"]
|
||||
script = ExtResource("1_lenw3")
|
7
client/player/health/DamageInstance.gd
Normal file
7
client/player/health/DamageInstance.gd
Normal file
@ -0,0 +1,7 @@
|
||||
class_name DamageInstance
|
||||
|
||||
var damage: float
|
||||
|
||||
func _init(_damage: float):
|
||||
damage = _damage
|
||||
|
18
client/player/health/HealthComponent.gd
Normal file
18
client/player/health/HealthComponent.gd
Normal file
@ -0,0 +1,18 @@
|
||||
class_name HealthComponent
|
||||
extends Node
|
||||
|
||||
signal value_changed
|
||||
|
||||
@export var max_value: float
|
||||
var value: float
|
||||
|
||||
func _ready():
|
||||
value = max_value
|
||||
value_changed.emit()
|
||||
|
||||
func take_damage(attack: DamageInstance):
|
||||
value -= attack.damage
|
||||
value_changed.emit()
|
||||
|
||||
if value <= 0:
|
||||
owner.queue_free()
|
@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://2bbycjulf00g"]
|
||||
|
||||
[ext_resource type="Script" path="res://character/health/HealthComponent.gd" id="1_403dm"]
|
||||
[ext_resource type="Script" path="res://player/health/HealthComponent.gd" id="1_403dm"]
|
||||
|
||||
[node name="Health" type="Node"]
|
||||
script = ExtResource("1_403dm")
|
14
client/player/hud/HUDComponent.gd
Normal file
14
client/player/hud/HUDComponent.gd
Normal file
@ -0,0 +1,14 @@
|
||||
class_name HUDComponent
|
||||
extends Sprite3D
|
||||
|
||||
@export var health: HealthComponent
|
||||
|
||||
func _ready():
|
||||
texture = $SubViewport.get_texture()
|
||||
update_name(owner.name)
|
||||
|
||||
if owner.has_signal("name_changed"):
|
||||
owner.name_changed.connect(update_name)
|
||||
|
||||
func update_name(new_name: String):
|
||||
%Label.text = new_name
|
44
client/player/hud/HUDComponent.tscn
Normal file
44
client/player/hud/HUDComponent.tscn
Normal file
@ -0,0 +1,44 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://6jpnl6c4fdvo"]
|
||||
|
||||
[ext_resource type="Script" path="res://player/hud/HUDComponent.gd" id="1_vynft"]
|
||||
[ext_resource type="Texture2D" uid="uid://d2rig4p2dfy30" path="res://assets/ui/bar-green.png" id="2_ad7qf"]
|
||||
[ext_resource type="Script" path="res://player/hud/HealthBar.gd" id="3_61bgt"]
|
||||
[ext_resource type="Texture2D" uid="uid://deopmcycal0aq" path="res://assets/ui/bar-yellow.png" id="4_5dl20"]
|
||||
[ext_resource type="Texture2D" uid="uid://cjg6cgv6hvnd" path="res://assets/ui/bar-red.png" id="5_3x8xp"]
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_y8qrs"]
|
||||
font_size = 32
|
||||
shadow_color = Color(0, 0, 0, 1)
|
||||
|
||||
[node name="HUD" type="Sprite3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.83994, 0)
|
||||
pixel_size = 0.003
|
||||
billboard = 1
|
||||
region_rect = Rect2(0, 0, 84, 26)
|
||||
script = ExtResource("1_vynft")
|
||||
|
||||
[node name="SubViewport" type="SubViewport" parent="."]
|
||||
disable_3d = true
|
||||
transparent_bg = true
|
||||
size = Vector2i(200, 70)
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="SubViewport"]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
[node name="Label" type="Label" parent="SubViewport/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
label_settings = SubResource("LabelSettings_y8qrs")
|
||||
uppercase = true
|
||||
|
||||
[node name="HealthBar" type="TextureProgressBar" parent="SubViewport/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
max_value = 1.0
|
||||
step = 0.0
|
||||
value = 1.0
|
||||
texture_progress = ExtResource("2_ad7qf")
|
||||
script = ExtResource("3_61bgt")
|
||||
high = ExtResource("2_ad7qf")
|
||||
medium = ExtResource("4_5dl20")
|
||||
low = ExtResource("5_3x8xp")
|
21
client/player/hud/HealthBar.gd
Normal file
21
client/player/hud/HealthBar.gd
Normal file
@ -0,0 +1,21 @@
|
||||
extends TextureProgressBar
|
||||
|
||||
@export var high: Texture2D
|
||||
@export var medium: Texture2D
|
||||
@export var low: Texture2D
|
||||
|
||||
var health: HealthComponent
|
||||
|
||||
func _ready():
|
||||
health = owner.health
|
||||
health.value_changed.connect(on_health_changed)
|
||||
|
||||
func on_health_changed():
|
||||
value = health.value / health.max_value
|
||||
|
||||
if value < 0.45:
|
||||
texture_progress = low
|
||||
elif value < 0.75:
|
||||
texture_progress = medium
|
||||
else:
|
||||
texture_progress = high
|
@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://x102pryt2s5a"]
|
||||
|
||||
[ext_resource type="Script" path="res://character/movement/MovementComponent.gd" id="1_2gnmd"]
|
||||
[ext_resource type="Script" path="res://player/movement/MovementComponent.gd" id="1_2gnmd"]
|
||||
|
||||
[node name="Movement" type="Node"]
|
||||
script = ExtResource("1_2gnmd")
|
@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://d0onbq0ad1ap4"]
|
||||
|
||||
[ext_resource type="Script" path="res://character/rotation/RotationComponent.gd" id="1_j1874"]
|
||||
[ext_resource type="Script" path="res://player/rotation/RotationComponent.gd" id="1_j1874"]
|
||||
|
||||
[node name="Rotation" type="Node"]
|
||||
script = ExtResource("1_j1874")
|
11
client/player/skills/SkillsComponent.gd
Normal file
11
client/player/skills/SkillsComponent.gd
Normal file
@ -0,0 +1,11 @@
|
||||
class_name SkillsComponent
|
||||
extends Node
|
||||
|
||||
var player: Player
|
||||
|
||||
func _ready():
|
||||
player = owner
|
||||
player.attacked.connect(attack)
|
||||
|
||||
func attack():
|
||||
%Health.take_damage(DamageInstance.new(10))
|
6
client/player/skills/SkillsComponent.tscn
Normal file
6
client/player/skills/SkillsComponent.tscn
Normal file
@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://b8xf4ltqyorjv"]
|
||||
|
||||
[ext_resource type="Script" path="res://player/skills/SkillsComponent.gd" id="1_016bx"]
|
||||
|
||||
[node name="Skills" type="Node"]
|
||||
script = ExtResource("1_016bx")
|
@ -83,6 +83,7 @@ attack={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":81,"key_label":0,"unicode":113,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
aim={
|
||||
|
Loading…
Reference in New Issue
Block a user