necra-prototypes/incantation.gd
Antonio Dell'Annunziata 097de25931
All checks were successful
/ test (push) Successful in 2s
Add ritual incantation
2025-03-09 09:17:55 +01:00

44 lines
1.4 KiB
GDScript

extends Path2D
var is_mouse_in_path_follow_area: bool = false
var is_incantation_started: bool = false
var incantation_progress: float = 0.0
@onready var path_follow: Node2D = $PathFollow2D
@onready var path_follow_area: Area2D = $PathFollow2D/Area2D
func _ready():
path_follow_area.mouse_entered.connect(func(): is_mouse_in_path_follow_area = true)
path_follow_area.mouse_exited.connect(func():
is_mouse_in_path_follow_area = false
reset_incantation()
)
func _draw():
var points = curve.get_baked_points()
for i in points.size():
if i == 0: continue
draw_line(points[i-1], points[i], Color.BLACK, 2.0)
var previous_offset: float
func _input(event):
if event is InputEventMouseButton:
if event.is_pressed() and is_mouse_in_path_follow_area and not is_incantation_started:
is_incantation_started = true
if event is InputEventMouseMotion and is_incantation_started:
var motion_event = event as InputEventMouseMotion
var next_point = curve.get_closest_point(to_local(motion_event.global_position))
var next_offset = curve.get_closest_offset(next_point)
print(previous_offset, " " ,next_offset)
if previous_offset <= 0.0:
previous_offset = next_offset
elif next_offset - previous_offset <= 0:
return
previous_offset = next_offset
path_follow.position = next_point
func reset_incantation():
is_incantation_started = false
path_follow.position = curve.get_point_position(0)
previous_offset = 0.0