extends Node class_name Player @export var max_distance : float @export var line : Line2D var target : NumberNode var legal : bool var gameloop : GameLoop func _ready(): GlobalVariables.player = self gameloop = GlobalVariables.gameloop func _input(event): if GlobalVariables.is_snapping: var target_pos = (line.global_position - get_viewport().get_mouse_position()) var dist = sqrt(abs(target_pos.x) * abs(target_pos.x) + abs(target_pos.y) * abs(target_pos.y)) if dist > max_distance: legal = false else: legal = true line.points[1] = Vector2(clampf(dist, 0, self.max_distance), 0) line.rotation = atan2(target_pos.y, target_pos.x) - deg_to_rad(180) if event is InputEventMouseButton && !event.pressed: GlobalVariables.is_snapping = false if target != null && gameloop.current_turns < gameloop.turns: target.join_from($"..") gameloop.current_turns += 1 line.points[1] = Vector2.ZERO if target != null: line.rotation = 0 line.points[1] = -(line.global_position - target.global_position) func _on_player_area_2d_input_event(_viewport : Node, event : InputEvent, _shape_idx : int): if event is InputEventMouseButton && event.pressed: GlobalVariables.is_snapping = true