summaryrefslogtreecommitdiff
path: root/Scripts/Player.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Scripts/Player.gd')
-rw-r--r--Scripts/Player.gd39
1 files changed, 39 insertions, 0 deletions
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