Separate ArriveDemo's drawing from root node

Closes #26
This commit is contained in:
Francois Belair 2020-02-08 18:17:39 -05:00
parent 809b0c53df
commit 7241bc754b
3 changed files with 31 additions and 15 deletions

View File

@ -1,4 +1,4 @@
extends Node2D extends Node
export(float, 0, 2000, 40) var linear_speed_max := 800.0 setget set_linear_speed_max export(float, 0, 2000, 40) var linear_speed_max := 800.0 setget set_linear_speed_max
@ -6,12 +6,8 @@ export(float, 0, 200, 2.0) var linear_acceleration_max := 80.0 setget set_linear
export(float, 0, 100, 0.1) var arrival_tolerance := 25.0 setget set_arrival_tolerance 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 export(float, 0, 500, 10) var deceleration_radius := 125.0 setget set_deceleration_radius
const COLORS := {
deceleration_radius = Color(1.0, 0.419, 0.592, 0.5),
arrival_tolerance = Color(0.278, 0.231, 0.47, 0.3)
}
onready var arriver := $Arriver onready var arriver := $Arriver
onready var target_drawer := $TargetDrawer
func _ready() -> void: func _ready() -> void:
@ -26,13 +22,7 @@ func _ready() -> void:
func _unhandled_input(event: InputEvent) -> void: func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.is_pressed(): 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) arriver.target.position = Vector3(event.position.x, event.position.y, 0)
update() target_drawer.update()
func _draw():
var target_position := Vector2(arriver.target.position.x, arriver.target.position.y)
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: func set_arrival_tolerance(value: float) -> void:

View File

@ -1,15 +1,16 @@
[gd_scene load_steps=7 format=2] [gd_scene load_steps=8 format=2]
[ext_resource path="res://demos/Arrive/Arriver.gd" type="Script" id=1] [ext_resource path="res://demos/Arrive/Arriver.gd" type="Script" id=1]
[ext_resource path="res://demos/Utils/DemoInterface.tscn" type="PackedScene" id=2] [ext_resource path="res://demos/Utils/DemoInterface.tscn" type="PackedScene" id=2]
[ext_resource path="res://demos/Arrive/ArriveDemo.gd" type="Script" id=3] [ext_resource path="res://demos/Arrive/ArriveDemo.gd" type="Script" id=3]
[ext_resource path="res://demos/Utils/BackgroudLayer.tscn" type="PackedScene" id=4] [ext_resource path="res://demos/Utils/BackgroudLayer.tscn" type="PackedScene" id=4]
[ext_resource path="res://demos/Arrive/TargetDrawer.gd" type="Script" id=5]
[ext_resource path="res://demos/Utils/CircleDraw.gd" type="Script" id=6] [ext_resource path="res://demos/Utils/CircleDraw.gd" type="Script" id=6]
[sub_resource type="CircleShape2D" id=1] [sub_resource type="CircleShape2D" id=1]
radius = 16.0 radius = 16.0
[node name="ArriveDemo" type="Node2D"] [node name="ArriveDemo" type="Node"]
script = ExtResource( 3 ) script = ExtResource( 3 )
[node name="BackgroudLayer" parent="." instance=ExtResource( 4 )] [node name="BackgroudLayer" parent="." instance=ExtResource( 4 )]
@ -26,4 +27,9 @@ inner_color = Color( 0.235294, 0.639216, 0.439216, 1 )
outer_color = Color( 0.560784, 0.870588, 0.364706, 1 ) outer_color = Color( 0.560784, 0.870588, 0.364706, 1 )
stroke = 4.0 stroke = 4.0
[node name="TargetDrawer" type="Node2D" parent="."]
script = ExtResource( 5 )
[node name="DemoInterface" parent="." instance=ExtResource( 2 )] [node name="DemoInterface" parent="." instance=ExtResource( 2 )]
text_bbcode = "Arrive Demo
Mouse click to make the [color=lime]green \"Player\"[/color] move to the [color=fuchsia]purple target[/color]"

View File

@ -0,0 +1,20 @@
extends Node2D
const COLORS := {
deceleration_radius = Color(1.0, 0.419, 0.592, 0.5),
arrival_tolerance = Color(0.278, 0.231, 0.47, 0.3)
}
var arriver: Node2D
func _ready() -> void:
yield(owner, "ready")
arriver = owner.arriver
func _draw():
var target_position := GSTUtils.to_vector2(arriver.target.position)
draw_circle(target_position, owner.deceleration_radius, COLORS.deceleration_radius)
draw_circle(target_position, owner.arrival_tolerance, COLORS.arrival_tolerance)