Update project to follow GDScript guidelines closer

Used `var variable := 0.0` as discussed in the Godot issue, instead of
`var variable: = 0.0`.

Mostly these are minor/cosmetic changes, but I've also reorganized the
folder structure (naming of folders) to reflect our guidelines, plus
made some minor changes to the demo codes. Still work in progress.
This commit is contained in:
Răzvan C. Rădulescu 2020-01-16 10:44:44 +02:00
parent 0a8551e5c9
commit 1a37b2bee0
72 changed files with 618 additions and 541 deletions

View File

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

View File

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

View File

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

View File

@ -1,7 +1,5 @@
[gd_resource type="StyleBoxLine" format=2]
[resource]
color = Color( 1, 1, 1, 0.196078 )
thickness = 2

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@ 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 ShipType := preload("res://demos/PursueSeek/Ship.gd")
onready var ships := [$Player, $Pursuer, $Seeker]
var _clones := {}

View File

@ -1,4 +1,4 @@
extends "res://demos/pursue_vs_seek/Ship.gd"
extends "res://demos/PursueSeek/Ship.gd"
# Controls the player ship's movements based on player input.

View File

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

View File

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

View File

@ -1,4 +1,4 @@
extends "res://demos/pursue_vs_seek/Ship.gd"
extends "res://demos/PursueSeek/Ship.gd"
# Represents a ship that chases after the player.

View File

@ -8,13 +8,13 @@ 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(
@ -23,8 +23,6 @@ func _init() -> void:
)
)
func _ready() -> void:
var rng := RandomNumberGenerator.new()
rng.randomize()
@ -42,9 +40,10 @@ func _ready() -> void:
func set_behavior_mode(mode: int) -> void:
behavior_mode = mode
if not is_inside_tree():
return
if spawner:
behavior_mode = mode
match mode:
Mode.SEEK:
for child in spawner.get_children():
@ -55,16 +54,18 @@ func set_behavior_mode(mode: int) -> void:
func set_max_linear_speed(value: float) -> void:
max_linear_speed = value
if not is_inside_tree():
return
if spawner:
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:
max_linear_accel = value
for child in spawner.get_children():
child.agent.max_linear_acceleration = value

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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