Add docstring to currently implemented code.

This commit is contained in:
Francois Belair 2019-12-16 23:12:18 -05:00
parent 9b02baaba6
commit 7520939bdd
18 changed files with 69 additions and 5 deletions

View File

@ -1,5 +1,8 @@
extends Reference
class_name AgentLocation
"""
Data type to represent an agent with a location and an orientation
"""
var position: = Vector3.ZERO

View File

@ -1,5 +1,9 @@
extends SteeringBehavior
class_name Arrive
"""
Calculates acceleration to take an agent to its target's location.
The calculation will attempt to arrive with zero remaining velocity.
"""
var target: AgentLocation

View File

@ -1,5 +1,10 @@
extends Pursue
class_name Evade
"""
Calculates acceleration to take an agent away from where a target agent will be.
The `max_predict_time` variable represents how far ahead to calculate the intersection point.
"""
func _init(agent: SteeringAgent, target: SteeringAgent, max_predict_time: = 1.0).(agent, target, max_predict_time):

View File

@ -1,5 +1,9 @@
extends MatchOrientation
class_name Face
"""
Calculates angular acceleration to rotate a target to face its target's position.
The acceleration will attempt to arrive with zero remaining angular velocity.
"""
func _init(agent: SteeringAgent, target: AgentLocation).(agent, target) -> void:

View File

@ -1,5 +1,8 @@
extends Seek
class_name Flee
"""
Calculates acceleration to take an agent directly away from a target agent.
"""
func _init(agent: SteeringAgent, target: AgentLocation).(agent, target) -> void:

View File

@ -1,5 +1,9 @@
extends SteeringBehavior
class_name MatchOrientation
"""
Calculates an angular acceleration to match an agent's orientation to its target's.
The calculation will attempt to arrive with zero remaining angular velocity.
"""
var target: AgentLocation

View File

@ -1,5 +1,10 @@
extends SteeringBehavior
class_name Pursue
"""
Calculates acceleration to take an agent to intersect with where a target agent will be.
The `max_predict_time` variable represents how far ahead to calculate the intersection point.
"""
var target: SteeringAgent

View File

@ -1,5 +1,8 @@
extends SteeringBehavior
class_name Seek
"""
Calculates acceleration to take an agent to a target agent's position as directly as possible
"""
var target: AgentLocation

View File

@ -1,4 +1,7 @@
extends StaticBody2D
"""
Draws the bounding box of the static body wall.
"""
var rect: Rect2

View File

@ -1,4 +1,7 @@
extends KinematicBody2D
"""
AI agent that seeks to move away from the player's location as directly as possible.
"""
onready var radius: = ($CollisionShape2D.shape as CircleShape2D).radius
@ -25,6 +28,9 @@ func _draw() -> void:
func _physics_process(delta: float) -> void:
if not player_agent:
return
_update_agent()
accel = flee.calculate_steering(accel)

View File

@ -1,4 +1,7 @@
extends KinematicBody2D
"""
Class to control the player in basic left/right up/down movement.
"""
onready var _radius: = ($CollisionShape2D.shape as CircleShape2D).radius

View File

@ -71,10 +71,8 @@ shape = SubResource( 3 )
[node name="SeekerSpawner" type="Node2D" parent="."]
script = ExtResource( 2 )
agent_scene = ExtResource( 4 )
player = NodePath("../Player")
[node name="FleeerSpawner" type="Node2D" parent="."]
script = ExtResource( 2 )
agent_scene = ExtResource( 6 )
player = NodePath("../Player")
agent_color = Color( 0.0980392, 0.886275, 0.517647, 1 )

View File

@ -1,8 +1,14 @@
extends Node2D
"""
Access helper class for children to access window boundaries.
"""
var camera_boundaries: Rect2
func _init() -> void:
camera_boundaries = Rect2(Vector2.ZERO, Vector2(ProjectSettings["display/window/size/width"], ProjectSettings["display/window/size/height"]))
camera_boundaries = Rect2(
Vector2.ZERO,
Vector2(ProjectSettings["display/window/size/width"], ProjectSettings["display/window/size/height"])
)

View File

@ -1,4 +1,7 @@
extends KinematicBody2D
"""
AI agent that uses the Seek behavior to hone in on the player's location as directly as possible.
"""
onready var radius: = ($CollisionShape2D.shape as CircleShape2D).radius
@ -25,6 +28,9 @@ func _draw() -> void:
func _physics_process(delta: float) -> void:
if not player_agent:
return
_update_agent()
accel = seek.calculate_steering(accel)

View File

@ -1,12 +1,14 @@
extends Node2D
"""
Instantiates and configures a number of agent scenes within the level boundaries.
"""
onready var player_agent: AgentLocation = get_node(player).player_agent
onready var player_agent: AgentLocation = owner.get_node("Player").player_agent
export(PackedScene) var agent_scene: PackedScene
export var agent_count: = 10
export var player: = NodePath()
export var min_speed: = 50.0
export var max_speed: = 125.0
export var agent_color: = Color.blue

View File

@ -1,5 +1,8 @@
extends AgentLocation
class_name SteeringAgent
"""
Extended agent data type that adds velocity and speed data.
"""
var zero_linear_speed_threshold: = 0.01

View File

@ -1,5 +1,8 @@
extends Reference
class_name SteeringBehavior
"""
Base class to calculate how an AI agent steers itself.
"""
var enabled: = true

View File

@ -1,5 +1,8 @@
extends Reference
class_name TargetAcceleration
"""
A linear and angular amount of acceleration.
"""
var linear: = Vector3.ZERO