summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraltaf-creator <dev@altafcreator.com>2024-04-13 14:55:31 +0700
committeraltaf-creator <dev@altafcreator.com>2024-04-13 14:55:31 +0700
commit24f5e910dd8f575adc483f768422ab51fdf905cc (patch)
tree3486579c0949ec89f3550ee94d35dc20a111ab0d
Initial commit. Exists: NumberNode, Player, dragging and dropping, joining NumberNodes
-rw-r--r--.gitattributes2
-rw-r--r--.gitignore4
-rw-r--r--Levels/game.tscn71
-rw-r--r--Reusable Scenes/number_node.tscn65
-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
-rw-r--r--icon.svg1
-rw-r--r--icon.svg.import37
-rw-r--r--project.godot32
13 files changed, 359 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..8ad74f7
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+# Normalize EOL for all files that Git considers text files.
+* text=auto eol=lf
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2010dea
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+# Godot 4+ specific ignores
+.godot/
+
+Meta/
diff --git a/Levels/game.tscn b/Levels/game.tscn
new file mode 100644
index 0000000..66640f9
--- /dev/null
+++ b/Levels/game.tscn
@@ -0,0 +1,71 @@
+[gd_scene load_steps=4 format=3 uid="uid://rd1m2fu22g1s"]
+
+[ext_resource type="PackedScene" uid="uid://ccvoi0qmvlxmj" path="res://Reusable Scenes/number_node.tscn" id="1_j877y"]
+[ext_resource type="Script" path="res://Scripts/Player.gd" id="3_j3fp5"]
+
+[sub_resource type="RectangleShape2D" id="RectangleShape2D_ludyn"]
+size = Vector2(38, 38)
+
+[node name="MainNode2D" type="Node2D"]
+position = Vector2(162, 105)
+
+[node name="Player" parent="." instance=ExtResource("1_j877y")]
+position = Vector2(393, 42)
+do_scanning = false
+color = Color(0, 0.329412, 0, 1)
+
+[node name="Player" type="Node" parent="Player" node_paths=PackedStringArray("line")]
+script = ExtResource("3_j3fp5")
+max_distance = 300.0
+line = NodePath("../Line2D")
+
+[node name="PlayerArea2D" type="Area2D" parent="Player"]
+
+[node name="CollisionShape2D" type="CollisionShape2D" parent="Player/PlayerArea2D"]
+shape = SubResource("RectangleShape2D_ludyn")
+
+[node name="Line2D" type="Line2D" parent="Player"]
+z_index = -1
+points = PackedVector2Array(0, 0, 100, 0)
+width = 20.0
+default_color = Color(0, 0, 0, 1)
+begin_cap_mode = 2
+end_cap_mode = 2
+
+[node name="NumberNode" parent="." instance=ExtResource("1_j877y")]
+position = Vector2(-4, 82)
+value = 5
+
+[node name="NumberNode2" parent="." instance=ExtResource("1_j877y")]
+position = Vector2(248, 474)
+value = 10
+
+[node name="NumberNode3" parent="." instance=ExtResource("1_j877y")]
+position = Vector2(753, 59)
+value = 100
+
+[node name="NumberNode4" parent="." instance=ExtResource("1_j877y")]
+position = Vector2(360, 241)
+
+[node name="NumberNode5" parent="." instance=ExtResource("1_j877y")]
+position = Vector2(620, 280)
+
+[node name="NumberNode6" parent="." instance=ExtResource("1_j877y")]
+position = Vector2(50, 338)
+
+[node name="NumberNode7" parent="." instance=ExtResource("1_j877y")]
+position = Vector2(260, -4)
+
+[node name="NumberNode8" parent="." instance=ExtResource("1_j877y")]
+position = Vector2(994, 4)
+value = 5
+modifier = 2
+modifier_operation = 4
+
+[node name="NumberNode9" parent="." instance=ExtResource("1_j877y")]
+position = Vector2(639, 476)
+value = 5
+
+[node name="Node" type="Node" parent="."]
+
+[connection signal="input_event" from="Player/PlayerArea2D" to="Player/Player" method="_on_player_area_2d_input_event"]
diff --git a/Reusable Scenes/number_node.tscn b/Reusable Scenes/number_node.tscn
new file mode 100644
index 0000000..7ab9497
--- /dev/null
+++ b/Reusable Scenes/number_node.tscn
@@ -0,0 +1,65 @@
+[gd_scene load_steps=5 format=3 uid="uid://ccvoi0qmvlxmj"]
+
+[ext_resource type="Script" path="res://Scripts/NumberNode.gd" id="1_7p1bu"]
+[ext_resource type="Texture2D" uid="uid://cckv0u0uvmp6p" path="res://icon.svg" id="2_d46p4"]
+[ext_resource type="Script" path="res://Scripts/NumberArea.gd" id="3_2viuw"]
+
+[sub_resource type="RectangleShape2D" id="RectangleShape2D_ld6aj"]
+size = Vector2(66, 66)
+
+[node name="NumberNode" type="Node2D" node_paths=PackedStringArray("label", "label_modifier", "sprite", "sprite_modifier")]
+script = ExtResource("1_7p1bu")
+label = NodePath("Label")
+label_modifier = NodePath("Label2")
+sprite = NodePath("Sprite2D")
+sprite_modifier = NodePath("Sprite2D2")
+
+[node name="Sprite2D" type="Sprite2D" parent="."]
+modulate = Color(0, 0, 0, 1)
+scale = Vector2(0.3, 0.3)
+texture = ExtResource("2_d46p4")
+
+[node name="Sprite2D2" type="Sprite2D" parent="."]
+modulate = Color(1, 0, 0, 1)
+position = Vector2(19, -17)
+scale = Vector2(0.26, 0.11)
+texture = ExtResource("2_d46p4")
+
+[node name="Label" type="Label" parent="."]
+anchors_preset = 8
+anchor_left = 0.5
+anchor_top = 0.5
+anchor_right = 0.5
+anchor_bottom = 0.5
+offset_left = -20.0
+offset_top = -19.0
+offset_right = 20.0
+offset_bottom = 19.0
+grow_horizontal = 2
+grow_vertical = 2
+text = "X"
+horizontal_alignment = 1
+vertical_alignment = 1
+
+[node name="Label2" type="Label" parent="."]
+anchors_preset = 2
+anchor_top = 1.0
+anchor_bottom = 1.0
+offset_left = 3.0
+offset_top = -24.0
+offset_right = 35.0
+offset_bottom = -10.0
+grow_vertical = 0
+theme_override_font_sizes/font_size = 10
+text = "X"
+horizontal_alignment = 1
+vertical_alignment = 1
+
+[node name="Area2D" type="Area2D" parent="."]
+script = ExtResource("3_2viuw")
+
+[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
+shape = SubResource("RectangleShape2D_ld6aj")
+
+[connection signal="mouse_entered" from="Area2D" to="Area2D" method="_on_mouse_entered"]
+[connection signal="mouse_exited" from="Area2D" to="Area2D" method="_on_mouse_exited"]
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($"..")
diff --git a/icon.svg b/icon.svg
new file mode 100644
index 0000000..b370ceb
--- /dev/null
+++ b/icon.svg
@@ -0,0 +1 @@
+<svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="2" width="124" height="124" rx="14" fill="#363d52" stroke="#212532" stroke-width="4"/><g transform="scale(.101) translate(122 122)"><g fill="#fff"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 813 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H447l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c3 34 55 34 58 0v-86c-3-34-55-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></g></svg>
diff --git a/icon.svg.import b/icon.svg.import
new file mode 100644
index 0000000..7e09902
--- /dev/null
+++ b/icon.svg.import
@@ -0,0 +1,37 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://cckv0u0uvmp6p"
+path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://icon.svg"
+dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1
+svg/scale=1.0
+editor/scale_with_editor_scale=false
+editor/convert_colors_with_editor_theme=false
diff --git a/project.godot b/project.godot
new file mode 100644
index 0000000..0971d0a
--- /dev/null
+++ b/project.godot
@@ -0,0 +1,32 @@
+; Engine configuration file.
+; It's best edited using the editor UI and not directly,
+; since the parameters that go here are not all obvious.
+;
+; Format:
+; [section] ; section goes between []
+; param=value ; assign values to parameters
+
+config_version=5
+
+[application]
+
+config/name="Ludum Dare 55"
+run/main_scene="res://Levels/game.tscn"
+config/features=PackedStringArray("4.2", "GL Compatibility")
+config/icon="res://icon.svg"
+
+[autoload]
+
+GlobalVariables="*res://Scripts/GlobalVariables.gd"
+
+[display]
+
+window/size/viewport_width=1280
+window/size/viewport_height=720
+window/size/mode=3
+window/stretch/mode="canvas_items"
+
+[rendering]
+
+renderer/rendering_method="gl_compatibility"
+renderer/rendering_method.mobile="gl_compatibility"