diff options
Diffstat (limited to 'Scripts/Generator.gd')
-rw-r--r-- | Scripts/Generator.gd | 69 |
1 files changed, 65 insertions, 4 deletions
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)) |