ajout du détecteur et liaison entre les scènes
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
@tool
|
||||
extends Node2D
|
||||
class_name DetectorSignal
|
||||
|
||||
const SIGNAL_DURATION = 1
|
||||
const PARTICLES_DISTANCE = 100
|
||||
const DEFAULT_ICON = preload("res://common/icons/north-star.svg")
|
||||
const ENERGY_ICON = preload("res://common/icons/bolt.svg")
|
||||
|
||||
var started_time = 0.
|
||||
var signals : Array[DetectorSignalIndividual] = []
|
||||
|
||||
@export_tool_button("Start", "Callable") var start = func(): started_time = 0
|
||||
|
||||
func _init(region : Region, pos : Vector2):
|
||||
for e in region.entity_container.get_children():
|
||||
if e is TruckRecharge:
|
||||
print(pos)
|
||||
print(e.global_position)
|
||||
print(e.global_position.angle_to(pos))
|
||||
signals.append(
|
||||
DetectorSignalIndividual.new(
|
||||
(pos - e.global_position).normalized().angle(),
|
||||
ENERGY_ICON
|
||||
)
|
||||
)
|
||||
|
||||
func _draw():
|
||||
if started_time < SIGNAL_DURATION:
|
||||
draw_circle(
|
||||
Vector2.ZERO,
|
||||
started_time/SIGNAL_DURATION * PARTICLES_DISTANCE,
|
||||
Color(1.,1.,1.,0.5*1-started_time/SIGNAL_DURATION),
|
||||
false,
|
||||
5.
|
||||
)
|
||||
for s in signals:
|
||||
draw_texture(
|
||||
s.icon,
|
||||
Vector2.ZERO - DEFAULT_ICON.get_size()/2 + Vector2.LEFT.rotated(s.angle) * started_time/SIGNAL_DURATION * PARTICLES_DISTANCE,
|
||||
Color(1.,1.,1.,1-started_time/SIGNAL_DURATION)
|
||||
)
|
||||
|
||||
func _process(delta):
|
||||
if started_time < SIGNAL_DURATION:
|
||||
started_time += delta
|
||||
queue_redraw()
|
||||
else:
|
||||
queue_free()
|
||||
|
||||
class DetectorSignalIndividual:
|
||||
var angle : float
|
||||
var icon : Texture
|
||||
|
||||
func _init(
|
||||
_angle : float = 0.,
|
||||
_icon : Texture = DEFAULT_ICON
|
||||
):
|
||||
angle = _angle
|
||||
icon = _icon
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://c0sivthidxafm
|
||||
Reference in New Issue
Block a user