Demo fixes

This commit is contained in:
Serhii Snitsaruk 2024-02-04 13:25:35 +01:00
parent 065b6dc29b
commit 73152b5760
7 changed files with 212 additions and 74 deletions

View File

@ -2,7 +2,7 @@
[ext_resource type="PackedScene" uid="uid://ooigbfhfy4wa" path="res://demo/agents/agent_base.tscn" id="1_afx5l"]
[ext_resource type="Texture2D" uid="uid://usu3j55d6dgc" path="res://demo/assets/agent_melee_nuanced.png" id="2_e51r0"]
[ext_resource type="BehaviorTree" uid="uid://c2u6sljqkim0n" path="res://demo/ai/trees/enemy_melee_nuanced.tres" id="3_b8kcf"]
[ext_resource type="BehaviorTree" uid="uid://c2u6sljqkim0n" path="res://demo/ai/trees/03_agent_melee_nuanced.tres" id="3_b8kcf"]
[sub_resource type="BlackboardPlan" id="BlackboardPlan_tnf02"]
var/speed/name = "speed"

View File

@ -51,6 +51,11 @@ texture = ExtResource("2_2rj5a")
position = Vector2(0, -93)
texture = ExtResource("1_ptof7")
[node name="RemoteTransform2D" type="RemoteTransform2D" parent="Root/NinjaStar"]
remote_path = NodePath("../../../Death")
update_rotation = false
update_scale = false
[node name="Hitbox" type="Area2D" parent="."]
collision_layer = 0
collision_mask = 4
@ -61,6 +66,7 @@ shape = SubResource("CircleShape2D_7uc1b")
debug_color = Color(0.839216, 0.192157, 0.815686, 0.419608)
[node name="Death" type="GPUParticles2D" parent="."]
position = Vector2(0, -93)
emitting = false
amount = 1
process_material = SubResource("ParticleProcessMaterial_gilhy")

View File

@ -28,7 +28,7 @@ var _is_dead: bool = false
func _ready() -> void:
health.damaged.connect(_damaged)
health.death.connect(_die)
health.death.connect(die)
func update_facing() -> void:
@ -111,7 +111,7 @@ func apply_knockback(knockback: Vector2, frames: int = 10) -> void:
await get_tree().physics_frame
func _die() -> void:
func die() -> void:
_is_dead = true
root.process_mode = Node.PROCESS_MODE_DISABLED
animation_player.play(&"death")

View File

@ -1,10 +1,10 @@
[gd_resource type="BehaviorTree" load_steps=41 format=3 uid="uid://c2u6sljqkim0n"]
[gd_resource type="BehaviorTree" load_steps=45 format=3 uid="uid://c2u6sljqkim0n"]
[ext_resource type="Script" path="res://demo/ai/tasks/get_first_in_group.gd" id="1_uvue5"]
[ext_resource type="Script" path="res://demo/ai/tasks/pursue.gd" id="2_aanv5"]
[ext_resource type="Script" path="res://demo/ai/tasks/select_flanking_pos.gd" id="2_fl3fr"]
[ext_resource type="Script" path="res://demo/ai/tasks/face_target.gd" id="3_r5itf"]
[ext_resource type="Script" path="res://demo/ai/tasks/arrive_pos.gd" id="3_x6gkn"]
[ext_resource type="Script" path="res://demo/ai/tasks/get_first_in_group.gd" id="1_08fik"]
[ext_resource type="Script" path="res://demo/ai/tasks/select_flanking_pos.gd" id="2_te3yo"]
[ext_resource type="Script" path="res://demo/ai/tasks/arrive_pos.gd" id="3_svwk8"]
[ext_resource type="Script" path="res://demo/ai/tasks/face_target.gd" id="4_mvsyw"]
[ext_resource type="Script" path="res://demo/ai/tasks/pursue.gd" id="5_r1ou0"]
[sub_resource type="BlackboardPlan" id="BlackboardPlan_46tbn"]
var/speed/name = "speed"
@ -31,9 +31,9 @@ blend = 0.1
max_duration = 3.0
[sub_resource type="BTAction" id="BTAction_c4cxo"]
script = ExtResource("1_uvue5")
script = ExtResource("1_08fik")
group = &"player"
output_var = "_target"
output_var = "target"
[sub_resource type="BTSequence" id="BTSequence_yhjh1"]
custom_name = "Pause before action"
@ -50,17 +50,17 @@ blend = 0.1
speed = 1.5
[sub_resource type="BTAction" id="BTAction_6e48s"]
script = ExtResource("2_fl3fr")
target_var = "_target"
script = ExtResource("2_te3yo")
target_var = "target"
closest_side = false
flank_side = 1
range_min = 400
range_max = 600
position_var = "_flank_pos"
position_var = "flank_pos"
[sub_resource type="BTAction" id="BTAction_66hsk"]
script = ExtResource("3_x6gkn")
target_position_var = "_flank_pos"
script = ExtResource("3_svwk8")
target_position_var = "flank_pos"
speed_var = "flank_speed"
tolerance = 50.0
@ -68,8 +68,8 @@ tolerance = 50.0
children = [SubResource("BTAction_66hsk")]
[sub_resource type="BTAction" id="BTAction_enw2m"]
script = ExtResource("3_r5itf")
target_var = "_target"
script = ExtResource("4_mvsyw")
target_var = "target"
[sub_resource type="BTSequence" id="BTSequence_lhg7f"]
custom_name = "Flank player"
@ -91,8 +91,8 @@ animation_name = &"walk"
blend = 0.1
[sub_resource type="BTAction" id="BTAction_a4jqi"]
script = ExtResource("2_aanv5")
target_var = "_target"
script = ExtResource("5_r1ou0")
target_var = "target"
speed_var = "speed"
approach_distance = 100.0
@ -101,8 +101,8 @@ time_limit = 2.0
children = [SubResource("BTAction_a4jqi")]
[sub_resource type="BTAction" id="BTAction_kidxn"]
script = ExtResource("3_r5itf")
target_var = "_target"
script = ExtResource("4_mvsyw")
target_var = "target"
[sub_resource type="BTWait" id="BTWait_tadkc"]
duration = 0.1
@ -119,11 +119,35 @@ animation_name = &"attack_3"
[sub_resource type="BTSequence" id="BTSequence_1xfnq"]
custom_name = "Approach and melee attack"
children = [SubResource("BTPlayAnimation_olf37"), SubResource("BTTimeLimit_xek5v"), SubResource("BTAction_kidxn"), SubResource("BTWait_tadkc"), SubResource("BTPlayAnimation_ppmxd")]
metadata/_weight_ = 3.0
metadata/_weight_ = 4.0
[sub_resource type="BTAction" id="BTAction_mf87t"]
script = ExtResource("2_te3yo")
target_var = "target"
closest_side = false
flank_side = 0
range_min = 350
range_max = 600
position_var = "pos"
[sub_resource type="BBNode" id="BBNode_cx111"]
saved_value = NodePath("AnimationPlayer")
resource_name = "AnimationPlayer"
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_mfbeu"]
animation_player = SubResource("BBNode_cx111")
animation_name = &"walk"
blend = 0.1
[sub_resource type="BTAction" id="BTAction_6nx58"]
script = ExtResource("3_svwk8")
target_position_var = "pos"
speed_var = "speed"
tolerance = 50.0
[sub_resource type="BTAction" id="BTAction_8q20y"]
script = ExtResource("3_r5itf")
target_var = "_target"
script = ExtResource("4_mvsyw")
target_var = "target"
[sub_resource type="BBNode" id="BBNode_s6vt4"]
saved_value = NodePath("AnimationPlayer")
@ -161,8 +185,8 @@ min_duration = 1.5
[sub_resource type="BTSequence" id="BTSequence_rgbq3"]
custom_name = "Throw ninja star"
children = [SubResource("BTAction_8q20y"), SubResource("BTPlayAnimation_qa8jy"), SubResource("BTWait_gbcyb"), SubResource("BTPlayAnimation_0ktds"), SubResource("BTCallMethod_yx4fk"), SubResource("BTRandomWait_2pmoe")]
metadata/_weight_ = 1.0
children = [SubResource("BTAction_mf87t"), SubResource("BTPlayAnimation_mfbeu"), SubResource("BTAction_6nx58"), SubResource("BTAction_8q20y"), SubResource("BTPlayAnimation_qa8jy"), SubResource("BTWait_gbcyb"), SubResource("BTPlayAnimation_0ktds"), SubResource("BTCallMethod_yx4fk"), SubResource("BTRandomWait_2pmoe")]
metadata/_weight_ = 2.0
[sub_resource type="BTProbabilitySelector" id="BTProbabilitySelector_rjsiq"]
abort_on_failure = true

View File

@ -2,20 +2,22 @@ extends Node2D
@onready var behavior_tree_view: BehaviorTreeView = %BehaviorTreeView
@onready var camera: Camera2D = $Camera2D
@onready var resource_name: Label = $CanvasLayer/ResourceName
@onready var resource_name: Label = %ResourceName
@onready var agent_selection: MenuButton = %AgentSelection
@onready var previous: Button = %Previous
@onready var next: Button = %Next
var bt_player: BTPlayer
var selected_tree_index: int = -1
var agent_files: Array[String]
func _ready() -> void:
var agent: CharacterBody2D
for child in get_children():
if child is CharacterBody2D:
bt_player = child.find_child("BTPlayer")
if bt_player != null:
agent = child
resource_name.text = bt_player.behavior_tree.resource_path.get_file()
break
_attach_camera(agent)
_populate_agent_files()
_on_agent_selection_id_pressed(0)
agent_selection.get_popup().id_pressed.connect(_on_agent_selection_id_pressed)
previous.pressed.connect(func(): _on_agent_selection_id_pressed(selected_tree_index - 1))
next.pressed.connect(func(): _on_agent_selection_id_pressed(selected_tree_index + 1))
func _physics_process(_delta: float) -> void:
@ -29,3 +31,51 @@ func _attach_camera(agent: CharacterBody2D) -> void:
camera.get_parent().remove_child(camera)
agent.add_child(camera)
camera.position = Vector2(400.0, 0.0)
func _populate_agent_files() -> void:
var popup: PopupMenu = agent_selection.get_popup()
popup.clear()
popup.reset_size()
agent_files.clear()
var dir := DirAccess.open("res://demo/agents/")
if dir:
dir.list_dir_begin()
var file_name: String = dir.get_next()
while file_name != "":
if dir.current_is_dir() or file_name.begins_with("agent_base"):
file_name = dir.get_next()
continue
agent_files.append(file_name.get_file())
file_name = dir.get_next()
dir.list_dir_end()
agent_files.sort()
for i in agent_files.size():
popup.add_item(agent_files[i], i)
func _load_agent(file_name: String) -> void:
var agent_res := load(file_name) as PackedScene
assert(agent_res != null)
for child in get_children():
if child is CharacterBody2D and child.name != "Dummy":
child.die()
var agent: CharacterBody2D = agent_res.instantiate()
add_child(agent)
bt_player = agent.find_child("BTPlayer")
_attach_camera(agent)
resource_name.text = bt_player.behavior_tree.resource_path.get_file()
func _on_agent_selection_id_pressed(id: int) -> void:
assert(id >= 0 and id < agent_files.size())
selected_tree_index = id
_load_agent("res://demo/agents/".path_join(agent_files[id]))
agent_selection.text = bt_player.behavior_tree.resource_path.get_file()
previous.disabled = id == 0
next.disabled = id == 8

View File

@ -1,13 +1,18 @@
[gd_scene load_steps=11 format=3 uid="uid://b3ae14mc2ty3y"]
[gd_scene load_steps=10 format=3 uid="uid://b3ae14mc2ty3y"]
[ext_resource type="Script" path="res://demo/scenes/agent_showcase.gd" id="1_frr2n"]
[ext_resource type="Theme" uid="uid://boqtjf88xcpu4" path="res://demo/assets/behavior_tree_view.theme" id="2_hb4lh"]
[ext_resource type="Theme" uid="uid://boqtjf88xcpu4" path="res://demo/assets/ui.theme" id="2_hb4lh"]
[ext_resource type="Texture2D" uid="uid://tyu0ua1ju38l" path="res://demo/assets/logo.png" id="3_v6wtt"]
[ext_resource type="FontFile" uid="uid://d25vkmce7mhlt" path="res://demo/assets/fonts/knewave_regular.ttf" id="4_tju7a"]
[ext_resource type="FontFile" uid="uid://n231m6uqsq6x" path="res://demo/assets/fonts/junction_bold.otf" id="5_0fprc"]
[ext_resource type="PackedScene" uid="uid://bsig1usigbbuy" path="res://demo/scenes/arena.tscn" id="6_6awy2"]
[ext_resource type="PackedScene" uid="uid://c5fhe3tulhlco" path="res://demo/props/dummy.tscn" id="7_ao7an"]
[ext_resource type="PackedScene" uid="uid://ci3x5esepbu5v" path="res://demo/agents/agent_ranged.tscn" id="8_bfg8u"]
[sub_resource type="LabelSettings" id="LabelSettings_3uhve"]
font = ExtResource("4_tju7a")
font_size = 29
outline_size = 10
outline_color = Color(0.145083, 0.168536, 0.203708, 1)
[sub_resource type="LabelSettings" id="LabelSettings_la4ui"]
font = ExtResource("4_tju7a")
@ -16,30 +21,101 @@ font_color = Color(1, 1, 0.239216, 1)
outline_size = 20
outline_color = Color(0.211521, 0.23888, 0.290166, 1)
[sub_resource type="LabelSettings" id="LabelSettings_3uhve"]
font = ExtResource("5_0fprc")
font_size = 38
outline_size = 20
outline_color = Color(0.0784314, 0.0941176, 0.117647, 1)
[node name="AgentShowcase" type="Node2D"]
y_sort_enabled = true
script = ExtResource("1_frr2n")
metadata/_edit_horizontal_guides_ = [1019.0]
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="UI Layer" type="CanvasLayer" parent="."]
[node name="BehaviorTreeView" type="BehaviorTreeView" parent="CanvasLayer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(600, 0)
offset_left = 1320.0
offset_right = 1920.0
offset_bottom = 1080.0
grow_horizontal = 0
[node name="Control" type="Control" parent="UI Layer"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("2_hb4lh")
[node name="Logo" type="TextureRect" parent="CanvasLayer"]
[node name="Panel" type="Panel" parent="UI Layer/Control"]
custom_minimum_size = Vector2(600, 0)
layout_mode = 1
anchors_preset = 11
anchor_left = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -600.0
grow_horizontal = 0
grow_vertical = 2
[node name="ClickToSelect" type="Label" parent="UI Layer/Control"]
unique_name_in_owner = true
layout_mode = 2
offset_left = 992.0
offset_top = -2.0
offset_right = 1305.0
offset_bottom = 52.0
text = "Select Agent ➤"
label_settings = SubResource("LabelSettings_3uhve")
horizontal_alignment = 2
vertical_alignment = 1
[node name="VBoxContainer" type="VBoxContainer" parent="UI Layer/Control"]
custom_minimum_size = Vector2(600, 0)
layout_mode = 1
anchors_preset = 11
anchor_left = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 0
grow_vertical = 2
theme_override_constants/separation = 0
[node name="HBoxContainer" type="HBoxContainer" parent="UI Layer/Control/VBoxContainer"]
layout_mode = 2
[node name="Previous" type="Button" parent="UI Layer/Control/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
focus_mode = 0
theme_override_font_sizes/font_size = 28
text = "⬅"
[node name="AgentSelection" type="MenuButton" parent="UI Layer/Control/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(400, 50)
layout_mode = 2
size_flags_horizontal = 3
theme_override_fonts/font = ExtResource("5_0fprc")
theme_override_font_sizes/font_size = 30
text = "02_agent_imp.tres
"
flat = false
[node name="Next" type="Button" parent="UI Layer/Control/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
focus_mode = 0
theme_override_font_sizes/font_size = 28
text = "➡"
[node name="ResourceName" type="Label" parent="UI Layer/Control/VBoxContainer"]
unique_name_in_owner = true
visible = false
layout_mode = 2
text = "o2_agent_imp.tres"
label_settings = SubResource("LabelSettings_3uhve")
horizontal_alignment = 2
vertical_alignment = 1
[node name="BehaviorTreeView" type="BehaviorTreeView" parent="UI Layer/Control/VBoxContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(600, 0)
layout_mode = 2
size_flags_vertical = 3
[node name="Logo" type="TextureRect" parent="UI Layer/Control"]
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
@ -53,7 +129,7 @@ grow_horizontal = 0
grow_vertical = 0
texture = ExtResource("3_v6wtt")
[node name="Demo project" type="Label" parent="CanvasLayer/Logo"]
[node name="Demo project" type="Label" parent="UI Layer/Control/Logo"]
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
@ -71,22 +147,6 @@ label_settings = SubResource("LabelSettings_la4ui")
horizontal_alignment = 2
vertical_alignment = 1
[node name="ResourceName" type="Label" parent="CanvasLayer"]
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -230.0
offset_top = -146.0
offset_right = -29.0
grow_horizontal = 0
grow_vertical = 0
text = "o2_agent_imp.tres"
label_settings = SubResource("LabelSettings_3uhve")
horizontal_alignment = 2
vertical_alignment = 1
[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2(400, 0)
zoom = Vector2(0.88, 0.88)
@ -104,5 +164,3 @@ metadata/_edit_lock_ = true
[node name="Dummy" parent="." instance=ExtResource("7_ao7an")]
position = Vector2(1106, 423)
[node name="AgentRanged" parent="." instance=ExtResource("8_bfg8u")]