mirror of
https://github.com/Relintai/godot-steering-ai-framework.git
synced 2024-11-10 00:52:10 +01:00
Add GUI to Pursue demo
This commit is contained in:
parent
3d50dcdb9c
commit
fc0b36ff22
30
project/demos/pursue_vs_seek/GUI.gd
Normal file
30
project/demos/pursue_vs_seek/GUI.gd
Normal file
@ -0,0 +1,30 @@
|
||||
extends MarginContainer
|
||||
|
||||
|
||||
signal linear_speed_changed(value)
|
||||
signal linear_accel_changed(value)
|
||||
|
||||
|
||||
onready var linear_speed: = $Controls/LinSpeed/LineEdit
|
||||
onready var linear_accel: = $Controls/LinAccel/LineEdit
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
linear_speed.connect("text_changed", self, "_on_LineText_linear_speed_changed")
|
||||
linear_accel.connect("text_changed", self, "_on_LineText_linear_accel_changed")
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton:
|
||||
linear_speed.release_focus()
|
||||
linear_accel.release_focus()
|
||||
|
||||
|
||||
func _on_LineText_linear_speed_changed(new_text: String) -> void:
|
||||
if new_text.is_valid_integer():
|
||||
emit_signal("linear_speed_changed", int(float(new_text)))
|
||||
|
||||
|
||||
func _on_LineText_linear_accel_changed(new_text: String) -> void:
|
||||
if new_text.is_valid_integer():
|
||||
emit_signal("linear_accel_changed", int(float(new_text)))
|
132
project/demos/pursue_vs_seek/GUI.tscn
Normal file
132
project/demos/pursue_vs_seek/GUI.tscn
Normal file
@ -0,0 +1,132 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://demos/pursue_vs_seek/GUI.gd" type="Script" id=1]
|
||||
|
||||
[node name="GUI" type="MarginContainer"]
|
||||
anchor_bottom = 1.0
|
||||
custom_constants/margin_right = 20
|
||||
custom_constants/margin_top = 20
|
||||
custom_constants/margin_left = 20
|
||||
custom_constants/margin_bottom = 20
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Controls" type="VBoxContainer" parent="."]
|
||||
margin_left = 20.0
|
||||
margin_top = 20.0
|
||||
margin_right = 241.0
|
||||
margin_bottom = 580.0
|
||||
|
||||
[node name="LinSpeed" type="HBoxContainer" parent="Controls"]
|
||||
margin_right = 221.0
|
||||
margin_bottom = 25.0
|
||||
custom_constants/separation = 10
|
||||
|
||||
[node name="Label" type="Label" parent="Controls/LinSpeed"]
|
||||
margin_right = 153.0
|
||||
margin_bottom = 25.0
|
||||
rect_min_size = Vector2( 153, 25 )
|
||||
text = "Max Linear Speed"
|
||||
valign = 1
|
||||
|
||||
[node name="LineEdit" type="LineEdit" parent="Controls/LinSpeed"]
|
||||
margin_left = 163.0
|
||||
margin_right = 221.0
|
||||
margin_bottom = 25.0
|
||||
rect_min_size = Vector2( 0, 25 )
|
||||
focus_mode = 1
|
||||
text = "200"
|
||||
context_menu_enabled = false
|
||||
shortcut_keys_enabled = false
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="LinAccel" type="HBoxContainer" parent="Controls"]
|
||||
margin_top = 29.0
|
||||
margin_right = 221.0
|
||||
margin_bottom = 54.0
|
||||
custom_constants/separation = 10
|
||||
|
||||
[node name="Label" type="Label" parent="Controls/LinAccel"]
|
||||
margin_right = 153.0
|
||||
margin_bottom = 25.0
|
||||
rect_min_size = Vector2( 153, 25 )
|
||||
text = "Max Linear Acceleration"
|
||||
valign = 1
|
||||
|
||||
[node name="LineEdit" type="LineEdit" parent="Controls/LinAccel"]
|
||||
margin_left = 163.0
|
||||
margin_right = 221.0
|
||||
margin_bottom = 25.0
|
||||
rect_min_size = Vector2( 0, 25 )
|
||||
focus_mode = 1
|
||||
text = "120"
|
||||
context_menu_enabled = false
|
||||
shortcut_keys_enabled = false
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Help" type="VBoxContainer" parent="Controls"]
|
||||
margin_top = 58.0
|
||||
margin_right = 221.0
|
||||
margin_bottom = 110.0
|
||||
|
||||
[node name="Controls" type="Label" parent="Controls/Help"]
|
||||
margin_right = 221.0
|
||||
margin_bottom = 14.0
|
||||
text = "Controls"
|
||||
|
||||
[node name="GridContainer" type="GridContainer" parent="Controls/Help"]
|
||||
margin_top = 18.0
|
||||
margin_right = 221.0
|
||||
margin_bottom = 52.0
|
||||
columns = 3
|
||||
|
||||
[node name="Sep" type="Control" parent="Controls/Help/GridContainer"]
|
||||
margin_right = 15.0
|
||||
margin_bottom = 15.0
|
||||
rect_min_size = Vector2( 15, 15 )
|
||||
|
||||
[node name="W" type="Label" parent="Controls/Help/GridContainer"]
|
||||
margin_left = 19.0
|
||||
margin_right = 34.0
|
||||
margin_bottom = 15.0
|
||||
rect_min_size = Vector2( 15, 15 )
|
||||
text = "W"
|
||||
align = 1
|
||||
|
||||
[node name="Sep2" type="Control" parent="Controls/Help/GridContainer"]
|
||||
margin_left = 38.0
|
||||
margin_right = 53.0
|
||||
margin_bottom = 15.0
|
||||
rect_min_size = Vector2( 15, 15 )
|
||||
|
||||
[node name="A" type="Label" parent="Controls/Help/GridContainer"]
|
||||
margin_top = 19.0
|
||||
margin_right = 15.0
|
||||
margin_bottom = 34.0
|
||||
rect_min_size = Vector2( 15, 15 )
|
||||
text = "A"
|
||||
align = 1
|
||||
|
||||
[node name="S" type="Label" parent="Controls/Help/GridContainer"]
|
||||
margin_left = 19.0
|
||||
margin_top = 19.0
|
||||
margin_right = 34.0
|
||||
margin_bottom = 34.0
|
||||
rect_min_size = Vector2( 15, 15 )
|
||||
text = "S"
|
||||
align = 1
|
||||
|
||||
[node name="D" type="Label" parent="Controls/Help/GridContainer"]
|
||||
margin_left = 38.0
|
||||
margin_top = 19.0
|
||||
margin_right = 53.0
|
||||
margin_bottom = 34.0
|
||||
rect_min_size = Vector2( 15, 15 )
|
||||
text = "D"
|
||||
align = 1
|
@ -1,14 +1,19 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://demos/pursue_vs_seek/Pursuer.gd" type="Script" id=1]
|
||||
[ext_resource path="res://demos/pursue_vs_seek/BoundaryManager.gd" type="Script" id=2]
|
||||
[ext_resource path="res://demos/pursue_vs_seek/Player.gd" type="Script" id=3]
|
||||
[ext_resource path="res://demos/pursue_vs_seek/GUI.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://demos/pursue_vs_seek/PursueVSSeekDemo.gd" type="Script" id=5]
|
||||
|
||||
[node name="PursueVSSeek" type="Node2D"]
|
||||
script = ExtResource( 5 )
|
||||
__meta__ = {
|
||||
"_editor_description_": "Toy demo to demonstrate the use of the Pursue contrasted to the more naive Seek steering behavior."
|
||||
}
|
||||
|
||||
[node name="GUI" parent="." instance=ExtResource( 4 )]
|
||||
|
||||
[node name="BoundaryManager" type="Node2D" parent="."]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
|
23
project/demos/pursue_vs_seek/PursueVSSeekDemo.gd
Normal file
23
project/demos/pursue_vs_seek/PursueVSSeekDemo.gd
Normal file
@ -0,0 +1,23 @@
|
||||
extends Node2D
|
||||
|
||||
|
||||
onready var _gui: = $GUI
|
||||
onready var _pursuer: = $BoundaryManager/Pursuer
|
||||
onready var _seeker: = $BoundaryManager/Seeker
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_gui.linear_speed.text = str(_pursuer.agent.max_linear_speed)
|
||||
_gui.linear_accel.text = str(_pursuer.agent.max_linear_acceleration)
|
||||
_gui.connect("linear_accel_changed", self, "_on_GUI_linear_accel_changed")
|
||||
_gui.connect("linear_speed_changed", self, "_on_GUI_linear_speed_changed")
|
||||
|
||||
|
||||
func _on_GUI_linear_accel_changed(value: int) -> void:
|
||||
_pursuer.agent.max_linear_acceleration = float(value)
|
||||
_seeker.agent.max_linear_acceleration = float(value)
|
||||
|
||||
|
||||
func _on_GUI_linear_speed_changed(value: int) -> void:
|
||||
_pursuer.agent.max_linear_speed = float(value)
|
||||
_seeker.agent.max_linear_speed = float(value)
|
@ -34,8 +34,8 @@ func _setup() -> void:
|
||||
|
||||
agent.max_angular_acceleration = 2
|
||||
agent.max_angular_speed = 5
|
||||
agent.max_linear_acceleration = 120
|
||||
agent.max_linear_speed = 200
|
||||
agent.max_linear_acceleration = 75
|
||||
agent.max_linear_speed = 125
|
||||
_update_agent()
|
||||
|
||||
|
||||
@ -51,9 +51,9 @@ func _physics_process(delta: float) -> void:
|
||||
rotation = rotation + _angular_velocity * delta
|
||||
|
||||
accel = _behavior.calculate_steering(accel)
|
||||
_linear_velocity = (
|
||||
_linear_velocity + Vector2(accel.linear.x, accel.linear.y) * delta).clamped(agent.max_linear_speed)
|
||||
_linear_velocity -= _linear_velocity * 1 * delta
|
||||
_linear_velocity += Vector2(accel.linear.x, accel.linear.y) * delta
|
||||
_linear_velocity -= _linear_velocity.normalized() * 10 * delta
|
||||
_linear_velocity = _linear_velocity.clamped(agent.max_linear_speed)
|
||||
_linear_velocity = move_and_slide(_linear_velocity)
|
||||
|
||||
_update_agent()
|
||||
|
@ -17,11 +17,11 @@ __meta__ = {
|
||||
[node name="BehaviorControls" type="VBoxContainer" parent="."]
|
||||
margin_left = 20.0
|
||||
margin_top = 20.0
|
||||
margin_right = 102.0
|
||||
margin_right = 96.0
|
||||
margin_bottom = 580.0
|
||||
|
||||
[node name="Seek" type="CheckBox" parent="BehaviorControls"]
|
||||
margin_right = 82.0
|
||||
margin_right = 76.0
|
||||
margin_bottom = 24.0
|
||||
focus_mode = 0
|
||||
pressed = true
|
||||
@ -30,7 +30,7 @@ text = "Seek"
|
||||
|
||||
[node name="Flee" type="CheckBox" parent="BehaviorControls"]
|
||||
margin_top = 28.0
|
||||
margin_right = 82.0
|
||||
margin_right = 76.0
|
||||
margin_bottom = 52.0
|
||||
focus_mode = 0
|
||||
enabled_focus_mode = 0
|
||||
@ -38,17 +38,17 @@ text = "Flee"
|
||||
|
||||
[node name="Help" type="VBoxContainer" parent="BehaviorControls"]
|
||||
margin_top = 56.0
|
||||
margin_right = 82.0
|
||||
margin_right = 76.0
|
||||
margin_bottom = 108.0
|
||||
|
||||
[node name="Controls" type="Label" parent="BehaviorControls/Help"]
|
||||
margin_right = 82.0
|
||||
margin_right = 76.0
|
||||
margin_bottom = 14.0
|
||||
text = "Controls"
|
||||
|
||||
[node name="GridContainer" type="GridContainer" parent="BehaviorControls/Help"]
|
||||
margin_top = 18.0
|
||||
margin_right = 82.0
|
||||
margin_right = 76.0
|
||||
margin_bottom = 52.0
|
||||
columns = 3
|
||||
|
||||
@ -59,11 +59,11 @@ rect_min_size = Vector2( 15, 15 )
|
||||
|
||||
[node name="W" type="Label" parent="BehaviorControls/Help/GridContainer"]
|
||||
margin_left = 19.0
|
||||
margin_top = -1.0
|
||||
margin_right = 34.0
|
||||
margin_bottom = 14.0
|
||||
margin_bottom = 15.0
|
||||
rect_min_size = Vector2( 15, 15 )
|
||||
text = "W"
|
||||
align = 1
|
||||
|
||||
[node name="Sep2" type="Control" parent="BehaviorControls/Help/GridContainer"]
|
||||
margin_left = 38.0
|
||||
@ -72,24 +72,27 @@ margin_bottom = 15.0
|
||||
rect_min_size = Vector2( 15, 15 )
|
||||
|
||||
[node name="A" type="Label" parent="BehaviorControls/Help/GridContainer"]
|
||||
margin_top = 18.0
|
||||
margin_top = 19.0
|
||||
margin_right = 15.0
|
||||
margin_bottom = 33.0
|
||||
margin_bottom = 34.0
|
||||
rect_min_size = Vector2( 15, 15 )
|
||||
text = "A"
|
||||
align = 1
|
||||
|
||||
[node name="S" type="Label" parent="BehaviorControls/Help/GridContainer"]
|
||||
margin_left = 19.0
|
||||
margin_top = 18.0
|
||||
margin_top = 19.0
|
||||
margin_right = 34.0
|
||||
margin_bottom = 33.0
|
||||
margin_bottom = 34.0
|
||||
rect_min_size = Vector2( 15, 15 )
|
||||
text = "S"
|
||||
align = 1
|
||||
|
||||
[node name="D" type="Label" parent="BehaviorControls/Help/GridContainer"]
|
||||
margin_left = 38.0
|
||||
margin_top = 18.0
|
||||
margin_top = 19.0
|
||||
margin_right = 53.0
|
||||
margin_bottom = 33.0
|
||||
margin_bottom = 34.0
|
||||
rect_min_size = Vector2( 15, 15 )
|
||||
text = "D"
|
||||
align = 1
|
||||
|
Loading…
Reference in New Issue
Block a user