2020-01-16 09:44:44 +01:00
|
|
|
extends KinematicBody2D
|
|
|
|
|
|
|
|
|
2020-02-11 18:33:25 +01:00
|
|
|
var face: GSAIFace
|
|
|
|
var agent := GSAIKinematicBody2DAgent.new(self)
|
2020-01-16 09:44:44 +01:00
|
|
|
|
2020-02-11 18:33:25 +01:00
|
|
|
var _accel := GSAITargetAcceleration.new()
|
2020-01-16 18:31:02 +01:00
|
|
|
var _angular_drag := 0.1
|
2020-01-16 09:44:44 +01:00
|
|
|
var _cannon: Rect2
|
2020-02-03 17:07:43 +01:00
|
|
|
var _color: Color
|
2020-01-16 09:44:44 +01:00
|
|
|
|
|
|
|
onready var collision_shape := $CollisionShape2D
|
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
var radius = collision_shape.shape.radius
|
|
|
|
_cannon = Rect2(Vector2(-5, 0), Vector2(10, -radius*2))
|
2020-02-03 17:07:43 +01:00
|
|
|
_color = collision_shape.outer_color
|
2020-01-16 09:44:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
2020-02-06 20:46:21 +01:00
|
|
|
face.calculate_steering(_accel)
|
2020-02-07 15:15:03 +01:00
|
|
|
agent._apply_steering(_accel, delta)
|
2020-01-16 09:44:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _draw() -> void:
|
2020-02-03 17:07:43 +01:00
|
|
|
draw_rect(_cannon, _color)
|
2020-01-16 09:44:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
func setup(
|
2020-02-11 18:33:25 +01:00
|
|
|
player_agent: GSAIAgentLocation,
|
2020-01-16 09:44:44 +01:00
|
|
|
align_tolerance: float,
|
|
|
|
deceleration_radius: float,
|
2020-01-22 17:55:49 +01:00
|
|
|
angular_accel_max: float,
|
|
|
|
angular_speed_max: float
|
2020-01-16 09:44:44 +01:00
|
|
|
) -> void:
|
2020-02-11 18:33:25 +01:00
|
|
|
face = GSAIFace.new(agent, player_agent)
|
2020-01-16 09:44:44 +01:00
|
|
|
|
|
|
|
face.alignment_tolerance = align_tolerance
|
|
|
|
face.deceleration_radius = deceleration_radius
|
|
|
|
|
2020-01-22 17:55:49 +01:00
|
|
|
agent.angular_acceleration_max = angular_accel_max
|
|
|
|
agent.angular_speed_max = angular_speed_max
|
2020-02-06 20:54:12 +01:00
|
|
|
agent.angular_drag_percentage = _angular_drag
|