diff --git a/enemy/enemy.gd b/enemy/enemy.gd index 20e7bfd8..7f56e434 100644 --- a/enemy/enemy.gd +++ b/enemy/enemy.gd @@ -4,10 +4,16 @@ class_name Enemy extends CharacterBody2D +signal health_changed + @export var max_health: int = 3 @export var damage : int = 1 @export var knockback_force : int = 600 -@onready var health := max_health +@onready var health := max_health : + set(value): + health = value + health_changed.emit() + # the max distance the entity will move from its starting position, aka that radius of the circle that the entity is allowed to move in @export var roaming_radius : float = 100 diff --git a/test_scenes/bossHealthBar_Test.tscn b/test_scenes/bossHealthBar_Test.tscn new file mode 100644 index 00000000..4d2ccdbd --- /dev/null +++ b/test_scenes/bossHealthBar_Test.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=4 format=3 uid="uid://c1knmn0ca34tb"] + +[ext_resource type="PackedScene" uid="uid://uj2rytnj1h4" path="res://enemy/test_enemy/test_enemy.tscn" id="1_dhsl4"] +[ext_resource type="PackedScene" uid="uid://cexm5ohj0j67i" path="res://ui/boss_health_bar/boss_health_bar.tscn" id="2_8qhgu"] +[ext_resource type="PackedScene" uid="uid://c7ck7ril2jix2" path="res://player/player.tscn" id="3_f2xhf"] + +[node name="BossHealthBarTest" type="Node2D"] +top_level = true + +[node name="TestEnemy" parent="." instance=ExtResource("1_dhsl4")] +position = Vector2(552, 306) + +[node name="BossHealthBar" parent="TestEnemy" node_paths=PackedStringArray("boss") instance=ExtResource("2_8qhgu")] +boss = NodePath("..") + +[node name="Player" parent="." instance=ExtResource("3_f2xhf")] +position = Vector2(889, 312) diff --git a/ui/boss_health_bar/boss_health_bar.gd b/ui/boss_health_bar/boss_health_bar.gd new file mode 100644 index 00000000..43e1daa3 --- /dev/null +++ b/ui/boss_health_bar/boss_health_bar.gd @@ -0,0 +1,23 @@ +extends CanvasLayer + +#Grab Enemy +@onready var progress_bar: ProgressBar = %ProgressBar +@export var boss : Enemy +#grab value + +func _on_boss_health_changed() -> void: + progress_bar.value = boss.health + +func _ready() -> void: + progress_bar.max_value = boss.max_health + progress_bar.value = boss.max_health + boss.health_changed.connect(_on_boss_health_changed) + +func _process(_delta: float) -> void: + if boss == null: + queue_free() + is_queued_for_deletion() + +#on value change + +#reset value to enemy health diff --git a/ui/boss_health_bar/boss_health_bar.tscn b/ui/boss_health_bar/boss_health_bar.tscn new file mode 100644 index 00000000..e61e2f1e --- /dev/null +++ b/ui/boss_health_bar/boss_health_bar.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=2 format=3 uid="uid://cexm5ohj0j67i"] + +[ext_resource type="Script" path="res://ui/boss_health_bar/boss_health_bar.gd" id="1_6gdbd"] + +[node name="BossHealthBar" type="CanvasLayer"] +script = ExtResource("1_6gdbd") + +[node name="ProgressBar" type="ProgressBar" parent="."] +unique_name_in_owner = true +anchors_preset = 5 +anchor_left = 0.5 +anchor_right = 0.5 +offset_left = -386.5 +offset_right = 386.5 +offset_bottom = 70.0 +grow_horizontal = 2 +show_percentage = false diff --git a/ui/options/options_menu.tscn b/ui/options/options_menu.tscn index d53fd825..8c7d9f5a 100644 --- a/ui/options/options_menu.tscn +++ b/ui/options/options_menu.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=5 format=3 uid="uid://dflfvpjufhfln"] +[gd_scene load_steps=5 format=3 uid="uid://bovhexq6t5u8o"] [ext_resource type="Script" path="res://ui/options/options_menu.gd" id="1_1bpan"] [ext_resource type="Theme" uid="uid://drqtpgod2pibc" path="res://ui/main_ui_theme.tres" id="1_eq1l6"]