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.
This commit is contained in:
Francois Belair 2020-01-13 16:15:44 -05:00
parent 82d92016a4
commit 0e95c24c7f
20 changed files with 298 additions and 182 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/large_circle.png-31c2e25548cad683b9cdbdea4df32e13.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/sprites/large_circle.png"
dest_files=[ "res://.import/large_circle.png-31c2e25548cad683b9cdbdea4df32e13.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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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:

View File

@ -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"]

View File

@ -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"),

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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 )