12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- extends VBoxContainer
- # Declare member variables here. Examples:
- # var a = 2
- # var b = "text"
- onready var MAIN = find_parent("MAIN")
- onready var SHIP = find_parent("SHIP")
- var pings_max = 3
- var labels = []
- var ping_per_dist = 1 #ms
- # Called when the node enters the scene tree for the first time.
- func _ready():
- for i in range(pings_max):
- var lab = Label.new()
- add_child(lab)
- labels.append(lab)
- func _process(delta):
- var planetlist = MAIN.planets.duplicate()
- planetlist.sort_custom(self, "ping_sort")
- update_pings(planetlist)
- func update_pings(planetlist):
- var i = 0
- for l in labels:
- var planet = planetlist[i]
- l.text = str(int(get_ping(planet)))+" ms"
- l.modulate = planet.color
- i += 1
-
- func get_ping(planet):
- var ping = (planet.global_position - SHIP.global_position).length() - planet.radius
- ping *= ping_per_dist
- return ping
- func ping_sort(planet_a, planet_b):
- return get_ping(planet_a) < get_ping(planet_b)
- # Called every frame. 'delta' is the elapsed time since the previous frame.
- #func _process(delta):
- # pass
|