summaryrefslogtreecommitdiff
path: root/Scripts
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 /Scripts
parent24f5e910dd8f575adc483f768422ab51fdf905cc (diff)
unfinished map generator
Diffstat (limited to 'Scripts')
-rw-r--r--Scripts/GameLoop.gd11
-rw-r--r--Scripts/Generator.gd69
-rw-r--r--Scripts/GlobalVariables.gd3
-rw-r--r--Scripts/NumberNode.gd16
4 files changed, 91 insertions, 8 deletions
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