53 lines
1.3 KiB
GDScript
53 lines
1.3 KiB
GDScript
extends Node2D
|
|
|
|
class_name Spot
|
|
|
|
class SpotLink:
|
|
var link_from: Node2D #Spot
|
|
var link_to: Node2D #Spot
|
|
var line: Line2D
|
|
|
|
func _init(from, to):
|
|
line = Line2D.new()
|
|
link_from = from
|
|
link_to = to
|
|
line.add_point(from.global_position)
|
|
line.add_point(to.global_position)
|
|
from.get_tree().root.call_deferred("add_child", line)
|
|
return self
|
|
|
|
var spot1 : SpotLink
|
|
var spot2 : SpotLink
|
|
var person: PersonRoot
|
|
|
|
onready var sprite: Sprite = $Circle
|
|
|
|
class MyCustomSorter:
|
|
static func sort_ascending(a, b):
|
|
if a[0] < b[0]:
|
|
return true
|
|
return false
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
var distances : Array = []
|
|
for spot in get_tree().get_nodes_in_group("spot"):
|
|
if spot != self:
|
|
distances.append([self.global_position.distance_squared_to(spot.global_position), spot])
|
|
distances.sort_custom(MyCustomSorter, "sort_ascending")
|
|
spot1 = SpotLink.new(self, distances[0][1])
|
|
spot2 = SpotLink.new(self, distances[1][1])
|
|
|
|
func _process(_delta):
|
|
sprite.self_modulate = Color.green if person != null else Color.red
|
|
|
|
|
|
# processSignalSpotHasPerson(Person)
|
|
# check the Person on the other spots
|
|
# change the color of the line2D that are and that lead to the other spots
|
|
# change this spot and other spots color appropriately
|
|
|
|
|
|
# processSignalSpotPersonLeft()
|
|
# reser that Spot and the other nearby
|