summaryrefslogtreecommitdiff
path: root/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Scripts')
-rw-r--r--Scripts/Generator.gd10
-rw-r--r--Scripts/GlobalVariables.gd6
-rw-r--r--Scripts/NumberArea.gd20
-rw-r--r--Scripts/NumberNode.gd66
-rw-r--r--Scripts/Player.gd39
-rw-r--r--Scripts/Test.gd6
6 files changed, 147 insertions, 0 deletions
diff --git a/Scripts/Generator.gd b/Scripts/Generator.gd
new file mode 100644
index 0000000..cb46eff
--- /dev/null
+++ b/Scripts/Generator.gd
@@ -0,0 +1,10 @@
+extends Node
+class_name Generator
+
+@export var numbernode : NumberNode
+
+func _ready():
+ pass # Replace with function body.
+
+func generate():
+ pass
diff --git a/Scripts/GlobalVariables.gd b/Scripts/GlobalVariables.gd
new file mode 100644
index 0000000..6a77bc6
--- /dev/null
+++ b/Scripts/GlobalVariables.gd
@@ -0,0 +1,6 @@
+extends Node
+
+## When player is dragging to find other [NumberNodes]
+var is_snapping : bool = false
+## Player, please assign yourself here at _ready():
+var player : Player
diff --git a/Scripts/NumberArea.gd b/Scripts/NumberArea.gd
new file mode 100644
index 0000000..443fada
--- /dev/null
+++ b/Scripts/NumberArea.gd
@@ -0,0 +1,20 @@
+extends Area2D
+
+var parent : NumberNode
+
+func _ready():
+ parent = $".."
+
+func _on_mouse_entered():
+ if !parent.do_scanning:
+ return
+
+ if GlobalVariables.is_snapping && GlobalVariables.player.legal:
+ GlobalVariables.player.target = parent
+
+func _on_mouse_exited():
+ if !parent.do_scanning:
+ return
+
+ if GlobalVariables.is_snapping:
+ GlobalVariables.player.target = null
diff --git a/Scripts/NumberNode.gd b/Scripts/NumberNode.gd
new file mode 100644
index 0000000..ca80530
--- /dev/null
+++ b/Scripts/NumberNode.gd
@@ -0,0 +1,66 @@
+extends Node2D
+class_name NumberNode
+
+@export_group("Values")
+@export var value : int
+@export var modifier : int
+enum Operations {
+ NONE,
+ ADDITION,
+ SUBTRACTION,
+ MULTIPLICATION,
+ DIVISION,
+}
+@export var modifier_operation : Operations
+## Scan for mouse as a target. Uncheck if player / AI.
+@export var do_scanning : bool = true
+
+@export_group("Visuals")
+@export_subgroup("Visual Nodes")
+@export var label : Label
+@export var label_modifier : Label
+@export var sprite : Sprite2D
+@export var sprite_modifier : Sprite2D
+@export_subgroup("Visual Values")
+@export var color : Color = Color.BLACK
+@export var min_scale : float
+@export var max_scale : float
+
+func _ready():
+ update_visuals()
+
+func _process(_delta):
+ pass
+
+func join_from(node : NumberNode):
+ node.value += self.value
+
+ if self.modifier_operation == Operations.ADDITION:
+ node.value += self.modifier
+ if self.modifier_operation == Operations.SUBTRACTION:
+ node.value -= self.modifier
+ if self.modifier_operation == Operations.MULTIPLICATION:
+ node.value = node.value * self.modifier
+ if self.modifier_operation == Operations.DIVISION:
+ node.value = roundi(float(node.value) / float(self.modifier))
+
+ node.position = self.position
+ node.update_visuals()
+
+ queue_free()
+
+func update_visuals():
+ label.text = str(self.value)
+ sprite.modulate = color
+
+ if self.modifier_operation == Operations.ADDITION:
+ label_modifier.text = "+ " + str(self.modifier)
+ if self.modifier_operation == Operations.SUBTRACTION:
+ label_modifier.text = "- " + str(self.modifier)
+ if self.modifier_operation == Operations.MULTIPLICATION:
+ label_modifier.text = "× " + str(self.modifier)
+ if self.modifier_operation == Operations.DIVISION:
+ label_modifier.text = "÷ " + str(self.modifier)
+ if self.modifier_operation == Operations.NONE:
+ sprite_modifier.visible = false
+ label_modifier.visible = false
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
diff --git a/Scripts/Test.gd b/Scripts/Test.gd
new file mode 100644
index 0000000..b71b53a
--- /dev/null
+++ b/Scripts/Test.gd
@@ -0,0 +1,6 @@
+extends Node
+
+@export var target : NumberNode
+
+func _ready():
+ target.join_from($"..")