blob: f3b9667162d600badddcf5b4982ce91a73e1936b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
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
|