diff --git a/project/assets/theme/button/disabled.stylebox b/project/assets/theme/button/disabled.stylebox index 5838b76..252f924 100644 Binary files a/project/assets/theme/button/disabled.stylebox and b/project/assets/theme/button/disabled.stylebox differ diff --git a/project/assets/theme/button/focused.stylebox b/project/assets/theme/button/focused.stylebox index 1b8fd76..04863c6 100644 Binary files a/project/assets/theme/button/focused.stylebox and b/project/assets/theme/button/focused.stylebox differ diff --git a/project/assets/theme/button/hover.stylebox b/project/assets/theme/button/hover.stylebox index fb464a1..08fb085 100644 Binary files a/project/assets/theme/button/hover.stylebox and b/project/assets/theme/button/hover.stylebox differ diff --git a/project/assets/theme/button/normal.stylebox b/project/assets/theme/button/normal.stylebox index 4f8c7da..999edcf 100644 Binary files a/project/assets/theme/button/normal.stylebox and b/project/assets/theme/button/normal.stylebox differ diff --git a/project/assets/theme/button/pressed.stylebox b/project/assets/theme/button/pressed.stylebox index c04a001..7cb801b 100644 Binary files a/project/assets/theme/button/pressed.stylebox and b/project/assets/theme/button/pressed.stylebox differ diff --git a/project/assets/theme/fonts/default_font.tres b/project/assets/theme/fonts/default_font.tres index 9f845d7..d0e94aa 100644 --- a/project/assets/theme/fonts/default_font.tres +++ b/project/assets/theme/fonts/default_font.tres @@ -2,10 +2,7 @@ [ext_resource path="res://assets/theme/fonts/montserrat/Montserrat-Medium.ttf" type="DynamicFontData" id=1] - [resource] - size = 20 use_filter = true font_data = ExtResource( 1 ) - diff --git a/project/assets/theme/fonts/default_font_bold.tres b/project/assets/theme/fonts/default_font_bold.tres index 238d067..0ab7209 100644 --- a/project/assets/theme/fonts/default_font_bold.tres +++ b/project/assets/theme/fonts/default_font_bold.tres @@ -2,10 +2,7 @@ [ext_resource path="res://assets/theme/fonts/montserrat/Montserrat-Bold.ttf" type="DynamicFontData" id=1] - [resource] - size = 20 use_filter = true font_data = ExtResource( 1 ) - diff --git a/project/assets/theme/fonts/default_font_code.tres b/project/assets/theme/fonts/default_font_code.tres index 4f13506..ea05d17 100644 --- a/project/assets/theme/fonts/default_font_code.tres +++ b/project/assets/theme/fonts/default_font_code.tres @@ -2,10 +2,7 @@ [ext_resource path="res://assets/theme/fonts/source_code_pro/SourceCodePro-Medium.otf" type="DynamicFontData" id=1] - [resource] - size = 20 use_filter = true font_data = ExtResource( 1 ) - diff --git a/project/assets/theme/panel/panel.stylebox b/project/assets/theme/panel/panel.stylebox index 1c623a7..0c557d0 100644 Binary files a/project/assets/theme/panel/panel.stylebox and b/project/assets/theme/panel/panel.stylebox differ diff --git a/project/assets/theme/separator/line.tres b/project/assets/theme/separator/line.tres index 85da689..49130dc 100644 --- a/project/assets/theme/separator/line.tres +++ b/project/assets/theme/separator/line.tres @@ -1,7 +1,5 @@ [gd_resource type="StyleBoxLine" format=2] [resource] - color = Color( 1, 1, 1, 0.196078 ) thickness = 2 - diff --git a/project/assets/theme/slider/grabber_area.stylebox b/project/assets/theme/slider/grabber_area.stylebox index 2f566a6..5fd31a9 100644 Binary files a/project/assets/theme/slider/grabber_area.stylebox and b/project/assets/theme/slider/grabber_area.stylebox differ diff --git a/project/assets/theme/slider/slider.stylebox b/project/assets/theme/slider/slider.stylebox index 6fbfe55..f89f29b 100644 Binary files a/project/assets/theme/slider/slider.stylebox and b/project/assets/theme/slider/slider.stylebox differ diff --git a/project/demos/Arrive/ArriveDemo.gd b/project/demos/Arrive/ArriveDemo.gd new file mode 100644 index 0000000..98ffabe --- /dev/null +++ b/project/demos/Arrive/ArriveDemo.gd @@ -0,0 +1,71 @@ +extends Node2D + + +onready var target := $Target +onready var arriver := $Arriver + +export(float, 0, 2000, 40) var max_linear_speed := 800.0 setget set_max_linear_speed +export(float, 0, 200, 1) var max_linear_acceleration := 80.0 setget set_max_linear_acceleration +export(float, 0, 100, 0.1) var arrival_tolerance := 25.0 setget set_arrival_tolerance +export(float, 0, 500, 10) var deceleration_radius := 125.0 setget set_deceleration_radius + +const COLORS := { + deceleration_radius = Color(0.9, 1, 0, 0.1), + arrival_tolerance = Color(0.5, 0.7, 0.9, 0.2) +} + + +func _ready() -> void: + target.position = arriver.global_position + arriver.setup( + max_linear_speed, + max_linear_acceleration, + arrival_tolerance, + deceleration_radius + ) + + +func _unhandled_input(event: InputEvent) -> void: + if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.is_pressed(): + arriver.target.position = Vector3(event.position.x, event.position.y, 0) + target.position = event.position + update() + + +func _draw(): + draw_circle(target.position, deceleration_radius, COLORS.deceleration_radius) + draw_circle(target.position, arrival_tolerance, COLORS.arrival_tolerance) + + +func set_arrival_tolerance(value: float) -> void: + if not is_inside_tree(): + return + + arrival_tolerance = value + arriver.arrive.arrival_tolerance = value + update() + + +func set_deceleration_radius(value: float) -> void: + if not is_inside_tree(): + return + + deceleration_radius = value + arriver.arrive.deceleration_radius = value + update() + + +func set_max_linear_speed(value: float) -> void: + if not is_inside_tree(): + return + + max_linear_speed = value + arriver.agent.max_linear_speed = value + + +func set_max_linear_acceleration(value: float) -> void: + if not is_inside_tree(): + return + + max_linear_acceleration = value + arriver.agent.max_linear_acceleration = value diff --git a/project/demos/Arrive/ArriveDemo.tscn b/project/demos/Arrive/ArriveDemo.tscn new file mode 100644 index 0000000..059dd8e --- /dev/null +++ b/project/demos/Arrive/ArriveDemo.tscn @@ -0,0 +1,49 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://demos/Arrive/Arriver.gd" type="Script" id=1] +[ext_resource path="res://assets/theme/gdquest.theme" type="Theme" id=2] +[ext_resource path="res://demos/Arrive/ArriveDemo.gd" type="Script" id=3] +[ext_resource path="res://assets/sprites/small_circle.png" type="Texture" id=4] + +[sub_resource type="CircleShape2D" id=1] +radius = 16.0 + +[node name="ArriveDemo" type="Node2D"] +script = ExtResource( 3 ) + +[node name="Arriver" type="KinematicBody2D" parent="."] +show_behind_parent = true +position = Vector2( 512, 300 ) +script = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Arriver"] +shape = SubResource( 1 ) + +[node name="Sprite" type="Sprite" parent="Arriver"] +modulate = Color( 0.952941, 0.172549, 0.0431373, 1 ) +texture = ExtResource( 4 ) + +[node name="Target" type="Node2D" parent="."] +position = Vector2( 0, 1 ) + +[node name="GUI" type="PanelContainer" parent="."] +anchor_right = 1.0 +margin_right = 1024.0 +margin_bottom = 87.0 +rect_min_size = Vector2( 1024, 0 ) +theme = ExtResource( 2 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="MarginContainer" type="MarginContainer" parent="GUI"] +margin_right = 1024.0 +margin_bottom = 87.0 + +[node name="Label" type="Label" parent="GUI/MarginContainer"] +margin_left = 16.0 +margin_top = 16.0 +margin_right = 1008.0 +margin_bottom = 71.0 +text = "Arrive Demo +Mouse click to make the red \"Player\" move to the yellow target" diff --git a/project/demos/Arrive/Arriver.gd b/project/demos/Arrive/Arriver.gd new file mode 100644 index 0000000..83c522c --- /dev/null +++ b/project/demos/Arrive/Arriver.gd @@ -0,0 +1,37 @@ +extends KinematicBody2D + + +var agent := GSTSteeringAgent.new() +var target := GSTAgentLocation.new() +var arrive := GSTArrive.new(agent, target) +var _accel := GSTTargetAcceleration.new() + +var _velocity := Vector2() +var _drag := 0.1 + + +func _physics_process(delta: float) -> void: + _update_agent() + _accel = arrive.calculate_steering(_accel) + _velocity += Vector2(_accel.linear.x, _accel.linear.y) + _velocity = _velocity.linear_interpolate(Vector2.ZERO, _drag).clamped(agent.max_linear_speed) + _velocity = move_and_slide(_velocity) + + +func setup( + max_linear_speed: float, + max_linear_acceleration: float, + arrival_tolerance: float, + deceleration_radius: float +) -> void: + agent.max_linear_speed = max_linear_speed + agent.max_linear_acceleration = max_linear_acceleration + agent.position = Vector3(global_position.x, global_position.y, 0) + arrive.deceleration_radius = deceleration_radius + arrive.arrival_tolerance = arrival_tolerance + target.position = agent.position + + +func _update_agent() -> void: + agent.position = Vector3(global_position.x, global_position.y, 0) + agent.linear_velocity = Vector3(_velocity.x, _velocity.y, 0) diff --git a/project/demos/Face/FaceDemo.gd b/project/demos/Face/FaceDemo.gd new file mode 100644 index 0000000..28028b0 --- /dev/null +++ b/project/demos/Face/FaceDemo.gd @@ -0,0 +1,63 @@ +extends Node2D + + +onready var player := $Player +onready var gui := $GUI +onready var turret := $Turret + +export(int, 0, 359) var max_angular_speed := 90 setget set_max_angular_speed +export(int, 0, 359) var max_angular_accel := 5 setget set_max_angular_accel +export(int, 0, 180) var align_tolerance := 5 setget set_align_tolerance +export(int, 0, 359) var deceleration_radius := 45 setget set_deceleration_radius +export(float, 0, 1000) var player_speed := 600.0 setget set_player_speed + + +func _ready() -> void: + player.speed = player_speed + turret.setup( + player.agent, + deg2rad(align_tolerance), + deg2rad(deceleration_radius), + deg2rad(max_angular_accel), + deg2rad(max_angular_speed) + ) + + +func set_align_tolerance(value: int) -> void: + if not is_inside_tree(): + return + + align_tolerance = value + turret.face.alignment_tolerance = deg2rad(value) + + +func set_deceleration_radius(value: int) -> void: + if not is_inside_tree(): + return + + deceleration_radius = value + turret.face.deceleration_radius = deg2rad(value) + + +func set_max_angular_accel(value: int) -> void: + if not is_inside_tree(): + return + + max_angular_accel = value + turret.agent.max_angular_acceleration = deg2rad(value) + + +func set_max_angular_speed(value: int) -> void: + if not is_inside_tree(): + return + + max_angular_speed = value + turret.agent.max_angular_speed = deg2rad(value) + + +func set_player_speed(value: float) -> void: + if not is_inside_tree(): + return + + player_speed = value + player.speed = player_speed diff --git a/project/demos/face/FaceDemo.tscn b/project/demos/Face/FaceDemo.tscn similarity index 56% rename from project/demos/face/FaceDemo.tscn rename to project/demos/Face/FaceDemo.tscn index 207981a..5108dd5 100644 --- a/project/demos/face/FaceDemo.tscn +++ b/project/demos/Face/FaceDemo.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=9 format=2] -[ext_resource path="res://demos/face/Turret.gd" type="Script" id=1] -[ext_resource path="res://demos/face/FaceDemo.gd" type="Script" id=2] -[ext_resource path="res://demos/face/Player.gd" type="Script" id=3] +[ext_resource path="res://demos/Face/Turret.gd" type="Script" id=1] +[ext_resource path="res://demos/Face/FaceDemo.gd" type="Script" id=2] +[ext_resource path="res://demos/Face/Player.gd" type="Script" id=3] [ext_resource path="res://assets/sprites/large_circle.png" type="Texture" id=4] [ext_resource path="res://assets/sprites/small_circle.png" type="Texture" id=5] +[ext_resource path="res://assets/theme/gdquest.theme" type="Theme" id=6] [sub_resource type="CircleShape2D" id=1] radius = 16.0 @@ -30,7 +31,7 @@ modulate = Color( 0.945098, 0.215686, 0.0705882, 1 ) texture = ExtResource( 5 ) [node name="Turret" type="KinematicBody2D" parent="."] -position = Vector2( 512, 150 ) +position = Vector2( 512, 286.288 ) script = ExtResource( 1 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="Turret"] @@ -39,3 +40,23 @@ shape = SubResource( 2 ) [node name="Sprite" type="Sprite" parent="Turret"] modulate = Color( 0.137255, 0.866667, 0.647059, 1 ) texture = ExtResource( 4 ) + +[node name="GUI" type="PanelContainer" parent="."] +margin_right = 1024.0 +margin_bottom = 14.0 +theme = ExtResource( 6 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="MarginContainer" type="MarginContainer" parent="GUI"] +margin_right = 1024.0 +margin_bottom = 87.0 + +[node name="Label" type="Label" parent="GUI/MarginContainer"] +margin_left = 16.0 +margin_top = 16.0 +margin_right = 1008.0 +margin_bottom = 71.0 +text = "Face Demo +Move the player around with WASD and notice the turret orient itself" diff --git a/project/demos/Face/Player.gd b/project/demos/Face/Player.gd new file mode 100644 index 0000000..44b2d47 --- /dev/null +++ b/project/demos/Face/Player.gd @@ -0,0 +1,22 @@ +extends KinematicBody2D + + +var speed: float + +onready var agent := GSTAgentLocation.new() + + +func _physics_process(delta: float) -> void: + var movement := _get_movement() + move_and_slide(movement * speed) + _update_agent() + + +func _get_movement() -> Vector2: + return Vector2( + Input.get_action_strength("sf_right") - Input.get_action_strength("sf_left"), + Input.get_action_strength("sf_down") - Input.get_action_strength("sf_up")) + + +func _update_agent() -> void: + agent.position = Vector3(global_position.x, global_position.y, 0) diff --git a/project/demos/Face/Turret.gd b/project/demos/Face/Turret.gd new file mode 100644 index 0000000..3e0cdff --- /dev/null +++ b/project/demos/Face/Turret.gd @@ -0,0 +1,46 @@ +extends KinematicBody2D + + +var face: GSTFace +var agent := GSTSteeringAgent.new() + +var _accel := GSTTargetAcceleration.new() +var _angular_drag := 0.01 +var _cannon: Rect2 + +onready var collision_shape := $CollisionShape2D + + +func _ready() -> void: + var radius = collision_shape.shape.radius + _cannon = Rect2(Vector2(-5, 0), Vector2(10, -radius*2)) + + +func _physics_process(delta: float) -> void: + _accel = face.calculate_steering(_accel) + agent.angular_velocity += _accel.angular + agent.angular_velocity = lerp(agent.angular_velocity, 0, _angular_drag) + agent.orientation += agent.angular_velocity * delta + rotation = agent.orientation + + +func _draw() -> void: + draw_rect(_cannon, Color.cadetblue) + + +func setup( + player_agent: GSTAgentLocation, + align_tolerance: float, + deceleration_radius: float, + max_angular_accel: float, + max_angular_speed: float +) -> void: + face = GSTFace.new(agent, player_agent) + + face.alignment_tolerance = align_tolerance + face.deceleration_radius = deceleration_radius + + agent.max_angular_acceleration = max_angular_accel + agent.max_angular_speed = max_angular_speed + agent.position = Vector3(global_position.x, global_position.y, 0) + diff --git a/project/demos/follow_path/Drawer.gd b/project/demos/FollowPath/Drawer.gd similarity index 88% rename from project/demos/follow_path/Drawer.gd rename to project/demos/FollowPath/Drawer.gd index b14ee8d..52a6c19 100644 --- a/project/demos/follow_path/Drawer.gd +++ b/project/demos/FollowPath/Drawer.gd @@ -4,9 +4,9 @@ extends Node2D signal path_established(points) -var active_points: = [] -var drawing: = false -var distance_threshold: = 100.0 +var active_points := [] +var drawing := false +var distance_threshold := 100.0 func _unhandled_input(event: InputEvent) -> void: @@ -42,11 +42,11 @@ func _draw() -> void: func _simplify() -> void: var first: Vector2 = active_points.front() var last: Vector2 = active_points.back() - var key: = first - var simplified_path: = [first] + var key := first + var simplified_path := [first] for i in range(1, active_points.size()): var point: Vector2 = active_points[i] - var distance: = point.distance_to(key) + var distance := point.distance_to(key) if distance > distance_threshold: key = point simplified_path.append(key) diff --git a/project/demos/follow_path/FollowPathDemo.gd b/project/demos/FollowPath/FollowPathDemo.gd similarity index 67% rename from project/demos/follow_path/FollowPathDemo.gd rename to project/demos/FollowPath/FollowPathDemo.gd index 62b2703..e990711 100644 --- a/project/demos/follow_path/FollowPathDemo.gd +++ b/project/demos/FollowPath/FollowPathDemo.gd @@ -1,7 +1,7 @@ extends Node2D -onready var drawer: = $Drawer +onready var drawer := $Drawer func _ready() -> void: diff --git a/project/demos/follow_path/FollowPathDemo.tscn b/project/demos/FollowPath/FollowPathDemo.tscn similarity index 73% rename from project/demos/follow_path/FollowPathDemo.tscn rename to project/demos/FollowPath/FollowPathDemo.tscn index b5cf5a8..d73659b 100644 --- a/project/demos/follow_path/FollowPathDemo.tscn +++ b/project/demos/FollowPath/FollowPathDemo.tscn @@ -1,9 +1,9 @@ [gd_scene load_steps=6 format=2] -[ext_resource path="res://demos/follow_path/Drawer.gd" type="Script" id=1] +[ext_resource path="res://demos/FollowPath/Drawer.gd" type="Script" id=1] [ext_resource path="res://assets/sprites/small_circle.png" type="Texture" id=2] -[ext_resource path="res://demos/follow_path/PathFollower.gd" type="Script" id=3] -[ext_resource path="res://demos/follow_path/FollowPathDemo.gd" type="Script" id=4] +[ext_resource path="res://demos/FollowPath/PathFollower.gd" type="Script" id=3] +[ext_resource path="res://demos/FollowPath/FollowPathDemo.gd" type="Script" id=4] [sub_resource type="CircleShape2D" id=1] radius = 16.0 diff --git a/project/demos/follow_path/PathFollower.gd b/project/demos/FollowPath/PathFollower.gd similarity index 78% rename from project/demos/follow_path/PathFollower.gd rename to project/demos/FollowPath/PathFollower.gd index b66405a..9063acc 100644 --- a/project/demos/follow_path/PathFollower.gd +++ b/project/demos/FollowPath/PathFollower.gd @@ -1,16 +1,16 @@ extends KinematicBody2D -onready var agent: = GSTSteeringAgent.new() -onready var path: = GSTPath.new([ +onready var agent := GSTSteeringAgent.new() +onready var path := GSTPath.new([ Vector3(global_position.x, global_position.y, 0), Vector3(global_position.x, global_position.y, 0) ], true) -onready var follow: = GSTFollowPath.new(agent, path, 20, 0) +onready var follow := GSTFollowPath.new(agent, path, 20, 0) -var _velocity: = Vector2.ZERO -var _accel: = GSTTargetAcceleration.new() -var _valid: = false +var _velocity := Vector2.ZERO +var _accel := GSTTargetAcceleration.new() +var _valid := false func setup() -> void: @@ -36,7 +36,7 @@ func _update_agent() -> void: func _on_Drawer_path_established(points: Array) -> void: - var points3: = [] + var points3 := [] for p in points: points3.append(Vector3(p.x, p.y, 0)) path.create_path(points3) diff --git a/project/demos/GroupBehaviors/GroupBehaviorsDemo.gd b/project/demos/GroupBehaviors/GroupBehaviorsDemo.gd new file mode 100644 index 0000000..0084405 --- /dev/null +++ b/project/demos/GroupBehaviors/GroupBehaviorsDemo.gd @@ -0,0 +1,68 @@ +extends Node2D + + +onready var spawner := $Spawner + +export var max_linear_speed := 100.0 setget set_max_linear_speed +export var max_linear_accel := 25.0 setget set_max_linear_accel +export var proximity_radius := 140.0 setget set_proximity_radius +export var show_proximity_radius := true setget set_show_proximity_radius +export var separation_decay_coefficient := 2000.0 setget set_separation_decay_coef +export var cohesion_strength := 0.3 setget set_cohesion_strength +export var separation_strength := 1.5 setget set_separation_strength + + +func set_max_linear_speed(value: float) -> void: + if not is_inside_tree(): + return + + max_linear_speed = value + spawner.set_max_linear_speed(value) + + +func set_max_linear_accel(value: float) -> void: + if not is_inside_tree(): + return + + max_linear_accel = value + spawner.set_max_linear_accel(value) + + +func set_proximity_radius(value: float) -> void: + if not is_inside_tree(): + return + + proximity_radius = value + spawner.set_proximity_radius(value) + + +func set_show_proximity_radius(value: bool) -> void: + if not is_inside_tree(): + return + + show_proximity_radius = value + spawner.set_show_proximity_radius(value) + + +func set_separation_decay_coef(value: float) -> void: + if not is_inside_tree(): + return + + separation_decay_coefficient = value + spawner.set_separation_decay_coef(value) + + +func set_cohesion_strength(value: float) -> void: + if not is_inside_tree(): + return + + cohesion_strength = value + spawner.set_cohesion_strength(value) + + +func set_separation_strength(value: float) -> void: + if not is_inside_tree(): + return + + separation_strength = value + spawner.set_separation_strength(value) diff --git a/project/demos/GroupBehaviors/GroupBehaviorsDemo.tscn b/project/demos/GroupBehaviors/GroupBehaviorsDemo.tscn new file mode 100644 index 0000000..536c138 --- /dev/null +++ b/project/demos/GroupBehaviors/GroupBehaviorsDemo.tscn @@ -0,0 +1,13 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://demos/GroupBehaviors/Member.tscn" type="PackedScene" id=1] +[ext_resource path="res://demos/GroupBehaviors/Spawner.gd" type="Script" id=2] +[ext_resource path="res://demos/GroupBehaviors/GroupBehaviorsDemo.gd" type="Script" id=3] + +[node name="GroupBehaviorsDemo" type="Node2D"] +script = ExtResource( 3 ) + +[node name="Spawner" type="Node2D" parent="."] +position = Vector2( 512, 300 ) +script = ExtResource( 2 ) +member = ExtResource( 1 ) diff --git a/project/demos/group_behaviors/Member.gd b/project/demos/GroupBehaviors/Member.gd similarity index 85% rename from project/demos/group_behaviors/Member.gd rename to project/demos/GroupBehaviors/Member.gd index 6a891d3..a4b6f8b 100644 --- a/project/demos/group_behaviors/Member.gd +++ b/project/demos/GroupBehaviors/Member.gd @@ -1,16 +1,16 @@ extends KinematicBody2D -var agent: = GSTSteeringAgent.new() +var agent := GSTSteeringAgent.new() var separation: GSTSeparation var cohesion: GSTCohesion var proximity: GSTRadiusProximity -var blend: = GSTBlend.new(agent) -var acceleration: = GSTTargetAcceleration.new() -var draw_proximity: = false +var blend := GSTBlend.new(agent) +var acceleration := GSTTargetAcceleration.new() +var draw_proximity := false -var _color: = Color.red -var _velocity: = Vector2() +var _color := Color.red +var _velocity := Vector2() func setup( @@ -53,6 +53,6 @@ func set_neighbors(neighbor: Array) -> void: func update_agent() -> void: - var current_position: = global_position + var current_position := global_position agent.position.x = current_position.x agent.position.y = current_position.y diff --git a/project/demos/group_behaviors/Member.tscn b/project/demos/GroupBehaviors/Member.tscn similarity index 83% rename from project/demos/group_behaviors/Member.tscn rename to project/demos/GroupBehaviors/Member.tscn index 6b7d2bb..a569388 100644 --- a/project/demos/group_behaviors/Member.tscn +++ b/project/demos/GroupBehaviors/Member.tscn @@ -1,8 +1,9 @@ [gd_scene load_steps=4 format=2] -[ext_resource path="res://demos/group_behaviors/Member.gd" type="Script" id=1] +[ext_resource path="res://demos/GroupBehaviors/Member.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 diff --git a/project/demos/group_behaviors/Spawner.gd b/project/demos/GroupBehaviors/Spawner.gd similarity index 95% rename from project/demos/group_behaviors/Spawner.gd rename to project/demos/GroupBehaviors/Spawner.gd index e9853fd..63ac60b 100644 --- a/project/demos/group_behaviors/Spawner.gd +++ b/project/demos/GroupBehaviors/Spawner.gd @@ -5,9 +5,9 @@ export var member: PackedScene func _ready() -> void: - var followers: = [] + var followers := [] for i in range(19): - var follower: = member.instance() + var follower := member.instance() add_child(follower) follower.position += Vector2(rand_range(-60, 60), rand_range(-60, 60)) followers.append(follower) @@ -22,7 +22,7 @@ func _ready() -> void: if i == 0 and owner.show_proximity_radius: follower.draw_proximity = true follower.update() - var agents: = [] + var agents := [] for i in followers: agents.append(i.agent) for i in followers: diff --git a/project/demos/pursue_vs_seek/BoundaryManager.gd b/project/demos/PursueSeek/BoundaryManager.gd similarity index 89% rename from project/demos/pursue_vs_seek/BoundaryManager.gd rename to project/demos/PursueSeek/BoundaryManager.gd index a73b32f..8c80687 100644 --- a/project/demos/pursue_vs_seek/BoundaryManager.gd +++ b/project/demos/PursueSeek/BoundaryManager.gd @@ -2,10 +2,10 @@ extends Node2D # Wraps the ships' positions around the world border, and controls their rendering clones. -onready var ShipType: = preload("res://demos/pursue_vs_seek/Ship.gd") -onready var ships: = [$Player, $Pursuer, $Seeker] +onready var ShipType := preload("res://demos/PursueSeek/Ship.gd") +onready var ships := [$Player, $Pursuer, $Seeker] -var _clones: = {} +var _clones := {} var _world_bounds: Vector2 @@ -17,10 +17,10 @@ func _ready() -> void: for i in range(ships.size()): var ship: Node2D = ships[i] - var world_pos: = ship.position + var world_pos := ship.position for i in range(3): - var ship_clone: = ShipType.new() + 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) diff --git a/project/demos/pursue_vs_seek/Player.gd b/project/demos/PursueSeek/Player.gd similarity index 78% rename from project/demos/pursue_vs_seek/Player.gd rename to project/demos/PursueSeek/Player.gd index 9487f1f..e04dc02 100644 --- a/project/demos/pursue_vs_seek/Player.gd +++ b/project/demos/PursueSeek/Player.gd @@ -1,22 +1,22 @@ -extends "res://demos/pursue_vs_seek/Ship.gd" +extends "res://demos/PursueSeek/Ship.gd" # Controls the player ship's movements based on player input. -onready var agent: = GSTSteeringAgent.new() +onready var agent := GSTSteeringAgent.new() -export var thruster_strength: = 250.0 -export var side_thruster_strength: = 10.0 -export var max_velocity: = 300.0 -export var max_angular_velocity: = 2.0 -export var angular_drag: = 0.025 -export var linear_drag: = 0.025 +export var thruster_strength := 250.0 +export var side_thruster_strength := 10.0 +export var max_velocity := 300.0 +export var max_angular_velocity := 2.0 +export var angular_drag := 0.025 +export var linear_drag := 0.025 -var _linear_velocity: = Vector2() -var _angular_velocity: = 0.0 +var _linear_velocity := Vector2() +var _angular_velocity := 0.0 func _physics_process(delta: float) -> void: - var movement: = _get_movement() + var movement := _get_movement() _angular_velocity = _calculate_angular_velocity( movement.x, _angular_velocity, @@ -50,7 +50,7 @@ func _calculate_angular_velocity( ship_drag: float, delta: float) -> float: - var velocity: = clamp( + var velocity := clamp( current_velocity + thruster_strength * horizontal_movement * delta, -max_velocity, max_velocity @@ -70,13 +70,13 @@ func _calculate_linear_velocity( max_speed: float, delta: float) -> Vector2: - var actual_strength: = 0.0 + var actual_strength := 0.0 if vertical_movement > 0: actual_strength = strength elif vertical_movement < 0: actual_strength = -strength/1.5 - var velocity: = current_velocity + facing_direction * actual_strength * delta + var velocity := current_velocity + facing_direction * actual_strength * delta velocity = velocity.linear_interpolate(Vector2.ZERO, ship_drag_coefficient) return velocity.clamped(max_speed) diff --git a/project/demos/PursueSeek/PursueVSSeekDemo.gd b/project/demos/PursueSeek/PursueVSSeekDemo.gd new file mode 100644 index 0000000..f9cbce5 --- /dev/null +++ b/project/demos/PursueSeek/PursueVSSeekDemo.gd @@ -0,0 +1,35 @@ +extends Node2D + + +onready var pursuer := $BoundaryManager/Pursuer +onready var seeker := $BoundaryManager/Seeker + +export(float, 0, 2000, 40) var max_linear_speed := 200.0 setget set_max_linear_speed +export(float, 0, 200, 1) var max_linear_accel := 10.0 setget set_max_linear_accel +export(float, 0, 5, 0.1) var predict_time := 2.0 setget set_predict_time + + +func set_max_linear_speed(value: float) -> void: + if not is_inside_tree(): + return + + max_linear_speed = value + pursuer.agent.max_linear_speed = value + seeker.agent.max_linear_speed = value + + +func set_max_linear_accel(value: float) -> void: + if not is_inside_tree(): + return + + max_linear_accel = value + pursuer.agent.max_linear_acceleration = value + seeker.agent.max_linear_acceleration = value + + +func set_predict_time(value: float) -> void: + if not is_inside_tree(): + return + + predict_time = value + pursuer._behavior.max_predict_time = value diff --git a/project/demos/pursue_vs_seek/PursueVSSeekDemo.tscn b/project/demos/PursueSeek/PursueVSSeekDemo.tscn similarity index 84% rename from project/demos/pursue_vs_seek/PursueVSSeekDemo.tscn rename to project/demos/PursueSeek/PursueVSSeekDemo.tscn index 0a4e5bc..adb91b1 100644 --- a/project/demos/pursue_vs_seek/PursueVSSeekDemo.tscn +++ b/project/demos/PursueSeek/PursueVSSeekDemo.tscn @@ -1,9 +1,9 @@ [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/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/PursueSeek/Pursuer.gd" type="Script" id=1] +[ext_resource path="res://demos/PursueSeek/Player.gd" type="Script" id=2] +[ext_resource path="res://demos/PursueSeek/BoundaryManager.gd" type="Script" id=3] +[ext_resource path="res://demos/PursueSeek/PursueVSSeekDemo.gd" type="Script" id=4] [ext_resource path="res://assets/sprites/triangle.png" type="Texture" id=6] [node name="PursueVSSeekDemo" type="Node2D"] diff --git a/project/demos/pursue_vs_seek/Pursuer.gd b/project/demos/PursueSeek/Pursuer.gd similarity index 86% rename from project/demos/pursue_vs_seek/Pursuer.gd rename to project/demos/PursueSeek/Pursuer.gd index b44276e..05c34a0 100644 --- a/project/demos/pursue_vs_seek/Pursuer.gd +++ b/project/demos/PursueSeek/Pursuer.gd @@ -1,9 +1,9 @@ -extends "res://demos/pursue_vs_seek/Ship.gd" +extends "res://demos/PursueSeek/Ship.gd" # Represents a ship that chases after the player. -onready var agent: = GSTSteeringAgent.new() -onready var accel: = GSTTargetAcceleration.new() +onready var agent := GSTSteeringAgent.new() +onready var accel := GSTTargetAcceleration.new() onready var player_agent: GSTSteeringAgent = owner.find_node("Player", true, false).agent export var use_seek: bool = false @@ -11,10 +11,10 @@ export var use_seek: bool = false var _orient_behavior: GSTSteeringBehavior var _behavior: GSTSteeringBehavior -var _linear_velocity: = Vector2() -var _linear_drag_coefficient: = 0.025 -var _angular_velocity: = 0.0 -var _angular_drag: = 1.0 +var _linear_velocity := Vector2() +var _linear_drag_coefficient := 0.025 +var _angular_velocity := 0.0 +var _angular_drag := 1.0 func _ready() -> void: diff --git a/project/demos/pursue_vs_seek/Ship.gd b/project/demos/PursueSeek/Ship.gd similarity index 100% rename from project/demos/pursue_vs_seek/Ship.gd rename to project/demos/PursueSeek/Ship.gd diff --git a/project/demos/seek_and_flee/Boundary.gd b/project/demos/SeekFlee/Boundary.gd similarity index 77% rename from project/demos/seek_and_flee/Boundary.gd rename to project/demos/SeekFlee/Boundary.gd index b5a9c03..cbf2441 100644 --- a/project/demos/seek_and_flee/Boundary.gd +++ b/project/demos/SeekFlee/Boundary.gd @@ -6,7 +6,7 @@ var rect: Rect2 func _ready() -> void: - var extents: = ($CollisionShape2D.shape as RectangleShape2D).extents + var extents := ($CollisionShape2D.shape as RectangleShape2D).extents rect = Rect2(-extents, extents*2) diff --git a/project/demos/seek_and_flee/Player.gd b/project/demos/SeekFlee/Player.gd similarity index 83% rename from project/demos/seek_and_flee/Player.gd rename to project/demos/SeekFlee/Player.gd index 9fba69f..85961a8 100644 --- a/project/demos/seek_and_flee/Player.gd +++ b/project/demos/SeekFlee/Player.gd @@ -2,9 +2,9 @@ extends KinematicBody2D # Class to control the player in basic left/right up/down movement. -onready var agent: = GSTAgentLocation.new() +onready var agent := GSTAgentLocation.new() -export var speed: = 200.0 +export var speed := 200.0 func _get_movement() -> Vector2: @@ -13,7 +13,7 @@ func _get_movement() -> Vector2: func _physics_process(delta: float) -> void: - var movement: = _get_movement() + var movement := _get_movement() if movement.length_squared() < 0.01: return diff --git a/project/demos/seek_and_flee/SeekFleeDemo.gd b/project/demos/SeekFlee/SeekFleeDemo.gd similarity index 61% rename from project/demos/seek_and_flee/SeekFleeDemo.gd rename to project/demos/SeekFlee/SeekFleeDemo.gd index 40a0e24..692c71d 100644 --- a/project/demos/seek_and_flee/SeekFleeDemo.gd +++ b/project/demos/SeekFlee/SeekFleeDemo.gd @@ -4,17 +4,17 @@ extends Node2D enum Mode { FLEE, SEEK } -export(Mode) var behavior_mode: = Mode.SEEK setget set_behavior_mode -export(float, 0, 2000, 40) var max_linear_speed: = 200.0 setget set_max_linear_speed -export(float, 0, 500, 0.5) var max_linear_accel: = 10.0 setget set_max_linear_accel +export(Mode) var behavior_mode := Mode.SEEK setget set_behavior_mode +export(float, 0, 2000, 40) var max_linear_speed := 200.0 setget set_max_linear_speed +export(float, 0, 500, 0.5) var max_linear_accel := 10.0 setget set_max_linear_accel + +var camera_boundaries: Rect2 onready var player: KinematicBody2D = $Player onready var spawner: Node2D = $Spawner -var camera_boundaries: Rect2 - -func _init() -> void: +func _ready() -> void: camera_boundaries = Rect2( Vector2.ZERO, Vector2( @@ -22,14 +22,12 @@ func _init() -> void: ProjectSettings["display/window/size/height"] ) ) - - -func _ready() -> void: - var rng: = RandomNumberGenerator.new() + + var rng := RandomNumberGenerator.new() rng.randomize() for i in range(spawner.entity_count): - var new_pos: = Vector2( + var new_pos := Vector2( rng.randf_range(-camera_boundaries.size.x/2, camera_boundaries.size.x/2), rng.randf_range(-camera_boundaries.size.y/2, camera_boundaries.size.y/2) ) @@ -42,29 +40,32 @@ func _ready() -> void: func set_behavior_mode(mode: int) -> void: - behavior_mode = mode + if not is_inside_tree(): + return - if spawner: - match mode: - Mode.SEEK: - for child in spawner.get_children(): - child.use_seek = true - Mode.FLEE: - for child in spawner.get_children(): - child.use_seek = false + behavior_mode = mode + match mode: + Mode.SEEK: + for child in spawner.get_children(): + child.use_seek = true + Mode.FLEE: + for child in spawner.get_children(): + child.use_seek = false func set_max_linear_speed(value: float) -> void: - max_linear_speed = value + if not is_inside_tree(): + return - if spawner: - for child in spawner.get_children(): - child.agent.max_linear_speed = value + max_linear_speed = value + for child in spawner.get_children(): + child.agent.max_linear_speed = value func set_max_linear_accel(value: float) -> void: - max_linear_accel = value + if not is_inside_tree(): + return - if spawner: - for child in spawner.get_children(): - child.agent.max_linear_acceleration = value + max_linear_accel = value + for child in spawner.get_children(): + child.agent.max_linear_acceleration = value diff --git a/project/demos/seek_and_flee/SeekFleeDemo.tscn b/project/demos/SeekFlee/SeekFleeDemo.tscn similarity index 83% rename from project/demos/seek_and_flee/SeekFleeDemo.tscn rename to project/demos/SeekFlee/SeekFleeDemo.tscn index faf8d07..330a328 100644 --- a/project/demos/seek_and_flee/SeekFleeDemo.tscn +++ b/project/demos/SeekFlee/SeekFleeDemo.tscn @@ -1,10 +1,10 @@ [gd_scene load_steps=10 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] -[ext_resource path="res://demos/seek_and_flee/SeekFleeDemo.gd" type="Script" id=3] -[ext_resource path="res://demos/seek_and_flee/Spawner.gd" type="Script" id=4] -[ext_resource path="res://demos/seek_and_flee/Seeker.tscn" type="PackedScene" id=6] +[ext_resource path="res://demos/SeekFlee/Boundary.gd" type="Script" id=1] +[ext_resource path="res://demos/SeekFlee/Player.gd" type="Script" id=2] +[ext_resource path="res://demos/SeekFlee/SeekFleeDemo.gd" type="Script" id=3] +[ext_resource path="res://demos/SeekFlee/Spawner.gd" type="Script" id=4] +[ext_resource path="res://demos/SeekFlee/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] diff --git a/project/demos/seek_and_flee/Seeker.gd b/project/demos/SeekFlee/Seeker.gd similarity index 77% rename from project/demos/seek_and_flee/Seeker.gd rename to project/demos/SeekFlee/Seeker.gd index 5795944..4247eb0 100644 --- a/project/demos/seek_and_flee/Seeker.gd +++ b/project/demos/SeekFlee/Seeker.gd @@ -2,16 +2,16 @@ extends KinematicBody2D # AI agent that uses the Seek behavior to hone in on the player's location as directly as possible. -onready var agent: = GSTSteeringAgent.new() -onready var accel: = GSTTargetAcceleration.new() -onready var seek: = GSTSeek.new(agent, player_agent) -onready var flee: = GSTFlee.new(agent, player_agent) +onready var agent := GSTSteeringAgent.new() +onready var accel := GSTTargetAcceleration.new() +onready var seek := GSTSeek.new(agent, player_agent) +onready var flee := GSTFlee.new(agent, player_agent) var player_agent: GSTAgentLocation -var velocity: = Vector2.ZERO +var velocity := Vector2.ZERO var start_speed: float var start_accel: float -var use_seek: = true +var use_seek := true func _ready() -> void: diff --git a/project/demos/seek_and_flee/Seeker.tscn b/project/demos/SeekFlee/Seeker.tscn similarity index 86% rename from project/demos/seek_and_flee/Seeker.tscn rename to project/demos/SeekFlee/Seeker.tscn index 6e5d647..cf2e52d 100644 --- a/project/demos/seek_and_flee/Seeker.tscn +++ b/project/demos/SeekFlee/Seeker.tscn @@ -1,8 +1,9 @@ [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://demos/SeekFlee/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 diff --git a/project/demos/seek_and_flee/Spawner.gd b/project/demos/SeekFlee/Spawner.gd similarity index 65% rename from project/demos/seek_and_flee/Spawner.gd rename to project/demos/SeekFlee/Spawner.gd index 99de62d..77fa588 100644 --- a/project/demos/seek_and_flee/Spawner.gd +++ b/project/demos/SeekFlee/Spawner.gd @@ -3,5 +3,5 @@ extends Node2D export(PackedScene) var Entity: PackedScene -export var entity_count: = 10 -export var entity_color: = Color.blue +export var entity_count:= 10 +export var entity_color:= Color.blue diff --git a/project/demos/arrive/ArriveDemo.gd b/project/demos/arrive/ArriveDemo.gd deleted file mode 100644 index deaef47..0000000 --- a/project/demos/arrive/ArriveDemo.gd +++ /dev/null @@ -1,39 +0,0 @@ -extends Node2D - - -onready var target: = $Target -onready var arriver: = $Arriver -onready var gui: = $GUI - -export(float, 0, 2000, 40) var max_linear_speed: = 200.0 setget set_max_linear_speed -export(float, 0, 200, 1) var max_linear_accel: = 25.0 setget set_max_linear_accel -export(float, 0, 100, 0.1) var arrival_tolerance: = 20.0 setget set_arrival_tolerance -export(float, 0, 500, 10) var deceleration_radius: = 200.0 setget set_deceleration_radius - - -func _ready() -> void: - target.position = arriver.global_position - - -func set_arrival_tolerance(value: float) -> void: - arrival_tolerance = value - if arriver: - arriver.arrive.arrival_tolerance = value - - -func set_deceleration_radius(value: float) -> void: - deceleration_radius = value - if arriver: - arriver.arrive.deceleration_radius = value - - -func set_max_linear_speed(value: float) -> void: - max_linear_speed = value - if arriver: - arriver.agent.max_linear_speed = value - - -func set_max_linear_accel(value: float) -> void: - max_linear_accel = value - if arriver: - arriver.agent.max_linear_acceleration = value diff --git a/project/demos/arrive/ArriveDemo.tscn b/project/demos/arrive/ArriveDemo.tscn deleted file mode 100644 index b84edba..0000000 --- a/project/demos/arrive/ArriveDemo.tscn +++ /dev/null @@ -1,35 +0,0 @@ -[gd_scene load_steps=6 format=2] - -[ext_resource path="res://demos/arrive/Arriver.gd" type="Script" id=1] -[ext_resource path="res://demos/arrive/ArriveDemo.gd" type="Script" id=2] -[ext_resource path="res://assets/sprites/large_circle.png" type="Texture" id=3] -[ext_resource path="res://assets/sprites/small_circle.png" type="Texture" id=4] - -[sub_resource type="CircleShape2D" id=1] -radius = 16.0 - -[node name="ArriveDemo" type="Node2D"] -script = ExtResource( 2 ) -max_linear_speed = 400.0 -max_linear_accel = 50.0 -arrival_tolerance = 10.0 -deceleration_radius = 80.0 - -[node name="Arriver" type="KinematicBody2D" parent="."] -position = Vector2( 512, 300 ) -script = ExtResource( 1 ) - -[node name="CollisionShape2D" type="CollisionShape2D" parent="Arriver"] -shape = SubResource( 1 ) - -[node name="Sprite" type="Sprite" parent="Arriver"] -modulate = Color( 0.952941, 0.172549, 0.0431373, 1 ) -texture = ExtResource( 4 ) - -[node name="Target" type="Sprite" parent="."] -modulate = Color( 0.827451, 1, 0, 0.501961 ) -texture = ExtResource( 3 ) - -[node name="Sprite" type="Sprite" parent="Target"] -scale = Vector2( 0.5, 0.5 ) -texture = ExtResource( 4 ) diff --git a/project/demos/arrive/Arriver.gd b/project/demos/arrive/Arriver.gd deleted file mode 100644 index 2cfad09..0000000 --- a/project/demos/arrive/Arriver.gd +++ /dev/null @@ -1,40 +0,0 @@ -extends KinematicBody2D - - -onready var agent: = GSTSteeringAgent.new() -onready var target: = GSTAgentLocation.new() -onready var arrive: = GSTArrive.new(agent, target) -var _accel: = GSTTargetAcceleration.new() - -var _velocity: = Vector2() -var _drag: = 0.1 - - -func _ready() -> void: - agent.max_linear_speed = owner.max_linear_speed - agent.max_linear_acceleration = owner.max_linear_accel - agent.position = Vector3(global_position.x, global_position.y, 0) - arrive.deceleration_radius = owner.deceleration_radius - arrive.arrival_tolerance = owner.arrival_tolerance - target.position = agent.position - - -func _unhandled_input(event: InputEvent) -> void: - if event is InputEventMouseButton: - var mb: InputEventMouseButton = event - if mb.button_index == BUTTON_LEFT and mb.pressed: - target.position = Vector3(mb.position.x, mb.position.y, 0) - owner.target.position = mb.position - - -func _physics_process(delta: float) -> void: - _update_agent() - _accel = arrive.calculate_steering(_accel) - _velocity += Vector2(_accel.linear.x, _accel.linear.y) - _velocity = _velocity.linear_interpolate(Vector2.ZERO, _drag).clamped(agent.max_linear_speed) - _velocity = move_and_slide(_velocity) - - -func _update_agent() -> void: - agent.position = Vector3(global_position.x, global_position.y, 0) - agent.linear_velocity = Vector3(_velocity.x, _velocity.y, 0) diff --git a/project/demos/face/FaceDemo.gd b/project/demos/face/FaceDemo.gd deleted file mode 100644 index b754e51..0000000 --- a/project/demos/face/FaceDemo.gd +++ /dev/null @@ -1,44 +0,0 @@ -extends Node2D - - -onready var player: = $Player -onready var gui: = $GUI -onready var turret: = $Turret - -export(int, 0, 359, 1) var max_angular_speed: = 90 setget set_max_angular_speed -export(int, 0, 359, 1) var max_angular_accel: = 5 setget set_max_angular_accel -export(int, 0, 180, 1) var align_tolerance: = 5 setget set_align_tolerance -export(int, 0, 359, 1) var deceleration_radius: = 45 setget set_deceleration_radius - - -func _ready() -> void: - turret.setup( - deg2rad(align_tolerance), - deg2rad(deceleration_radius), - deg2rad(max_angular_accel), - deg2rad(max_angular_speed) - ) - - -func set_align_tolerance(value: int) -> void: - align_tolerance = value - if turret: - turret._face.alignment_tolerance = deg2rad(value) - - -func set_deceleration_radius(value: int) -> void: - deceleration_radius = value - if turret: - turret._face.deceleration_radius = deg2rad(value) - - -func set_max_angular_accel(value: int) -> void: - max_angular_accel = value - if turret: - turret._agent.max_angular_acceleration = deg2rad(value) - - -func set_max_angular_speed(value: int) -> void: - max_angular_speed = value - if turret: - turret._agent.max_angular_speed = deg2rad(value) diff --git a/project/demos/face/Player.gd b/project/demos/face/Player.gd deleted file mode 100644 index 5c7609e..0000000 --- a/project/demos/face/Player.gd +++ /dev/null @@ -1,21 +0,0 @@ -extends KinematicBody2D - - -onready var agent: = GSTAgentLocation.new() - -export var speed: = 125.0 - - -func _physics_process(delta: float) -> void: - var movement: = _get_movement() - move_and_slide(movement * speed) - _update_agent() - - -func _get_movement() -> Vector2: - return Vector2( Input.get_action_strength("sf_right") - Input.get_action_strength("sf_left"), - Input.get_action_strength("sf_down") - Input.get_action_strength("sf_up")) - - -func _update_agent() -> void: - agent.position = Vector3(global_position.x, global_position.y, 0) diff --git a/project/demos/face/Turret.gd b/project/demos/face/Turret.gd deleted file mode 100644 index 7eb6cae..0000000 --- a/project/demos/face/Turret.gd +++ /dev/null @@ -1,59 +0,0 @@ -extends KinematicBody2D - - -onready var collision_shape: = $CollisionShape2D - -var _cannon: Rect2 - -var _agent: = GSTSteeringAgent.new() -var _accel: = GSTTargetAcceleration.new() - -var _angular_velocity: = 0.0 -var _angular_drag: = 0.01 -var _face: GSTFace - - -func _ready() -> void: - var radius = collision_shape.shape.radius - _cannon = Rect2(Vector2(-5, 0), Vector2(10, -radius*2)) - - -func _draw() -> void: - draw_rect(_cannon, Color.blue) - - -func _physics_process(delta: float) -> void: - if not _face: - return - - _accel = _face.calculate_steering(_accel) - _angular_velocity += _accel.angular - - _angular_velocity = lerp(_angular_velocity, 0, _angular_drag) - - rotation += _angular_velocity * delta - - _update_agent() - - -func setup( - align_tolerance: float, - deceleration_radius: float, - max_angular_accel: float, - max_angular_speed: float - ) -> void: - _face = GSTFace.new(_agent, owner.player.agent) - - _face.alignment_tolerance = align_tolerance - _face.deceleration_radius = deceleration_radius - - _agent.max_angular_acceleration = max_angular_accel - _agent.max_angular_speed = max_angular_speed - _agent.position = Vector3(global_position.x, global_position.y, 0) - - _update_agent() - - -func _update_agent() -> void: - _agent.angular_velocity = _angular_velocity - _agent.orientation = rotation diff --git a/project/demos/group_behaviors/GroupBehaviorsDemo.gd b/project/demos/group_behaviors/GroupBehaviorsDemo.gd deleted file mode 100644 index d400c31..0000000 --- a/project/demos/group_behaviors/GroupBehaviorsDemo.gd +++ /dev/null @@ -1,58 +0,0 @@ -extends Node2D - - -onready var spawner: = $Spawner - -export var max_linear_speed: = 100.0 setget set_max_linear_speed -export var max_linear_accel: = 25.0 setget set_max_linear_accel -export var proximity_radius: = 140.0 setget set_proximity_radius -export var show_proximity_radius: = true setget set_show_proximity_radius -export var separation_decay_coefficient: = 2000.0 setget set_separation_decay_coef -export var cohesion_strength: = 0.3 setget set_cohesion_strength -export var separation_strength: = 1.5 setget set_separation_strength - - -func _ready() -> void: - pass - - -func set_max_linear_speed(value: float) -> void: - max_linear_speed = value - if spawner: - spawner.set_max_linear_speed(value) - - -func set_max_linear_accel(value: float) -> void: - max_linear_accel = value - if spawner: - spawner.set_max_linear_accel(value) - - -func set_proximity_radius(value: float) -> void: - proximity_radius = value - if spawner: - spawner.set_proximity_radius(value) - - -func set_show_proximity_radius(value: bool) -> void: - show_proximity_radius = value - if spawner: - spawner.set_show_proximity_radius(value) - - -func set_separation_decay_coef(value: float) -> void: - separation_decay_coefficient = value - if spawner: - spawner.set_separation_decay_coef(value) - - -func set_cohesion_strength(value: float) -> void: - cohesion_strength = value - if spawner: - spawner.set_cohesion_strength(value) - - -func set_separation_strength(value: float) -> void: - separation_strength = value - if spawner: - spawner.set_separation_strength(value) diff --git a/project/demos/group_behaviors/GroupBehaviorsDemo.tscn b/project/demos/group_behaviors/GroupBehaviorsDemo.tscn deleted file mode 100644 index d1338cd..0000000 --- a/project/demos/group_behaviors/GroupBehaviorsDemo.tscn +++ /dev/null @@ -1,13 +0,0 @@ -[gd_scene load_steps=4 format=2] - -[ext_resource path="res://demos/group_behaviors/Member.tscn" type="PackedScene" id=1] -[ext_resource path="res://demos/group_behaviors/Spawner.gd" type="Script" id=2] -[ext_resource path="res://demos/group_behaviors/GroupBehaviorsDemo.gd" type="Script" id=3] - -[node name="GroupBehaviorsDemo" type="Node2D"] -script = ExtResource( 3 ) - -[node name="Spawner" type="Node2D" parent="."] -position = Vector2( 512, 300 ) -script = ExtResource( 2 ) -member = ExtResource( 1 ) diff --git a/project/demos/pursue_vs_seek/PursueVSSeekDemo.gd b/project/demos/pursue_vs_seek/PursueVSSeekDemo.gd deleted file mode 100644 index 5af3c3d..0000000 --- a/project/demos/pursue_vs_seek/PursueVSSeekDemo.gd +++ /dev/null @@ -1,31 +0,0 @@ -extends Node2D - - -onready var pursuer: = $BoundaryManager/Pursuer -onready var seeker: = $BoundaryManager/Seeker - -export(float, 0, 2000, 40) var max_linear_speed: = 200.0 setget set_max_linear_speed -export(float, 0, 200, 1) var max_linear_accel: = 10.0 setget set_max_linear_accel -export(float, 0, 5, 0.1) var predict_time: = 2.0 setget set_predict_time - - -func set_max_linear_speed(value: float) -> void: - max_linear_speed = value - if pursuer: - pursuer.agent.max_linear_speed = value - if seeker: - seeker.agent.max_linear_speed = value - - -func set_max_linear_accel(value: float) -> void: - max_linear_accel = value - if pursuer: - pursuer.agent.max_linear_acceleration = value - if seeker: - seeker.agent.max_linear_acceleration = value - - -func set_predict_time(value: float) -> void: - predict_time = value - if pursuer: - pursuer._behavior.max_predict_time = value diff --git a/project/project.godot b/project/project.godot index fc258be..dfc6310 100644 --- a/project/project.godot +++ b/project/project.godot @@ -17,42 +17,42 @@ _global_script_classes=[ { "base": "GSTSteeringBehavior", "class": "GSTArrive", "language": "GDScript", -"path": "res://src/behaviors/GSTArrive.gd" +"path": "res://src/Behaviors/GSTArrive.gd" }, { "base": "GSTGroupBehavior", "class": "GSTAvoidCollisions", "language": "GDScript", -"path": "res://src/behaviors/GSTAvoidCollisions.gd" +"path": "res://src/Behaviors/GSTAvoidCollisions.gd" }, { "base": "GSTSteeringBehavior", "class": "GSTBlend", "language": "GDScript", -"path": "res://src/behaviors/GSTBlend.gd" +"path": "res://src/Behaviors/GSTBlend.gd" }, { "base": "GSTGroupBehavior", "class": "GSTCohesion", "language": "GDScript", -"path": "res://src/behaviors/GSTCohesion.gd" +"path": "res://src/Behaviors/GSTCohesion.gd" }, { "base": "GSTPursue", "class": "GSTEvade", "language": "GDScript", -"path": "res://src/behaviors/GSTEvade.gd" +"path": "res://src/Behaviors/GSTEvade.gd" }, { "base": "GSTMatchOrientation", "class": "GSTFace", "language": "GDScript", -"path": "res://src/behaviors/GSTFace.gd" +"path": "res://src/Behaviors/GSTFace.gd" }, { "base": "GSTSeek", "class": "GSTFlee", "language": "GDScript", -"path": "res://src/behaviors/GSTFlee.gd" +"path": "res://src/Behaviors/GSTFlee.gd" }, { "base": "GSTArrive", "class": "GSTFollowPath", "language": "GDScript", -"path": "res://src/behaviors/GSTFollowPath.gd" +"path": "res://src/Behaviors/GSTFollowPath.gd" }, { "base": "GSTSteeringBehavior", "class": "GSTGroupBehavior", @@ -62,17 +62,17 @@ _global_script_classes=[ { "base": "GSTProximity", "class": "GSTInfiniteProximity", "language": "GDScript", -"path": "res://src/proximities/GSTInfiniteProximity.gd" +"path": "res://src/Proximities/GSTInfiniteProximity.gd" }, { "base": "GSTMatchOrientation", "class": "GSTLookWhereYouGo", "language": "GDScript", -"path": "res://src/behaviors/GSTLookWhereYouGo.gd" +"path": "res://src/Behaviors/GSTLookWhereYouGo.gd" }, { "base": "GSTSteeringBehavior", "class": "GSTMatchOrientation", "language": "GDScript", -"path": "res://src/behaviors/GSTMatchOrientation.gd" +"path": "res://src/Behaviors/GSTMatchOrientation.gd" }, { "base": "Reference", "class": "GSTPath", @@ -82,32 +82,32 @@ _global_script_classes=[ { "base": "GSTSteeringBehavior", "class": "GSTPriority", "language": "GDScript", -"path": "res://src/behaviors/GSTPriority.gd" +"path": "res://src/Behaviors/GSTPriority.gd" }, { "base": "Reference", "class": "GSTProximity", "language": "GDScript", -"path": "res://src/proximities/GSTProximity.gd" +"path": "res://src/Proximities/GSTProximity.gd" }, { "base": "GSTSteeringBehavior", "class": "GSTPursue", "language": "GDScript", -"path": "res://src/behaviors/GSTPursue.gd" +"path": "res://src/Behaviors/GSTPursue.gd" }, { "base": "GSTProximity", "class": "GSTRadiusProximity", "language": "GDScript", -"path": "res://src/proximities/GSTRadiusProximity.gd" +"path": "res://src/Proximities/GSTRadiusProximity.gd" }, { "base": "GSTSteeringBehavior", "class": "GSTSeek", "language": "GDScript", -"path": "res://src/behaviors/GSTSeek.gd" +"path": "res://src/Behaviors/GSTSeek.gd" }, { "base": "GSTGroupBehavior", "class": "GSTSeparation", "language": "GDScript", -"path": "res://src/behaviors/GSTSeparation.gd" +"path": "res://src/Behaviors/GSTSeparation.gd" }, { "base": "GSTAgentLocation", "class": "GSTSteeringAgent", diff --git a/project/src/behaviors/GSTArrive.gd b/project/src/Behaviors/GSTArrive.gd similarity index 82% rename from project/src/behaviors/GSTArrive.gd rename to project/src/Behaviors/GSTArrive.gd index eeb84c0..a451bd9 100644 --- a/project/src/behaviors/GSTArrive.gd +++ b/project/src/Behaviors/GSTArrive.gd @@ -7,7 +7,7 @@ class_name GSTArrive var target: GSTAgentLocation var arrival_tolerance: float var deceleration_radius: float -var time_to_reach: = 0.1 +var time_to_reach := 0.1 func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void: @@ -15,18 +15,18 @@ func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void: func _arrive(acceleration: GSTTargetAcceleration, target_position: Vector3) -> GSTTargetAcceleration: - var to_target: = target_position - agent.position - var distance: = to_target.length() + var to_target := target_position - agent.position + var distance := to_target.length() if distance <= arrival_tolerance: acceleration.set_zero() else: - var desired_speed: = agent.max_linear_speed + var desired_speed := agent.max_linear_speed if distance <= deceleration_radius: desired_speed *= distance / deceleration_radius - var desired_velocity: = to_target * desired_speed/distance + var desired_velocity := to_target * desired_speed/distance desired_velocity = (desired_velocity - agent.linear_velocity) * 1.0 / time_to_reach diff --git a/project/src/behaviors/GSTAvoidCollisions.gd b/project/src/Behaviors/GSTAvoidCollisions.gd similarity index 88% rename from project/src/behaviors/GSTAvoidCollisions.gd rename to project/src/Behaviors/GSTAvoidCollisions.gd index d4ed8d2..2562b30 100644 --- a/project/src/behaviors/GSTAvoidCollisions.gd +++ b/project/src/Behaviors/GSTAvoidCollisions.gd @@ -21,7 +21,7 @@ func _calculate_steering(acceleration: GSTTargetAcceleration) -> GSTTargetAccele first_minimum_separation = 0 first_distance = 0 - var neighbor_count: = proximity.find_neighbors(_callback) + var neighbor_count := proximity.find_neighbors(_callback) if neighbor_count == 0 or not first_neighbor: acceleration.set_zero() @@ -39,9 +39,9 @@ func _calculate_steering(acceleration: GSTTargetAcceleration) -> GSTTargetAccele func report_neighbor(neighbor: GSTSteeringAgent) -> bool: - var relative_position: = neighbor.position - agent.position - var relative_velocity: = neighbor.linear_velocity - agent.linear_velocity - var relative_speed_squared: = relative_velocity.length_squared() + var relative_position := neighbor.position - agent.position + var relative_velocity := neighbor.linear_velocity - agent.linear_velocity + var relative_speed_squared := relative_velocity.length_squared() if relative_speed_squared == 0: return false diff --git a/project/src/behaviors/GSTBlend.gd b/project/src/Behaviors/GSTBlend.gd similarity index 95% rename from project/src/behaviors/GSTBlend.gd rename to project/src/Behaviors/GSTBlend.gd index 67f5899..310c6fa 100644 --- a/project/src/behaviors/GSTBlend.gd +++ b/project/src/Behaviors/GSTBlend.gd @@ -9,8 +9,8 @@ class_name GSTBlend # `GSTSteeringBehavior` and a `weight` key with a value of type float. -var _behaviors: = [] -var _accel: = GSTTargetAcceleration.new() +var _behaviors := [] +var _accel := GSTTargetAcceleration.new() func _init(agent: GSTSteeringAgent).(agent) -> void: diff --git a/project/src/behaviors/GSTCohesion.gd b/project/src/Behaviors/GSTCohesion.gd similarity index 100% rename from project/src/behaviors/GSTCohesion.gd rename to project/src/Behaviors/GSTCohesion.gd diff --git a/project/src/behaviors/GSTEvade.gd b/project/src/Behaviors/GSTEvade.gd similarity index 85% rename from project/src/behaviors/GSTEvade.gd rename to project/src/Behaviors/GSTEvade.gd index ce89767..b8448fd 100644 --- a/project/src/behaviors/GSTEvade.gd +++ b/project/src/Behaviors/GSTEvade.gd @@ -8,7 +8,7 @@ class_name GSTEvade func _init( agent: GSTSteeringAgent, target: GSTSteeringAgent, - max_predict_time: = 1.0).(agent, target, max_predict_time): + max_predict_time := 1.0).(agent, target, max_predict_time): pass diff --git a/project/src/behaviors/GSTFace.gd b/project/src/Behaviors/GSTFace.gd similarity index 88% rename from project/src/behaviors/GSTFace.gd rename to project/src/Behaviors/GSTFace.gd index 7a5c3dd..853acaa 100644 --- a/project/src/behaviors/GSTFace.gd +++ b/project/src/Behaviors/GSTFace.gd @@ -9,8 +9,8 @@ func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent, target) -> func _face(acceleration: GSTTargetAcceleration, target_position: Vector3) -> GSTTargetAcceleration: - var to_target: = target_position - agent.position - var distance_squared: = to_target.length_squared() + var to_target := target_position - agent.position + var distance_squared := to_target.length_squared() if distance_squared < agent.zero_linear_speed_threshold: acceleration.set_zero() diff --git a/project/src/behaviors/GSTFlee.gd b/project/src/Behaviors/GSTFlee.gd similarity index 100% rename from project/src/behaviors/GSTFlee.gd rename to project/src/Behaviors/GSTFlee.gd diff --git a/project/src/behaviors/GSTFollowPath.gd b/project/src/Behaviors/GSTFollowPath.gd similarity index 71% rename from project/src/behaviors/GSTFollowPath.gd rename to project/src/Behaviors/GSTFollowPath.gd index d870fee..9c31627 100644 --- a/project/src/behaviors/GSTFollowPath.gd +++ b/project/src/Behaviors/GSTFollowPath.gd @@ -4,33 +4,33 @@ class_name GSTFollowPath var path: GSTPath -var path_offset: = 0.0 +var path_offset := 0.0 -var path_param: = {segment_index = 0, distance = 0} +var path_param := {segment_index = 0, distance = 0} -var arrive_enabled: = true -var prediction_time: = 0.0 +var arrive_enabled := true +var prediction_time := 0.0 func _init( agent: GSTSteeringAgent, path: GSTPath, - path_offset: = 0.0, - prediction_time: = 0.0).(agent, null) -> void: + path_offset := 0.0, + prediction_time := 0.0).(agent, null) -> void: self.path = path self.path_offset = path_offset self.prediction_time = prediction_time func _calculate_steering(acceleration: GSTTargetAcceleration) -> GSTTargetAcceleration: - var location: = ( + var location := ( agent.position if prediction_time == 0 else agent.position + (agent.linear_velocity * prediction_time)) - var distance: = path.calculate_distance(location, path_param) - var target_distance: = distance + path_offset + var distance := path.calculate_distance(location, path_param) + var target_distance := distance + path_offset - var target_position: = path.calculate_target_position(path_param, target_distance) + var target_position := path.calculate_target_position(path_param, target_distance) if arrive_enabled and path.open: if path_offset >= 0: diff --git a/project/src/behaviors/GSTLookWhereYouGo.gd b/project/src/Behaviors/GSTLookWhereYouGo.gd similarity index 88% rename from project/src/behaviors/GSTLookWhereYouGo.gd rename to project/src/Behaviors/GSTLookWhereYouGo.gd index 058becf..9c03af4 100644 --- a/project/src/behaviors/GSTLookWhereYouGo.gd +++ b/project/src/Behaviors/GSTLookWhereYouGo.gd @@ -12,5 +12,5 @@ func _calculate_steering(accel: GSTTargetAcceleration) -> GSTTargetAcceleration: accel.set_zero() return accel else: - var orientation: = atan2(agent.linear_velocity.x, -agent.linear_velocity.y) + var orientation := atan2(agent.linear_velocity.x, -agent.linear_velocity.y) return _match_orientation(accel, orientation) diff --git a/project/src/behaviors/GSTMatchOrientation.gd b/project/src/Behaviors/GSTMatchOrientation.gd similarity index 85% rename from project/src/behaviors/GSTMatchOrientation.gd rename to project/src/Behaviors/GSTMatchOrientation.gd index 8185dc9..ac89974 100644 --- a/project/src/behaviors/GSTMatchOrientation.gd +++ b/project/src/Behaviors/GSTMatchOrientation.gd @@ -15,14 +15,14 @@ func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void: func _match_orientation(acceleration: GSTTargetAcceleration, desired_orientation: float) -> GSTTargetAcceleration: - var rotation: = wrapf(desired_orientation - agent.orientation, -PI, PI) + var rotation := wrapf(desired_orientation - agent.orientation, -PI, PI) - var rotation_size: = abs(rotation) + var rotation_size := abs(rotation) if rotation_size <= alignment_tolerance: acceleration.set_zero() else: - var desired_rotation: = agent.max_angular_speed + var desired_rotation := agent.max_angular_speed if rotation_size <= deceleration_radius: desired_rotation *= rotation_size / deceleration_radius @@ -31,7 +31,7 @@ func _match_orientation(acceleration: GSTTargetAcceleration, desired_orientation acceleration.angular = (desired_rotation - agent.angular_velocity) / time_to_reach - var limited_acceleration: = abs(acceleration.angular) + var limited_acceleration := abs(acceleration.angular) if limited_acceleration > agent.max_angular_acceleration: acceleration.angular *= agent.max_angular_acceleration / limited_acceleration diff --git a/project/src/behaviors/GSTPriority.gd b/project/src/Behaviors/GSTPriority.gd similarity index 84% rename from project/src/behaviors/GSTPriority.gd rename to project/src/Behaviors/GSTPriority.gd index 4cb84df..cbe91ea 100644 --- a/project/src/behaviors/GSTPriority.gd +++ b/project/src/Behaviors/GSTPriority.gd @@ -4,13 +4,13 @@ class_name GSTPriority # acceleration. -var _behaviors: = [] +var _behaviors := [] var last_selected_index: int var threshold_for_zero: float -func _init(agent: GSTSteeringAgent, threshold_for_zero: = 0.001).(agent) -> void: +func _init(agent: GSTSteeringAgent, threshold_for_zero := 0.001).(agent) -> void: self.threshold_for_zero = threshold_for_zero @@ -26,11 +26,11 @@ func get_behavior_at(index: int) -> GSTSteeringBehavior: func _calculate_steering(accel: GSTTargetAcceleration) -> GSTTargetAcceleration: - var threshold_squared: = threshold_for_zero * threshold_for_zero + var threshold_squared := threshold_for_zero * threshold_for_zero last_selected_index = -1 - var size: = _behaviors.size() + var size := _behaviors.size() if size > 0: for i in range(size): diff --git a/project/src/behaviors/GSTPursue.gd b/project/src/Behaviors/GSTPursue.gd similarity index 75% rename from project/src/behaviors/GSTPursue.gd rename to project/src/Behaviors/GSTPursue.gd index 84b2efd..1e0f53b 100644 --- a/project/src/behaviors/GSTPursue.gd +++ b/project/src/Behaviors/GSTPursue.gd @@ -12,20 +12,20 @@ var max_predict_time: float func _init( agent: GSTSteeringAgent, target: GSTSteeringAgent, - max_predict_time: = 1.0).(agent) -> void: + max_predict_time := 1.0).(agent) -> void: self.target = target self.max_predict_time = max_predict_time func _calculate_steering(acceleration: GSTTargetAcceleration) -> GSTTargetAcceleration: - var target_position: = target.position - var distance_squared: = (target_position - agent.position).length_squared() + var target_position := target.position + var distance_squared := (target_position - agent.position).length_squared() - var speed_squared: = agent.linear_velocity.length_squared() - var predict_time: = max_predict_time + var speed_squared := agent.linear_velocity.length_squared() + var predict_time := max_predict_time if speed_squared > 0: - var predict_time_squared: = distance_squared / speed_squared + var predict_time_squared := distance_squared / speed_squared if predict_time_squared < max_predict_time * max_predict_time: predict_time = sqrt(predict_time_squared) diff --git a/project/src/behaviors/GSTSeek.gd b/project/src/Behaviors/GSTSeek.gd similarity index 100% rename from project/src/behaviors/GSTSeek.gd rename to project/src/Behaviors/GSTSeek.gd diff --git a/project/src/behaviors/GSTSeparation.gd b/project/src/Behaviors/GSTSeparation.gd similarity index 80% rename from project/src/behaviors/GSTSeparation.gd rename to project/src/Behaviors/GSTSeparation.gd index 9d9a573..7aa6692 100644 --- a/project/src/behaviors/GSTSeparation.gd +++ b/project/src/Behaviors/GSTSeparation.gd @@ -8,7 +8,7 @@ class_name GSTSeparation # # In effect, all neighbors produce a single repelling force. -var decay_coefficient: = 1.0 +var decay_coefficient := 1.0 var acceleration: GSTTargetAcceleration @@ -25,12 +25,12 @@ func _calculate_steering(acceleration: GSTTargetAcceleration) -> GSTTargetAccele func report_neighbor(neighbor: GSTSteeringAgent) -> bool: - var to_agent: = agent.position - neighbor.position + var to_agent := agent.position - neighbor.position - var distance_squared: = to_agent.length_squared() - var max_acceleration: = agent.max_linear_acceleration + var distance_squared := to_agent.length_squared() + var max_acceleration := agent.max_linear_acceleration - var strength: = decay_coefficient / distance_squared + var strength := decay_coefficient / distance_squared if strength > max_acceleration: strength = max_acceleration diff --git a/project/src/GSTAgentLocation.gd b/project/src/GSTAgentLocation.gd index df804c5..9a6261e 100644 --- a/project/src/GSTAgentLocation.gd +++ b/project/src/GSTAgentLocation.gd @@ -2,5 +2,5 @@ class_name GSTAgentLocation # Data type to represent an agent with a location and an orientation -var position: = Vector3.ZERO -var orientation: = 0.0 +var position := Vector3.ZERO +var orientation := 0.0 diff --git a/project/src/GSTGroupBehavior.gd b/project/src/GSTGroupBehavior.gd index 5a38843..6e98159 100644 --- a/project/src/GSTGroupBehavior.gd +++ b/project/src/GSTGroupBehavior.gd @@ -5,7 +5,7 @@ class_name GSTGroupBehavior var proximity: GSTProximity -var _callback: = funcref(self, "report_neighbor") +var _callback := funcref(self, "report_neighbor") func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent) -> void: diff --git a/project/src/GSTPath.gd b/project/src/GSTPath.gd index 1f6e502..bc5cd57 100644 --- a/project/src/GSTPath.gd +++ b/project/src/GSTPath.gd @@ -15,8 +15,8 @@ var _nearest_point_on_segment: Vector3 var _nearest_point_on_path: Vector3 -func _init(waypoints: Array, is_open: = false) -> void: - open = is_open +func _init(waypoints: Array, open := false) -> void: + self.open = open create_path(waypoints) _nearest_point_on_segment = waypoints[0] _nearest_point_on_path = waypoints[0] @@ -39,8 +39,8 @@ func create_path(waypoints: Array) -> void: elif open: break else: - current = waypoints.front() - var segment: = GSTSegment.new(previous, current) + current = waypoints[0] + var segment := GSTSegment.new(previous, current) length += segment.length segment.cumulative_length = length _segments.append(segment) @@ -53,7 +53,7 @@ func calculate_distance(agent_current_position: Vector3, path_parameter: Diction var nearest_segment: GSTSegment for i in range(_segments.size()): var segment: GSTSegment = _segments[i] - var distance_squared: = _calculate_point_segment_distance_squared( + var distance_squared := _calculate_point_segment_distance_squared( segment.begin, segment.end, agent_current_position @@ -65,7 +65,7 @@ func calculate_distance(agent_current_position: Vector3, path_parameter: Diction nearest_segment = segment path_parameter.segment_index = i - var length_on_path: = ( + var length_on_path := ( nearest_segment.cumulative_length - _nearest_point_on_path.distance_to(nearest_segment.end)) @@ -93,7 +93,7 @@ func calculate_target_position(param: Dictionary, target_distance: float) -> Vec if not desired_segment: desired_segment = _segments.back() - var distance: = desired_segment.cumulative_length - target_distance + var distance := desired_segment.cumulative_length - target_distance return ( (desired_segment.begin - desired_segment.end) * @@ -110,8 +110,8 @@ func get_end_point() -> Vector3: func _calculate_point_segment_distance_squared(start: Vector3, end: Vector3, position: Vector3) -> float: _nearest_point_on_segment = start - var start_end: = end - start - var start_end_length_squared: = start_end.length_squared() + var start_end := end - start + var start_end_length_squared := start_end.length_squared() if start_end_length_squared != 0: var t = (position - start).dot(start_end) / start_end_length_squared _nearest_point_on_segment += start_end * clamp(t, 0, 1) diff --git a/project/src/GSTSteeringAgent.gd b/project/src/GSTSteeringAgent.gd index 68c787a..55f5347 100644 --- a/project/src/GSTSteeringAgent.gd +++ b/project/src/GSTSteeringAgent.gd @@ -3,12 +3,12 @@ class_name GSTSteeringAgent # Extended agent data type that adds velocity, speed, and size data -var zero_linear_speed_threshold: = 0.01 -var max_linear_speed: = 0.0 -var max_linear_acceleration: = 0.0 -var max_angular_speed: = 0.0 -var max_angular_acceleration: = 0.0 -var linear_velocity: = Vector3.ZERO -var angular_velocity: = 0.0 -var bounding_radius: = 0.0 -var tagged: = false +var zero_linear_speed_threshold := 0.01 +var max_linear_speed := 0.0 +var max_linear_acceleration := 0.0 +var max_angular_speed := 0.0 +var max_angular_acceleration := 0.0 +var linear_velocity := Vector3.ZERO +var angular_velocity := 0.0 +var bounding_radius := 0.0 +var tagged := false diff --git a/project/src/GSTSteeringBehavior.gd b/project/src/GSTSteeringBehavior.gd index 961c49a..b8ac9e0 100644 --- a/project/src/GSTSteeringBehavior.gd +++ b/project/src/GSTSteeringBehavior.gd @@ -2,7 +2,7 @@ class_name GSTSteeringBehavior # Base class to calculate how an AI agent steers itself. -var enabled: = true +var enabled := true var agent: GSTSteeringAgent diff --git a/project/src/GSTTargetAcceleration.gd b/project/src/GSTTargetAcceleration.gd index a9caccf..4a6c74b 100644 --- a/project/src/GSTTargetAcceleration.gd +++ b/project/src/GSTTargetAcceleration.gd @@ -2,8 +2,8 @@ class_name GSTTargetAcceleration # A linear and angular amount of acceleration. -var linear: = Vector3.ZERO -var angular: = 0.0 +var linear := Vector3.ZERO +var angular := 0.0 func set_zero() -> void: diff --git a/project/src/GSTUtils.gd b/project/src/GSTUtils.gd index b366ff5..f63caf1 100644 --- a/project/src/GSTUtils.gd +++ b/project/src/GSTUtils.gd @@ -3,8 +3,8 @@ class_name GSTUtils static func clampedv3(vector: Vector3, limit: float) -> Vector3: - var length_squared: = vector.length_squared() - var limit_squared: = limit * limit + var length_squared := vector.length_squared() + var limit_squared := limit * limit if length_squared > limit_squared: vector *= sqrt(limit_squared / length_squared) return vector diff --git a/project/src/proximities/GSTInfiniteProximity.gd b/project/src/Proximities/GSTInfiniteProximity.gd similarity index 79% rename from project/src/proximities/GSTInfiniteProximity.gd rename to project/src/Proximities/GSTInfiniteProximity.gd index 0dd9b17..f873ee4 100644 --- a/project/src/proximities/GSTInfiniteProximity.gd +++ b/project/src/Proximities/GSTInfiniteProximity.gd @@ -8,10 +8,10 @@ func _init(agent: GSTSteeringAgent, agents: Array).(agent, agents) -> void: func find_neighbors(callback: FuncRef) -> int: - var neighbor_count: = 0 - var agent_count: = agents.size() + var neighbor_count := 0 + var agent_count := agents.size() for i in range(agent_count): - var current_agent: = agents[i] as GSTSteeringAgent + var current_agent := agents[i] as GSTSteeringAgent if current_agent != agent: if callback.call_func(current_agent): diff --git a/project/src/proximities/GSTProximity.gd b/project/src/Proximities/GSTProximity.gd similarity index 95% rename from project/src/proximities/GSTProximity.gd rename to project/src/Proximities/GSTProximity.gd index f746410..df40908 100644 --- a/project/src/proximities/GSTProximity.gd +++ b/project/src/Proximities/GSTProximity.gd @@ -5,7 +5,7 @@ class_name GSTProximity var agent: GSTSteeringAgent -var agents: = [] +var agents := [] func _init(agent: GSTSteeringAgent, agents: Array) -> void: diff --git a/project/src/proximities/GSTRadiusProximity.gd b/project/src/Proximities/GSTRadiusProximity.gd similarity index 73% rename from project/src/proximities/GSTRadiusProximity.gd rename to project/src/Proximities/GSTRadiusProximity.gd index 300fd11..511f8c0 100644 --- a/project/src/proximities/GSTRadiusProximity.gd +++ b/project/src/Proximities/GSTRadiusProximity.gd @@ -4,9 +4,9 @@ class_name GSTRadiusProximity # they lie within the specified radius. -var radius: = 0.0 +var radius := 0.0 -var _last_frame: = 0 +var _last_frame := 0 var _scene_tree: SceneTree @@ -16,22 +16,22 @@ func _init(agent: GSTSteeringAgent, agents: Array, radius: float).(agent, agents func find_neighbors(callback: FuncRef) -> int: - var agent_count: = agents.size() - var neighbor_count: = 0 + var agent_count := agents.size() + var neighbor_count := 0 - var current_frame: = _scene_tree.get_frame() if _scene_tree else -_last_frame + var current_frame := _scene_tree.get_frame() if _scene_tree else -_last_frame if current_frame != _last_frame: _last_frame = current_frame - var owner_position: = agent.position + var owner_position := agent.position for i in range(agent_count): - var current_agent: = agents[i] as GSTSteeringAgent + var current_agent := agents[i] as GSTSteeringAgent if current_agent != agent: - var distance_squared: = owner_position.distance_squared_to(current_agent.position) + var distance_squared := owner_position.distance_squared_to(current_agent.position) - var range_to: = radius + current_agent.bounding_radius + var range_to := radius + current_agent.bounding_radius if distance_squared < range_to * range_to: if callback.call_func(current_agent):