Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boss health bar #115

Merged
merged 5 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion enemy/enemy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 17 additions & 0 deletions test_scenes/bossHealthBar_Test.tscn
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 23 additions & 0 deletions ui/boss_health_bar/boss_health_bar.gd
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions ui/boss_health_bar/boss_health_bar.tscn
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion ui/options/options_menu.tscn
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down