From 24f5e910dd8f575adc483f768422ab51fdf905cc Mon Sep 17 00:00:00 2001 From: altaf-creator Date: Sat, 13 Apr 2024 14:55:31 +0700 Subject: Initial commit. Exists: NumberNode, Player, dragging and dropping, joining NumberNodes --- Scripts/Player.gd | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Scripts/Player.gd (limited to 'Scripts/Player.gd') diff --git a/Scripts/Player.gd b/Scripts/Player.gd new file mode 100644 index 0000000..e422ba8 --- /dev/null +++ b/Scripts/Player.gd @@ -0,0 +1,39 @@ +extends Node +class_name Player + +@export var max_distance : float +@export var line : Line2D +var target : NumberNode +var legal : bool + +func _ready(): + GlobalVariables.player = self + +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: + target.join_from($"..") + + 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 -- cgit v1.2.3