From 0e95c24c7f17449ed5fe654cc56f142fface98ca Mon Sep 17 00:00:00 2001 From: Francois Belair Date: Mon, 13 Jan 2020 16:15:44 -0500 Subject: [PATCH] Add GDQuest theme to improved Pursue demo Changed text boxes to sliders to improve usability. This also involved adding some simple graphics, since the _draw method is not anti-aliased and doesn't look great. --- project/assets/sprites/large_circle.png | Bin 0 -> 2345 bytes .../assets/sprites/large_circle.png.import | 34 ++++ project/assets/sprites/small_circle.png | Bin 0 -> 1918 bytes .../assets/sprites/small_circle.png.import | 34 ++++ project/assets/sprites/triangle.png | Bin 0 -> 2752 bytes project/assets/sprites/triangle.png.import | 34 ++++ .../demos/pursue_vs_seek/BoundaryManager.gd | 5 +- project/demos/pursue_vs_seek/GUI.gd | 38 ++-- project/demos/pursue_vs_seek/GUI.tscn | 181 +++++++++--------- project/demos/pursue_vs_seek/Player.gd | 8 +- .../demos/pursue_vs_seek/PursueVSSeekDemo.gd | 15 +- .../pursue_vs_seek/PursueVSSeekDemo.tscn | 32 ++-- project/demos/pursue_vs_seek/Ship.gd | 28 +-- project/demos/seek_and_flee/GUI.gd | 16 +- project/demos/seek_and_flee/GUI.tscn | 5 +- project/demos/seek_and_flee/Player.gd | 11 -- project/demos/seek_and_flee/SeekFleeDemo.gd | 5 +- project/demos/seek_and_flee/SeekFleeDemo.tscn | 15 +- project/demos/seek_and_flee/Seeker.gd | 11 +- project/demos/seek_and_flee/Seeker.tscn | 8 +- 20 files changed, 298 insertions(+), 182 deletions(-) create mode 100644 project/assets/sprites/large_circle.png create mode 100644 project/assets/sprites/large_circle.png.import create mode 100644 project/assets/sprites/small_circle.png create mode 100644 project/assets/sprites/small_circle.png.import create mode 100644 project/assets/sprites/triangle.png create mode 100644 project/assets/sprites/triangle.png.import diff --git a/project/assets/sprites/large_circle.png b/project/assets/sprites/large_circle.png new file mode 100644 index 0000000000000000000000000000000000000000..e69cc1136fbcf0d2212cc72a7c558f88d58869d0 GIT binary patch literal 2345 zcmcImc~BEq9A2;pf~hEq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b-@v^xM${yV9$uj4xSE0HWn|4{vw?*})7IM6IK-8@amn2!`c^1HPJ2%lS(O znUn9*MFZcrR!#S>zn}k1`SFkQyIb>LFI{l<-z=zH$h&?{f9tQ!ec;~Wt%);%U&+Bh z#aN)C!bO~3yuHX>o-F*l;#z1VFxlZe-!a-eUO!iSr5T^ya>?r*s@ie*c3GeQfc#-e z*{h``<-!a1j%|f!yPiHVzo%nl;Fr_mRhP$ZR*xQC9q;ySFS!!H*3DO)rB`2_BG=W{ zY(L>`cp^Sq=l}8e%;?L{-I%^BJb&^2jiJqvccxw}Ut3lnP3H{!9{sv_rl|ObUAYCj zw9nrD!Wi7J??T&qPc`iQcGt#*V?P&lZVU7sy2F>wHh60yjd%ai Ri`~{2GEiIZo7lFy|8LTpfx-X) literal 0 HcmV?d00001 diff --git a/project/assets/sprites/small_circle.png.import b/project/assets/sprites/small_circle.png.import new file mode 100644 index 0000000..560c875 --- /dev/null +++ b/project/assets/sprites/small_circle.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/small_circle.png-e9ef462acf0465fde3767e7b0877ff44.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/sprites/small_circle.png" +dest_files=[ "res://.import/small_circle.png-e9ef462acf0465fde3767e7b0877ff44.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/project/assets/sprites/triangle.png b/project/assets/sprites/triangle.png new file mode 100644 index 0000000000000000000000000000000000000000..5d8b0262cfc7bf42ed1968428fc5c3000aafd7a1 GIT binary patch literal 2752 zcmcImdsGuw9=<_DAXN1C;z}8USNY zYvYqFN%94llG1Z=f>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*~h*6cf((-^ItH~aG7!9lQ9X2iLVnsUNC*K zD&TSPS+sPoX{UbO%0DkFl)Yn5Nv;CSwI?gW(v~#ZnznA98GE3xIEHyRucch7_?>;V z`oj3;#CzvOj_8to2M)}9gydX7u3g$H4UcKLulF>eXA|1Fj%EFIpVubGKU?U3m!VYbN#7wk{l(TGY1%t$cFwh)dvK-K`a2ORL6~`+KU&YVMyZ zZyFCN+9!EEO-^}vdXbMQ1by75aYbS@h4-ujPi7hNax_oQ+@9L+&lY~vpknx|{pL*U zjt{*Z&ng>tzc+Xs5?b{KpC@^ndW&w}3aRB!+XrT?Sv|AwP-l)KxC6T<-@GER0&Kg} yjr|aIJAVJZD;GX?a7q(qBh~32g{Z;HL!VJ+3!-9cik~_EF{2|F%BsTC^8W)CH42FU literal 0 HcmV?d00001 diff --git a/project/assets/sprites/triangle.png.import b/project/assets/sprites/triangle.png.import new file mode 100644 index 0000000..e63a133 --- /dev/null +++ b/project/assets/sprites/triangle.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/triangle.png-fa05d9e46946b626c9973edf66af1138.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/sprites/triangle.png" +dest_files=[ "res://.import/triangle.png-fa05d9e46946b626c9973edf66af1138.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/project/demos/pursue_vs_seek/BoundaryManager.gd b/project/demos/pursue_vs_seek/BoundaryManager.gd index 8cb79f4..a73b32f 100644 --- a/project/demos/pursue_vs_seek/BoundaryManager.gd +++ b/project/demos/pursue_vs_seek/BoundaryManager.gd @@ -20,15 +20,16 @@ func _ready() -> void: var world_pos: = ship.position for i in range(3): - var ship_clone: = ShipType.new($Player/CollisionPolygon2D.polygon) + var ship_clone: = ShipType.new() ship_clone.position.x = world_pos.x if i == 1 else (world_pos.x - _world_bounds.x) ship_clone.position.y = world_pos.y if i == 0 else (world_pos.y - _world_bounds.y) ship_clone.rotation = ship.rotation - ship_clone.color = ship.color ship_clone.tag = i + ship_clone.name = ship.name + "Clone" add_child(ship_clone) + ship_clone.generate_sprite(ship.get_node("Sprite")) _clones[ship_clone] = ship diff --git a/project/demos/pursue_vs_seek/GUI.gd b/project/demos/pursue_vs_seek/GUI.gd index 77c06e3..467c9e2 100644 --- a/project/demos/pursue_vs_seek/GUI.gd +++ b/project/demos/pursue_vs_seek/GUI.gd @@ -1,30 +1,38 @@ -extends MarginContainer +extends PanelContainer signal linear_speed_changed(value) signal linear_accel_changed(value) +signal angular_speed_changed(value) +signal angular_accel_changed(value) +signal decel_radius_changed(value) +signal predict_time_changed(value) -onready var linear_speed: = $Controls/LinSpeed/LineEdit -onready var linear_accel: = $Controls/LinAccel/LineEdit +onready var linear_speed: = $GUI/Controls/LinSpeedBox/MaxLinSpeed +onready var lin_speed_label: = $GUI/Controls/LinSpeedBox/Label +onready var linear_accel: = $GUI/Controls/LinAccelBox/MaxLinAccel +onready var lin_accel_label: = $GUI/Controls/LinAccelBox/Label +onready var predict_time: = $GUI/Controls/PredictTime/PredictTime +onready var predict_time_label: = $GUI/Controls/PredictTime/Label 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") + linear_speed.connect("value_changed", self, "_on_Slider_linear_speed_changed") + linear_accel.connect("value_changed", self, "_on_Slider_linear_accel_changed") + predict_time.connect("value_changed", self, "_on_Slider_predict_time_changed") -func _unhandled_input(event: InputEvent) -> void: - if event is InputEventMouseButton: - linear_speed.release_focus() - linear_accel.release_focus() +func _on_Slider_linear_speed_changed(value: float) -> void: + lin_speed_label.text = "Max linear speed (" + str(value) + ")" + emit_signal("linear_speed_changed", value) -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_Slider_linear_accel_changed(value: float) -> void: + lin_accel_label.text = "Max linear accel (" + str(value) + ")" + emit_signal("linear_accel_changed", value) -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))) +func _on_Slider_predict_time_changed(value: float) -> void: + predict_time_label.text = "Predict time (" + str(value) + " sec)" + emit_signal("predict_time_changed", value) diff --git a/project/demos/pursue_vs_seek/GUI.tscn b/project/demos/pursue_vs_seek/GUI.tscn index f339484..4eda7ac 100644 --- a/project/demos/pursue_vs_seek/GUI.tscn +++ b/project/demos/pursue_vs_seek/GUI.tscn @@ -1,132 +1,139 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://demos/pursue_vs_seek/GUI.gd" type="Script" id=1] +[ext_resource path="res://assets/theme/gdquest.theme" type="Theme" id=2] -[node name="GUI" type="MarginContainer"] +[node name="PanelContainer" type="PanelContainer"] anchor_bottom = 1.0 -custom_constants/margin_right = 20 -custom_constants/margin_top = 20 -custom_constants/margin_left = 20 -custom_constants/margin_bottom = 20 +margin_right = 364.0 +theme = ExtResource( 2 ) script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": false } -[node name="Controls" type="VBoxContainer" parent="."] +[node name="GUI" type="MarginContainer" parent="."] +margin_right = 364.0 +margin_bottom = 600.0 +custom_constants/margin_right = 20 +custom_constants/margin_top = 20 +custom_constants/margin_left = 20 +custom_constants/margin_bottom = 20 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Controls" type="VBoxContainer" parent="GUI"] margin_left = 20.0 margin_top = 20.0 -margin_right = 241.0 +margin_right = 344.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="LinSpeedBox" type="VBoxContainer" parent="GUI/Controls"] +margin_right = 324.0 +margin_bottom = 50.0 -[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="Label" type="Label" parent="GUI/Controls/LinSpeedBox"] +margin_right = 324.0 +margin_bottom = 26.0 +text = "Max linear speed (2000)" -[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="MaxLinSpeed" type="HSlider" parent="GUI/Controls/LinSpeedBox"] +margin_top = 34.0 +margin_right = 324.0 +margin_bottom = 50.0 +max_value = 500.0 -[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"] +[node name="LinAccelBox" type="VBoxContainer" parent="GUI/Controls"] margin_top = 58.0 -margin_right = 221.0 -margin_bottom = 110.0 +margin_right = 324.0 +margin_bottom = 108.0 -[node name="Controls" type="Label" parent="Controls/Help"] -margin_right = 221.0 -margin_bottom = 14.0 +[node name="Label" type="Label" parent="GUI/Controls/LinAccelBox"] +margin_right = 324.0 +margin_bottom = 26.0 +text = "Max linear accel (2000)" + +[node name="MaxLinAccel" type="HSlider" parent="GUI/Controls/LinAccelBox"] +margin_top = 34.0 +margin_right = 324.0 +margin_bottom = 50.0 +step = 0.5 + +[node name="PredictTime" type="VBoxContainer" parent="GUI/Controls"] +margin_top = 116.0 +margin_right = 324.0 +margin_bottom = 166.0 + +[node name="Label" type="Label" parent="GUI/Controls/PredictTime"] +margin_right = 324.0 +margin_bottom = 26.0 +text = "Predict time (2000)" + +[node name="PredictTime" type="HSlider" parent="GUI/Controls/PredictTime"] +margin_top = 34.0 +margin_right = 324.0 +margin_bottom = 50.0 +max_value = 5.0 +step = 0.1 + +[node name="Help" type="VBoxContainer" parent="GUI/Controls"] +margin_top = 174.0 +margin_right = 324.0 +margin_bottom = 264.0 + +[node name="Controls" type="Label" parent="GUI/Controls/Help"] +margin_right = 324.0 +margin_bottom = 26.0 text = "Controls" -[node name="GridContainer" type="GridContainer" parent="Controls/Help"] -margin_top = 18.0 -margin_right = 221.0 -margin_bottom = 52.0 +[node name="GridContainer" type="GridContainer" parent="GUI/Controls/Help"] +margin_top = 34.0 +margin_right = 324.0 +margin_bottom = 90.0 columns = 3 -[node name="Sep" type="Control" parent="Controls/Help/GridContainer"] +[node name="Sep" type="Control" parent="GUI/Controls/Help/GridContainer"] margin_right = 15.0 -margin_bottom = 15.0 +margin_bottom = 26.0 rect_min_size = Vector2( 15, 15 ) -[node name="W" type="Label" parent="Controls/Help/GridContainer"] +[node name="W" type="Label" parent="GUI/Controls/Help/GridContainer"] margin_left = 19.0 -margin_right = 34.0 -margin_bottom = 15.0 +margin_right = 42.0 +margin_bottom = 26.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 +[node name="Sep2" type="Control" parent="GUI/Controls/Help/GridContainer"] +margin_left = 46.0 +margin_right = 63.0 +margin_bottom = 26.0 rect_min_size = Vector2( 15, 15 ) -[node name="A" type="Label" parent="Controls/Help/GridContainer"] -margin_top = 19.0 +[node name="A" type="Label" parent="GUI/Controls/Help/GridContainer"] +margin_top = 30.0 margin_right = 15.0 -margin_bottom = 34.0 +margin_bottom = 56.0 rect_min_size = Vector2( 15, 15 ) text = "A" align = 1 -[node name="S" type="Label" parent="Controls/Help/GridContainer"] +[node name="S" type="Label" parent="GUI/Controls/Help/GridContainer"] margin_left = 19.0 -margin_top = 19.0 -margin_right = 34.0 -margin_bottom = 34.0 +margin_top = 30.0 +margin_right = 42.0 +margin_bottom = 56.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 +[node name="D" type="Label" parent="GUI/Controls/Help/GridContainer"] +margin_left = 46.0 +margin_top = 30.0 +margin_right = 63.0 +margin_bottom = 56.0 rect_min_size = Vector2( 15, 15 ) text = "D" align = 1 diff --git a/project/demos/pursue_vs_seek/Player.gd b/project/demos/pursue_vs_seek/Player.gd index b0b7762..29df3ed 100644 --- a/project/demos/pursue_vs_seek/Player.gd +++ b/project/demos/pursue_vs_seek/Player.gd @@ -40,7 +40,6 @@ func _physics_process(delta: float) -> void: _linear_velocity = move_and_slide(_linear_velocity) _update_agent(_linear_velocity, rotation) - update() func _calculate_angular_velocity( @@ -94,6 +93,9 @@ func _get_movement() -> Vector2: func _update_agent(velocity: Vector2, orientation: float) -> void: - agent.position = Vector3(global_position.x, global_position.y, 0) - agent.linear_velocity = Vector3(velocity.x, velocity.y, 0) + agent.position.x = global_position.x + agent.position.y = global_position.y + agent.linear_velocity.x = velocity.x + agent.linear_velocity.y = velocity.y + agent.angular_velocity = _angular_velocity agent.orientation = orientation diff --git a/project/demos/pursue_vs_seek/PursueVSSeekDemo.gd b/project/demos/pursue_vs_seek/PursueVSSeekDemo.gd index 5f1dbb1..e65d583 100644 --- a/project/demos/pursue_vs_seek/PursueVSSeekDemo.gd +++ b/project/demos/pursue_vs_seek/PursueVSSeekDemo.gd @@ -5,12 +5,19 @@ onready var gui: = $GUI onready var pursuer: = $BoundaryManager/Pursuer onready var seeker: = $BoundaryManager/Seeker +export var start_linear_speed: = 200.0 +export var start_linear_accel: = 25.0 +export var start_predict_time: = 0.3 + 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") + gui.connect("predict_time_changed", self, "_on_GUI_predict_time_changed") + yield(get_tree(), "idle_frame") + gui.linear_speed.value = start_linear_speed + gui.linear_accel.value = start_linear_accel + gui.predict_time.value = start_predict_time func _on_GUI_linear_accel_changed(value: int) -> void: @@ -21,3 +28,7 @@ func _on_GUI_linear_accel_changed(value: int) -> void: func _on_GUI_linear_speed_changed(value: int) -> void: pursuer.agent.max_linear_speed = float(value) seeker.agent.max_linear_speed = float(value) + + +func _on_GUI_predict_time_changed(value: int) -> void: + pursuer._behavior.max_predict_time = float(value) diff --git a/project/demos/pursue_vs_seek/PursueVSSeekDemo.tscn b/project/demos/pursue_vs_seek/PursueVSSeekDemo.tscn index 2691452..d9d2437 100644 --- a/project/demos/pursue_vs_seek/PursueVSSeekDemo.tscn +++ b/project/demos/pursue_vs_seek/PursueVSSeekDemo.tscn @@ -1,16 +1,20 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://demos/pursue_vs_seek/Pursuer.gd" type="Script" id=1] [ext_resource path="res://demos/pursue_vs_seek/Player.gd" type="Script" id=2] [ext_resource path="res://demos/pursue_vs_seek/BoundaryManager.gd" type="Script" id=3] [ext_resource path="res://demos/pursue_vs_seek/PursueVSSeekDemo.gd" type="Script" id=4] [ext_resource path="res://demos/pursue_vs_seek/GUI.tscn" type="PackedScene" id=5] +[ext_resource path="res://assets/sprites/triangle.png" type="Texture" id=6] [node name="PursueVSSeekDemo" type="Node2D"] script = ExtResource( 4 ) __meta__ = { "_editor_description_": "Toy demo to demonstrate the use of the Pursue contrasted to the more naive Seek steering behavior." } +start_linear_speed = 150.0 +start_linear_accel = 75.0 +start_predict_time = 2.0 [node name="BoundaryManager" type="Node2D" parent="."] script = ExtResource( 3 ) @@ -20,32 +24,38 @@ position = Vector2( 49.2031, 556.936 ) rotation = 1.5708 collision_mask = 2 script = ExtResource( 2 ) -color = Color( 1, 0, 0, 1 ) [node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="BoundaryManager/Player"] -polygon = PoolVector2Array( 0, -30, -25, 25, 25, 25 ) +polygon = PoolVector2Array( 0, -32, -24, 32, 24, 32 ) + +[node name="Sprite" type="Sprite" parent="BoundaryManager/Player"] +modulate = Color( 0.968627, 0.188235, 0.0352941, 1 ) +texture = ExtResource( 6 ) [node name="Pursuer" type="KinematicBody2D" parent="BoundaryManager"] position = Vector2( 868.495, 87.9043 ) collision_layer = 2 script = ExtResource( 1 ) -color = Color( 0.811765, 0.909804, 0.113725, 1 ) [node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="BoundaryManager/Pursuer"] -modulate = Color( 0.694118, 0.694118, 0.694118, 1 ) -polygon = PoolVector2Array( 0, -30, -25, 25, 25, 25 ) +polygon = PoolVector2Array( 0, -32, -24, 32, 24, 32 ) + +[node name="Sprite" type="Sprite" parent="BoundaryManager/Pursuer"] +modulate = Color( 0.756863, 0.952941, 0.054902, 1 ) +texture = ExtResource( 6 ) [node name="Seeker" type="KinematicBody2D" parent="BoundaryManager"] position = Vector2( 821.24, 87.9043 ) collision_layer = 2 script = ExtResource( 1 ) -color = Color( 0.113725, 0.909804, 0.219608, 1 ) use_seek = true [node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="BoundaryManager/Seeker"] -modulate = Color( 0.317647, 0.317647, 0.317647, 1 ) -polygon = PoolVector2Array( 0, -30, -25, 25, 25, 25 ) +polygon = PoolVector2Array( 0, -32, -24, 32, 24, 32 ) + +[node name="Sprite" type="Sprite" parent="BoundaryManager/Seeker"] +modulate = Color( 0.278431, 0.815686, 0.14902, 1 ) +texture = ExtResource( 6 ) [node name="GUI" parent="." instance=ExtResource( 5 )] -margin_right = 261.0 -margin_bottom = 150.0 +margin_right = 309.0 diff --git a/project/demos/pursue_vs_seek/Ship.gd b/project/demos/pursue_vs_seek/Ship.gd index 7d9d770..194c329 100644 --- a/project/demos/pursue_vs_seek/Ship.gd +++ b/project/demos/pursue_vs_seek/Ship.gd @@ -1,27 +1,13 @@ extends KinematicBody2D -# Draws a notched triangle based on the vertices of the ship's polygon collider. +# Represents a basic ship -export var color: = Color() - var tag: int = 0 -var _vertices: PoolVector2Array -var _colors: PoolColorArray - -func _init(verts: = PoolVector2Array()) -> void: - _vertices = verts - - -func _ready() -> void: - if not _vertices: - _vertices = $CollisionPolygon2D.polygon - var centroid: = (_vertices[0] + _vertices[1] + _vertices[2])/3 - _vertices.insert(2, centroid) - for i in range(_vertices.size()): - _colors.append(color) - - -func _draw() -> void: - draw_polygon(_vertices, _colors) +func generate_sprite(sprite: Sprite) -> void: + var new_sprite = Sprite.new() + new_sprite.texture = sprite.texture + new_sprite.modulate = sprite.modulate + new_sprite.name = "Sprite" + add_child(new_sprite) diff --git a/project/demos/seek_and_flee/GUI.gd b/project/demos/seek_and_flee/GUI.gd index e6826ee..c3750c8 100644 --- a/project/demos/seek_and_flee/GUI.gd +++ b/project/demos/seek_and_flee/GUI.gd @@ -4,23 +4,23 @@ extends PanelContainer enum BehaviorMode { SEEK, FLEE } signal mode_changed(behavior_mode) -signal acc_changed(value) +signal accel_changed(value) signal speed_changed(value) onready var seek: = $MarginContainer/BehaviorControls/Seek onready var flee: = $MarginContainer/BehaviorControls/Flee -onready var max_acc: = $MarginContainer/BehaviorControls/MaxAccValue +onready var max_accel: = $MarginContainer/BehaviorControls/MaxAccelValue onready var max_speed: = $MarginContainer/BehaviorControls/MaxSpeedValue -onready var max_acc_label: = $MarginContainer/BehaviorControls/MaxAcc +onready var max_accel_label: = $MarginContainer/BehaviorControls/MaxAccel onready var max_speed_label: = $MarginContainer/BehaviorControls/MaxSpeed func _ready() -> void: seek.connect("pressed", self, "_on_Seek_pressed") flee.connect("pressed", self, "_on_Flee_pressed") - max_acc.connect("value_changed", self, "_on_Acc_changed") + max_accel.connect("value_changed", self, "_on_Accel_changed") max_speed.connect("value_changed", self, "_on_Speed_changed") - max_acc_label.text = "Max accel (" + str(max_acc.value) + ")" + max_accel_label.text = "Max accel (" + str(max_accel.value) + ")" max_speed_label.text = "Max speed (" + str(max_speed.value) + ")" @@ -38,9 +38,9 @@ func _on_Flee_pressed() -> void: emit_signal("mode_changed", BehaviorMode.FLEE) -func _on_Acc_changed(value: float) -> void: - max_acc_label.text = "Max accel (" + str(value) + ")" - emit_signal("acc_changed", value) +func _on_Accel_changed(value: float) -> void: + max_accel_label.text = "Max accel (" + str(value) + ")" + emit_signal("accel_changed", value) func _on_Speed_changed(value: float) -> void: diff --git a/project/demos/seek_and_flee/GUI.tscn b/project/demos/seek_and_flee/GUI.tscn index c3d7918..a63d376 100644 --- a/project/demos/seek_and_flee/GUI.tscn +++ b/project/demos/seek_and_flee/GUI.tscn @@ -45,7 +45,7 @@ focus_mode = 0 enabled_focus_mode = 0 text = "Flee" -[node name="MaxAcc" type="Label" parent="MarginContainer/BehaviorControls"] +[node name="MaxAccel" type="Label" parent="MarginContainer/BehaviorControls"] margin_top = 68.0 margin_right = 178.0 margin_bottom = 94.0 @@ -54,7 +54,7 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="MaxAccValue" type="HSlider" parent="MarginContainer/BehaviorControls"] +[node name="MaxAccelValue" type="HSlider" parent="MarginContainer/BehaviorControls"] margin_top = 102.0 margin_right = 178.0 margin_bottom = 118.0 @@ -76,7 +76,6 @@ margin_top = 160.0 margin_right = 178.0 margin_bottom = 176.0 max_value = 450.0 -step = 1.0 value = 100.0 [node name="Help" type="VBoxContainer" parent="MarginContainer/BehaviorControls"] diff --git a/project/demos/seek_and_flee/Player.gd b/project/demos/seek_and_flee/Player.gd index 037b73d..485b88e 100644 --- a/project/demos/seek_and_flee/Player.gd +++ b/project/demos/seek_and_flee/Player.gd @@ -2,21 +2,10 @@ extends KinematicBody2D # Class to control the player in basic left/right up/down movement. -onready var collision_shape: = $CollisionShape2D onready var agent: = GSTAgentLocation.new() export var speed: = 150.0 -var _radius: = 0.0 - - -func _ready() -> void: - _radius = collision_shape.shape.radius - - -func _draw() -> void: - draw_circle(Vector2.ZERO, _radius, Color.red) - func _get_movement() -> Vector2: return Vector2( Input.get_action_strength("sf_right") - Input.get_action_strength("sf_left"), diff --git a/project/demos/seek_and_flee/SeekFleeDemo.gd b/project/demos/seek_and_flee/SeekFleeDemo.gd index 6ae0274..9fcd168 100644 --- a/project/demos/seek_and_flee/SeekFleeDemo.gd +++ b/project/demos/seek_and_flee/SeekFleeDemo.gd @@ -23,7 +23,7 @@ func _ready() -> void: var rng: = RandomNumberGenerator.new() rng.randomize() - gui.max_acc.value = spawner.max_accel + gui.max_accel.value = spawner.max_accel gui.max_speed.value = spawner.max_speed for i in range(spawner.entity_count): @@ -36,8 +36,7 @@ func _ready() -> void: entity.player_agent = player.agent entity.start_speed = spawner.max_speed entity.start_accel = spawner.max_accel - entity.color = spawner.entity_color gui.connect("mode_changed", entity, "_on_GUI_mode_changed") - gui.connect("acc_changed", entity, "_on_GUI_acc_changed") + gui.connect("accel_changed", entity, "_on_GUI_accel_changed") gui.connect("speed_changed", entity, "_on_GUI_speed_changed") spawner.add_child(entity) diff --git a/project/demos/seek_and_flee/SeekFleeDemo.tscn b/project/demos/seek_and_flee/SeekFleeDemo.tscn index 25c2750..02a7a48 100644 --- a/project/demos/seek_and_flee/SeekFleeDemo.tscn +++ b/project/demos/seek_and_flee/SeekFleeDemo.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=10 format=2] +[gd_scene load_steps=11 format=2] [ext_resource path="res://demos/seek_and_flee/Boundary.gd" type="Script" id=1] [ext_resource path="res://demos/seek_and_flee/Player.gd" type="Script" id=2] @@ -6,9 +6,10 @@ [ext_resource path="res://demos/seek_and_flee/Spawner.gd" type="Script" id=4] [ext_resource path="res://demos/seek_and_flee/GUI.tscn" type="PackedScene" id=5] [ext_resource path="res://demos/seek_and_flee/Seeker.tscn" type="PackedScene" id=6] +[ext_resource path="res://assets/sprites/large_circle.png" type="Texture" id=7] [sub_resource type="CircleShape2D" id=1] -radius = 30.0 +radius = 32.0 [sub_resource type="RectangleShape2D" id=2] extents = Vector2( 10, 300 ) @@ -32,6 +33,10 @@ script = ExtResource( 2 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="Player"] shape = SubResource( 1 ) +[node name="Sprite" type="Sprite" parent="Player"] +modulate = Color( 0.952941, 0.290196, 0.0588235, 1 ) +texture = ExtResource( 7 ) + [node name="LeftBoundary" type="StaticBody2D" parent="."] position = Vector2( -512, 0 ) collision_layer = 2 @@ -74,8 +79,8 @@ Entity = ExtResource( 6 ) max_speed = 150.0 [node name="GUI" parent="." instance=ExtResource( 5 )] +anchor_bottom = 0.0 margin_left = -512.0 margin_top = -300.0 -margin_right = -386.0 -margin_bottom = -102.0 -rect_min_size = Vector2( 0, 600 ) +margin_right = -294.0 +margin_bottom = 14.0 diff --git a/project/demos/seek_and_flee/Seeker.gd b/project/demos/seek_and_flee/Seeker.gd index 32022db..9374926 100644 --- a/project/demos/seek_and_flee/Seeker.gd +++ b/project/demos/seek_and_flee/Seeker.gd @@ -2,8 +2,6 @@ extends KinematicBody2D # AI agent that uses the Seek behavior to hone in on the player's location as directly as possible. -onready var collision_shape: = $CollisionShape2D - onready var agent: = GSTSteeringAgent.new() onready var accel: = GSTTargetAcceleration.new() onready var seek: = GSTSeek.new(agent, player_agent) @@ -14,18 +12,11 @@ var player_agent: GSTAgentLocation var velocity: = Vector2.ZERO var start_speed: float var start_accel: float -var color: Color -var radius: = 0.0 func _ready() -> void: agent.max_linear_acceleration = start_accel agent.max_linear_speed = start_speed - radius = collision_shape.shape.radius - - -func _draw() -> void: - draw_circle(Vector2.ZERO, radius, color) func _physics_process(delta: float) -> void: @@ -53,7 +44,7 @@ func _on_GUI_mode_changed(mode: int) -> void: _active_behavior = flee -func _on_GUI_acc_changed(value: float) -> void: +func _on_GUI_accel_changed(value: float) -> void: agent.max_linear_acceleration = value diff --git a/project/demos/seek_and_flee/Seeker.tscn b/project/demos/seek_and_flee/Seeker.tscn index 1d154bb..6e5d647 100644 --- a/project/demos/seek_and_flee/Seeker.tscn +++ b/project/demos/seek_and_flee/Seeker.tscn @@ -1,8 +1,10 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://demos/seek_and_flee/Seeker.gd" type="Script" id=1] +[ext_resource path="res://assets/sprites/small_circle.png" type="Texture" id=2] [sub_resource type="CircleShape2D" id=1] +radius = 16.0 [node name="Seeker" type="KinematicBody2D"] collision_layer = 4 @@ -11,3 +13,7 @@ script = ExtResource( 1 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource( 1 ) + +[node name="Sprite" type="Sprite" parent="."] +modulate = Color( 0.113725, 0.635294, 0.94902, 1 ) +texture = ExtResource( 2 )