necra-prototypes/incantation.gd
Antonio Dell'Annunziata f6c53bf5ca
All checks were successful
/ test (push) Successful in 2s
Color text when chanting
2025-03-09 10:31:55 +01:00

58 lines
1.7 KiB
GDScript

extends Path2D
signal completed
var is_mouse_in_path_follow_area: bool = false
var is_incantation_started: bool = false
var incantation_progress: float = 0.0
var is_incantation_completed: bool = false
@onready var area: Area2D = $Area2D
@onready var incantation_text: IncantationText = $IncantationText
func _ready():
area.mouse_entered.connect(func(): is_mouse_in_path_follow_area = true)
area.mouse_exited.connect(func():
is_mouse_in_path_follow_area = false
reset_incantation()
)
func _draw():
# Draws debug line accross the path in game
#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)
pass
var previous_offset: float:
set(new_value):
previous_offset = new_value
incantation_text.colored_offset = previous_offset
func _input(event):
if is_incantation_completed: return
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)
if previous_offset <= 0.0:
previous_offset = next_offset
elif next_offset - previous_offset <= 0:
return
previous_offset = next_offset
area.position = next_point
if next_point == curve.get_point_position(curve.point_count - 1):
completed.emit()
is_incantation_completed = true
func reset_incantation():
if is_incantation_completed: return
is_incantation_started = false
area.position = curve.get_point_position(0)
previous_offset = 0.0