Skip to content

Commit 552ffcb

Browse files
committed
feat(boss): make boss to die
1 parent 4c28254 commit 552ffcb

File tree

6 files changed

+298
-16
lines changed

6 files changed

+298
-16
lines changed

objects/actors/mob/boss/Boss.gd

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ class_name Boss extends Mob
44

55
@onready var states: States = $States
66
@onready var follow: Follow = $States/Follow
7+
@onready var death: Death = $States/Death
8+
9+
@onready var health_bar: HealthBar = %HealthBar
710

811
var players: Array[Player] = []
912

10-
func _ready() -> void:
13+
func _ready():
14+
health_bar.init(_currentHealth)
1115
for node in players_node.get_children():
1216
if node is Player:
1317
players.push_back(node)
@@ -28,3 +32,11 @@ func _sort_by_distance(a: Node2D, b: Node2D) -> bool:
2832
func _update_animation() -> void:
2933
if states.current_state == follow:
3034
super._update_animation()
35+
36+
func _on_hit():
37+
super._on_hit()
38+
health_bar.value = _currentHealth
39+
40+
func _on_death() -> void:
41+
super._on_death()
42+
states.change_state(death)

objects/actors/mob/boss/Boss.tscn

Lines changed: 261 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
[gd_scene load_steps=83 format=3 uid="uid://1562kt6mf0l3"]
1+
[gd_scene load_steps=117 format=3 uid="uid://1562kt6mf0l3"]
22

33
[ext_resource type="PackedScene" uid="uid://b3y0j0iqfou0u" path="res://objects/actors/mob/Mob.tscn" id="1_iq4jn"]
44
[ext_resource type="Script" path="res://objects/actors/mob/boss/Boss.gd" id="2_mafjq"]
55
[ext_resource type="Texture2D" uid="uid://bp8jwo7r325f3" path="res://objects/actors/mob/boss/orc3_idle_full.png" id="3_8kdme"]
66
[ext_resource type="Texture2D" uid="uid://qbbjae54gdb0" path="res://objects/actors/mob/boss/orc3_attack_full.png" id="3_20ajd"]
77
[ext_resource type="Texture2D" uid="uid://cplvqkhq4h17s" path="res://objects/actors/mob/boss/orc3_run_full.png" id="4_cnqb0"]
8+
[ext_resource type="Texture2D" uid="uid://bmsxlhdgv75v7" path="res://objects/actors/mob/boss/orc3_death_full.png" id="4_snvho"]
89
[ext_resource type="Script" path="res://objects/actors/mob/boss/states/States.gd" id="5_8xxkf"]
9-
[ext_resource type="Script" path="res://objects/actors/mob/boss/states/State.gd" id="5_mshb6"]
1010
[ext_resource type="Script" path="res://objects/actors/mob/boss/states/Idle.gd" id="6_mfoa0"]
1111
[ext_resource type="Script" path="res://objects/actors/mob/boss/states/Follow.gd" id="7_h0hef"]
12+
[ext_resource type="PackedScene" uid="uid://c5w6dv2r65qsd" path="res://objects/hud/HealthBar.tscn" id="7_sphy2"]
1213
[ext_resource type="Script" path="res://objects/actors/mob/boss/states/Attack.gd" id="8_n2euq"]
1314
[ext_resource type="Script" path="res://objects/actors/mob/boss/SpawnMob.gd" id="10_ogdny"]
15+
[ext_resource type="Script" path="res://objects/actors/mob/boss/states/Death.gd" id="11_om2e5"]
1416

1517
[sub_resource type="AtlasTexture" id="AtlasTexture_s7elu"]
1618
atlas = ExtResource("3_20ajd")
@@ -140,6 +142,134 @@ region = Rect2(385, 65, 63, 63)
140142
atlas = ExtResource("3_20ajd")
141143
region = Rect2(449, 65, 63, 63)
142144

145+
[sub_resource type="AtlasTexture" id="AtlasTexture_25nr3"]
146+
atlas = ExtResource("4_snvho")
147+
region = Rect2(0, 0, 62, 62)
148+
149+
[sub_resource type="AtlasTexture" id="AtlasTexture_oue50"]
150+
atlas = ExtResource("4_snvho")
151+
region = Rect2(64, 0, 62, 62)
152+
153+
[sub_resource type="AtlasTexture" id="AtlasTexture_hvlk4"]
154+
atlas = ExtResource("4_snvho")
155+
region = Rect2(128, 0, 62, 62)
156+
157+
[sub_resource type="AtlasTexture" id="AtlasTexture_4e6b2"]
158+
atlas = ExtResource("4_snvho")
159+
region = Rect2(192, 0, 62, 62)
160+
161+
[sub_resource type="AtlasTexture" id="AtlasTexture_78rkf"]
162+
atlas = ExtResource("4_snvho")
163+
region = Rect2(256, 0, 62, 62)
164+
165+
[sub_resource type="AtlasTexture" id="AtlasTexture_gfl0r"]
166+
atlas = ExtResource("4_snvho")
167+
region = Rect2(320, 0, 62, 62)
168+
169+
[sub_resource type="AtlasTexture" id="AtlasTexture_vt5o7"]
170+
atlas = ExtResource("4_snvho")
171+
region = Rect2(384, 0, 62, 62)
172+
173+
[sub_resource type="AtlasTexture" id="AtlasTexture_q3gm1"]
174+
atlas = ExtResource("4_snvho")
175+
region = Rect2(448, 0, 62, 62)
176+
177+
[sub_resource type="AtlasTexture" id="AtlasTexture_gn5kp"]
178+
atlas = ExtResource("4_snvho")
179+
region = Rect2(0, 128, 62, 62)
180+
181+
[sub_resource type="AtlasTexture" id="AtlasTexture_8tvv0"]
182+
atlas = ExtResource("4_snvho")
183+
region = Rect2(64, 128, 62, 62)
184+
185+
[sub_resource type="AtlasTexture" id="AtlasTexture_5u1il"]
186+
atlas = ExtResource("4_snvho")
187+
region = Rect2(128, 128, 62, 62)
188+
189+
[sub_resource type="AtlasTexture" id="AtlasTexture_eswkw"]
190+
atlas = ExtResource("4_snvho")
191+
region = Rect2(192, 128, 62, 62)
192+
193+
[sub_resource type="AtlasTexture" id="AtlasTexture_h3tvp"]
194+
atlas = ExtResource("4_snvho")
195+
region = Rect2(256, 128, 62, 62)
196+
197+
[sub_resource type="AtlasTexture" id="AtlasTexture_j2mpj"]
198+
atlas = ExtResource("4_snvho")
199+
region = Rect2(320, 128, 62, 62)
200+
201+
[sub_resource type="AtlasTexture" id="AtlasTexture_ihtcj"]
202+
atlas = ExtResource("4_snvho")
203+
region = Rect2(384, 128, 62, 62)
204+
205+
[sub_resource type="AtlasTexture" id="AtlasTexture_rfbs0"]
206+
atlas = ExtResource("4_snvho")
207+
region = Rect2(448, 128, 62, 62)
208+
209+
[sub_resource type="AtlasTexture" id="AtlasTexture_06t1s"]
210+
atlas = ExtResource("4_snvho")
211+
region = Rect2(0, 192, 62, 62)
212+
213+
[sub_resource type="AtlasTexture" id="AtlasTexture_lt2p8"]
214+
atlas = ExtResource("4_snvho")
215+
region = Rect2(64, 192, 62, 62)
216+
217+
[sub_resource type="AtlasTexture" id="AtlasTexture_ple2h"]
218+
atlas = ExtResource("4_snvho")
219+
region = Rect2(128, 192, 62, 62)
220+
221+
[sub_resource type="AtlasTexture" id="AtlasTexture_eenp4"]
222+
atlas = ExtResource("4_snvho")
223+
region = Rect2(192, 192, 62, 62)
224+
225+
[sub_resource type="AtlasTexture" id="AtlasTexture_dk3u7"]
226+
atlas = ExtResource("4_snvho")
227+
region = Rect2(256, 192, 62, 62)
228+
229+
[sub_resource type="AtlasTexture" id="AtlasTexture_tpnq3"]
230+
atlas = ExtResource("4_snvho")
231+
region = Rect2(320, 192, 62, 62)
232+
233+
[sub_resource type="AtlasTexture" id="AtlasTexture_upmsq"]
234+
atlas = ExtResource("4_snvho")
235+
region = Rect2(384, 192, 62, 62)
236+
237+
[sub_resource type="AtlasTexture" id="AtlasTexture_bi5qo"]
238+
atlas = ExtResource("4_snvho")
239+
region = Rect2(448, 192, 62, 62)
240+
241+
[sub_resource type="AtlasTexture" id="AtlasTexture_lcfwe"]
242+
atlas = ExtResource("4_snvho")
243+
region = Rect2(0, 64, 62, 62)
244+
245+
[sub_resource type="AtlasTexture" id="AtlasTexture_l1apq"]
246+
atlas = ExtResource("4_snvho")
247+
region = Rect2(64, 64, 62, 62)
248+
249+
[sub_resource type="AtlasTexture" id="AtlasTexture_qy3yc"]
250+
atlas = ExtResource("4_snvho")
251+
region = Rect2(128, 64, 62, 62)
252+
253+
[sub_resource type="AtlasTexture" id="AtlasTexture_qjmm0"]
254+
atlas = ExtResource("4_snvho")
255+
region = Rect2(192, 64, 62, 62)
256+
257+
[sub_resource type="AtlasTexture" id="AtlasTexture_cll38"]
258+
atlas = ExtResource("4_snvho")
259+
region = Rect2(256, 64, 62, 62)
260+
261+
[sub_resource type="AtlasTexture" id="AtlasTexture_14vlg"]
262+
atlas = ExtResource("4_snvho")
263+
region = Rect2(320, 64, 62, 62)
264+
265+
[sub_resource type="AtlasTexture" id="AtlasTexture_1rg2f"]
266+
atlas = ExtResource("4_snvho")
267+
region = Rect2(384, 64, 62, 62)
268+
269+
[sub_resource type="AtlasTexture" id="AtlasTexture_6xgca"]
270+
atlas = ExtResource("4_snvho")
271+
region = Rect2(448, 64, 62, 62)
272+
143273
[sub_resource type="AtlasTexture" id="AtlasTexture_5mojw"]
144274
atlas = ExtResource("3_8kdme")
145275
region = Rect2(0, 0, 62, 62)
@@ -404,6 +534,122 @@ animations = [{
404534
}, {
405535
"frames": [{
406536
"duration": 1.0,
537+
"texture": SubResource("AtlasTexture_25nr3")
538+
}, {
539+
"duration": 1.0,
540+
"texture": SubResource("AtlasTexture_oue50")
541+
}, {
542+
"duration": 1.0,
543+
"texture": SubResource("AtlasTexture_hvlk4")
544+
}, {
545+
"duration": 1.0,
546+
"texture": SubResource("AtlasTexture_4e6b2")
547+
}, {
548+
"duration": 1.0,
549+
"texture": SubResource("AtlasTexture_78rkf")
550+
}, {
551+
"duration": 1.0,
552+
"texture": SubResource("AtlasTexture_gfl0r")
553+
}, {
554+
"duration": 1.0,
555+
"texture": SubResource("AtlasTexture_vt5o7")
556+
}, {
557+
"duration": 1.0,
558+
"texture": SubResource("AtlasTexture_q3gm1")
559+
}],
560+
"loop": false,
561+
"name": &"DeathDown",
562+
"speed": 5.0
563+
}, {
564+
"frames": [{
565+
"duration": 1.0,
566+
"texture": SubResource("AtlasTexture_gn5kp")
567+
}, {
568+
"duration": 1.0,
569+
"texture": SubResource("AtlasTexture_8tvv0")
570+
}, {
571+
"duration": 1.0,
572+
"texture": SubResource("AtlasTexture_5u1il")
573+
}, {
574+
"duration": 1.0,
575+
"texture": SubResource("AtlasTexture_eswkw")
576+
}, {
577+
"duration": 1.0,
578+
"texture": SubResource("AtlasTexture_h3tvp")
579+
}, {
580+
"duration": 1.0,
581+
"texture": SubResource("AtlasTexture_j2mpj")
582+
}, {
583+
"duration": 1.0,
584+
"texture": SubResource("AtlasTexture_ihtcj")
585+
}, {
586+
"duration": 1.0,
587+
"texture": SubResource("AtlasTexture_rfbs0")
588+
}],
589+
"loop": false,
590+
"name": &"DeathLeft",
591+
"speed": 5.0
592+
}, {
593+
"frames": [{
594+
"duration": 1.0,
595+
"texture": SubResource("AtlasTexture_06t1s")
596+
}, {
597+
"duration": 1.0,
598+
"texture": SubResource("AtlasTexture_lt2p8")
599+
}, {
600+
"duration": 1.0,
601+
"texture": SubResource("AtlasTexture_ple2h")
602+
}, {
603+
"duration": 1.0,
604+
"texture": SubResource("AtlasTexture_eenp4")
605+
}, {
606+
"duration": 1.0,
607+
"texture": SubResource("AtlasTexture_dk3u7")
608+
}, {
609+
"duration": 1.0,
610+
"texture": SubResource("AtlasTexture_tpnq3")
611+
}, {
612+
"duration": 1.0,
613+
"texture": SubResource("AtlasTexture_upmsq")
614+
}, {
615+
"duration": 1.0,
616+
"texture": SubResource("AtlasTexture_bi5qo")
617+
}],
618+
"loop": false,
619+
"name": &"DeathRight",
620+
"speed": 5.0
621+
}, {
622+
"frames": [{
623+
"duration": 1.0,
624+
"texture": SubResource("AtlasTexture_lcfwe")
625+
}, {
626+
"duration": 1.0,
627+
"texture": SubResource("AtlasTexture_l1apq")
628+
}, {
629+
"duration": 1.0,
630+
"texture": SubResource("AtlasTexture_qy3yc")
631+
}, {
632+
"duration": 1.0,
633+
"texture": SubResource("AtlasTexture_qjmm0")
634+
}, {
635+
"duration": 1.0,
636+
"texture": SubResource("AtlasTexture_cll38")
637+
}, {
638+
"duration": 1.0,
639+
"texture": SubResource("AtlasTexture_14vlg")
640+
}, {
641+
"duration": 1.0,
642+
"texture": SubResource("AtlasTexture_1rg2f")
643+
}, {
644+
"duration": 1.0,
645+
"texture": SubResource("AtlasTexture_6xgca")
646+
}],
647+
"loop": false,
648+
"name": &"DeathUp",
649+
"speed": 5.0
650+
}, {
651+
"frames": [{
652+
"duration": 1.0,
407653
"texture": SubResource("AtlasTexture_5mojw")
408654
}, {
409655
"duration": 1.0,
@@ -547,6 +793,8 @@ collision_layer = 2
547793
collision_mask = 5
548794
script = ExtResource("2_mafjq")
549795
_speed = 150.0
796+
_maxHealth = 200.0
797+
_currentHealth = 200.0
550798

551799
[node name="AnimatedSprite" parent="." index="0"]
552800
position = Vector2(0, 4)
@@ -576,15 +824,22 @@ horizontal_alignment = 1
576824
vertical_alignment = 1
577825
metadata/_edit_use_anchors_ = true
578826

579-
[node name="DetectionArea" type="Area2D" parent="." index="3"]
827+
[node name="HealthBar" parent="." index="3" instance=ExtResource("7_sphy2")]
828+
unique_name_in_owner = true
829+
offset_left = -27.0
830+
offset_top = -23.0
831+
offset_right = 84.0
832+
offset_bottom = -12.0
833+
834+
[node name="DetectionArea" type="Area2D" parent="." index="4"]
580835
unique_name_in_owner = true
581836
collision_layer = 0
582837

583838
[node name="CollisionShape2D" type="CollisionShape2D" parent="DetectionArea" index="0"]
584839
shape = SubResource("CircleShape2D_fyh5s")
585840
debug_color = Color(0, 1, 0, 0.419608)
586841

587-
[node name="Minions" type="Node2D" parent="." index="4"]
842+
[node name="Minions" type="Node2D" parent="." index="5"]
588843
unique_name_in_owner = true
589844

590845
[node name="Spanw1" type="Marker2D" parent="Minions" index="0"]
@@ -596,7 +851,7 @@ position = Vector2(53.4613, -14.3073)
596851
[node name="Spanw3" type="Marker2D" parent="Minions" index="2"]
597852
position = Vector2(-23.6918, 58.6978)
598853

599-
[node name="States" type="Node2D" parent="." index="5"]
854+
[node name="States" type="Node2D" parent="." index="6"]
600855
script = ExtResource("5_8xxkf")
601856

602857
[node name="Idle" type="Node2D" parent="States" index="0"]
@@ -612,6 +867,6 @@ script = ExtResource("8_n2euq")
612867
script = ExtResource("10_ogdny")
613868

614869
[node name="Death" type="Node2D" parent="States" index="4"]
615-
script = ExtResource("5_mshb6")
870+
script = ExtResource("11_om2e5")
616871

617872
[connection signal="body_entered" from="DetectionArea" to="States/Idle" method="_on_body_detected"]

objects/actors/mob/boss/states/Attack.gd

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,31 @@ class_name Attack extends State
77
@onready var idle: Idle = $"../Idle"
88
@onready var spawn_mob: SpawnMob = $"../SpawnMob"
99

10+
var _is_attacking := false
11+
1012
func enter() -> void:
1113
super.enter()
14+
_is_attacking = true
1215
attack()
1316

17+
func exit() -> void:
18+
super.exit()
19+
_is_attacking = false
20+
1421
func attack() -> void:
1522
var direction = _boss._direction_name()
1623
animated_sprite.play("Attack" + direction)
1724
await animated_sprite.animation_finished
18-
attack()
25+
if _is_attacking:
26+
attack()
1927

2028
func transition() -> void:
2129
super.transition()
2230
var player = _boss.get_targeted_player()
2331
if not player:
2432
states.change_state(idle)
2533
return
26-
34+
2735
var distance_to_player = _boss.global_position.distance_to(player.global_position)
2836
if distance_to_player > 80:
2937
if randi() % 10 < 3:

0 commit comments

Comments
 (0)