summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraltaf-creator <dev@altafcreator.com>2024-04-13 18:49:03 +0700
committeraltaf-creator <dev@altafcreator.com>2024-04-13 18:49:03 +0700
commitc5a806528af8a4de5f903d26cd33edb7e0bb6597 (patch)
tree619f07a7a7f8b2e65fc97e9f04212d2c7c8c686e
parent24f5e910dd8f575adc483f768422ab51fdf905cc (diff)
unfinished map generator
-rw-r--r--Levels/game.tscn64
-rw-r--r--Reusable Scenes/number_node.tscn30
-rw-r--r--Scripts/GameLoop.gd11
-rw-r--r--Scripts/Generator.gd69
-rw-r--r--Scripts/GlobalVariables.gd3
-rw-r--r--Scripts/NumberNode.gd16
6 files changed, 135 insertions, 58 deletions
diff --git a/Levels/game.tscn b/Levels/game.tscn
index 66640f9..e624884 100644
--- a/Levels/game.tscn
+++ b/Levels/game.tscn
@@ -1,16 +1,27 @@
-[gd_scene load_steps=4 format=3 uid="uid://rd1m2fu22g1s"]
+[gd_scene load_steps=6 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/Generator.gd" id="1_uaslf"]
[ext_resource type="Script" path="res://Scripts/Player.gd" id="3_j3fp5"]
+[ext_resource type="Script" path="res://Scripts/GameLoop.gd" id="3_u7xnc"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ludyn"]
size = Vector2(38, 38)
[node name="MainNode2D" type="Node2D"]
-position = Vector2(162, 105)
+
+[node name="Generator" type="Node" parent="."]
+script = ExtResource("1_uaslf")
+numbernode = ExtResource("1_j877y")
+min_nodes = 100
+max_nodes = 100
+
+[node name="GameLoop" type="Node" parent="."]
+script = ExtResource("3_u7xnc")
[node name="Player" parent="." instance=ExtResource("1_j877y")]
-position = Vector2(393, 42)
+z_index = 4096
+position = Vector2(63, 658)
do_scanning = false
color = Color(0, 0.329412, 0, 1)
@@ -19,53 +30,20 @@ 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)
+points = PackedVector2Array(0, 0, 0, 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="PlayerArea2D" type="Area2D" parent="Player"]
+collision_layer = 2
+collision_mask = 2
+collision_priority = 9999.0
-[node name="Node" type="Node" parent="."]
+[node name="CollisionShape2D" type="CollisionShape2D" parent="Player/PlayerArea2D"]
+shape = SubResource("RectangleShape2D_ludyn")
[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
index 7ab9497..9564505 100644
--- a/Reusable Scenes/number_node.tscn
+++ b/Reusable Scenes/number_node.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=5 format=3 uid="uid://ccvoi0qmvlxmj"]
+[gd_scene load_steps=7 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"]
@@ -7,6 +7,12 @@
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ld6aj"]
size = Vector2(66, 66)
+[sub_resource type="CircleShape2D" id="CircleShape2D_mh4p4"]
+radius = 29.41
+
+[sub_resource type="CircleShape2D" id="CircleShape2D_y33cg"]
+radius = 130.8
+
[node name="NumberNode" type="Node2D" node_paths=PackedStringArray("label", "label_modifier", "sprite", "sprite_modifier")]
script = ExtResource("1_7p1bu")
label = NodePath("Label")
@@ -14,6 +20,22 @@ label_modifier = NodePath("Label2")
sprite = NodePath("Sprite2D")
sprite_modifier = NodePath("Sprite2D2")
+[node name="Area2D" type="Area2D" parent="."]
+script = ExtResource("3_2viuw")
+
+[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
+shape = SubResource("RectangleShape2D_ld6aj")
+
+[node name="ShapeCast2D" type="ShapeCast2D" parent="."]
+shape = SubResource("CircleShape2D_mh4p4")
+target_position = Vector2(0, 0)
+collide_with_areas = true
+
+[node name="ShapeCast2D2" type="ShapeCast2D" parent="."]
+shape = SubResource("CircleShape2D_y33cg")
+target_position = Vector2(0, 0)
+collide_with_areas = true
+
[node name="Sprite2D" type="Sprite2D" parent="."]
modulate = Color(0, 0, 0, 1)
scale = Vector2(0.3, 0.3)
@@ -55,11 +77,5 @@ 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/GameLoop.gd b/Scripts/GameLoop.gd
new file mode 100644
index 0000000..ea5e157
--- /dev/null
+++ b/Scripts/GameLoop.gd
@@ -0,0 +1,11 @@
+extends Node
+class_name GameLoop
+
+@export var turns : int
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ GlobalVariables.gameloop = self
+
+func _process(_delta):
+ pass
diff --git a/Scripts/Generator.gd b/Scripts/Generator.gd
index cb46eff..c236f7c 100644
--- a/Scripts/Generator.gd
+++ b/Scripts/Generator.gd
@@ -1,10 +1,71 @@
extends Node
class_name Generator
-@export var numbernode : NumberNode
+@export_group("Scenes")
+@export var numbernode : PackedScene
-func _ready():
- pass # Replace with function body.
+@export_group("Values")
+@export var max_pos_tries : int
+@export_subgroup("Node Count")
+@export var min_nodes : int
+@export var max_nodes : int
+
+var started : bool = false
+
+func _physics_process(_delta):
+ #for i in 100:
+ # print()
+ if !started:
+ generate()
+ started = true
func generate():
- pass
+ var count : int = randi_range(min_nodes, max_nodes)
+ print(count)
+
+ for i in count:
+ var is_big : bool = false
+
+ if randf() < 0.1:
+ is_big = true
+
+ var new : NumberNode = numbernode.instantiate()
+
+ if is_big:
+ new.position = Vector2(randf_range(30, 1250), randf_range(30, 690))
+ else:
+ new.position = Vector2(randf_range(30, 1250), randf_range(30, 690)) # disgusting hardcoded values, or not really?
+
+ get_node(GlobalVariables.NODE).add_child(new)
+
+ var shape_cast : ShapeCast2D = new.get_node("ShapeCast2D")
+
+ if !is_big: check_position_and_retry(new, shape_cast, 0)
+
+ new.value = randi_range(0, 10)
+ if is_big:
+ new.value *= 20
+ new.modifier_operation = clamp(abs(roundi(randfn(0, 10))) - 7, 0, 4)
+
+ if new.modifier_operation == NumberNode.Operations.DIVISION:
+ new.modifier = randi_range(1, 3)
+ else:
+ new.modifier = snapped(randf_range(-3, 3), 0.1)
+
+ new.update_visuals()
+
+func check_position_and_retry(node : NumberNode, shape_cast : ShapeCast2D, tries : int = 0):
+ shape_cast.force_shapecast_update()
+
+ var collision_count = shape_cast.get_collision_count()
+ print(node.name + " " + str(collision_count))
+ if collision_count > 1:
+ node.queue_free() # TODO: failed? screw you! DIE!!!!
+ #tries += 1
+
+ #node.position = Vector2(randf_range(0, 1280), randf_range(0, 720)) # disgusting hardcoded values, or not really?
+ #shape_cast.position = Vector2.ZERO
+ #shape_cast.global_position = node.global_position
+ #shape_cast.force_shapecast_update()
+ #check_position_and_retry(node, shape_cast, tries)
+ #print("retried! attempt: " + str(tries))
diff --git a/Scripts/GlobalVariables.gd b/Scripts/GlobalVariables.gd
index 6a77bc6..7f8a305 100644
--- a/Scripts/GlobalVariables.gd
+++ b/Scripts/GlobalVariables.gd
@@ -1,6 +1,9 @@
extends Node
+const NODE = "/root/MainNode2D/"
+
## When player is dragging to find other [NumberNodes]
var is_snapping : bool = false
## Player, please assign yourself here at _ready():
var player : Player
+var gameloop : GameLoop
diff --git a/Scripts/NumberNode.gd b/Scripts/NumberNode.gd
index ca80530..41c5d4a 100644
--- a/Scripts/NumberNode.gd
+++ b/Scripts/NumberNode.gd
@@ -3,7 +3,7 @@ class_name NumberNode
@export_group("Values")
@export var value : int
-@export var modifier : int
+@export var modifier : float
enum Operations {
NONE,
ADDITION,
@@ -36,11 +36,11 @@ func join_from(node : NumberNode):
node.value += self.value
if self.modifier_operation == Operations.ADDITION:
- node.value += self.modifier
+ node.value += roundi(self.modifier)
if self.modifier_operation == Operations.SUBTRACTION:
- node.value -= self.modifier
+ node.value -= roundi(self.modifier)
if self.modifier_operation == Operations.MULTIPLICATION:
- node.value = node.value * self.modifier
+ node.value = roundi(float(node.value) * self.modifier)
if self.modifier_operation == Operations.DIVISION:
node.value = roundi(float(node.value) / float(self.modifier))
@@ -55,12 +55,20 @@ func update_visuals():
if self.modifier_operation == Operations.ADDITION:
label_modifier.text = "+ " + str(self.modifier)
+ sprite_modifier.visible = true
+ label_modifier.visible = true
if self.modifier_operation == Operations.SUBTRACTION:
label_modifier.text = "- " + str(self.modifier)
+ sprite_modifier.visible = true
+ label_modifier.visible = true
if self.modifier_operation == Operations.MULTIPLICATION:
label_modifier.text = "× " + str(self.modifier)
+ sprite_modifier.visible = true
+ label_modifier.visible = true
if self.modifier_operation == Operations.DIVISION:
label_modifier.text = "÷ " + str(self.modifier)
+ sprite_modifier.visible = true
+ label_modifier.visible = true
if self.modifier_operation == Operations.NONE:
sprite_modifier.visible = false
label_modifier.visible = false