From 248b1915b6f553275029dce072ea2ad49df5030a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melvin=20Wei=C3=9F?= Date: Wed, 22 Oct 2025 01:45:25 +0200 Subject: [PATCH] Fixed vines spawning inactively at some point --- utils/grid_node.gd | 21 ++++++--------------- vines_petals/bud.gd | 6 +++++- vines_petals/petal.gd | 1 + vines_petals/vine.gd | 9 +++++---- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/utils/grid_node.gd b/utils/grid_node.gd index 28f768e..1bca244 100644 --- a/utils/grid_node.gd +++ b/utils/grid_node.gd @@ -1,6 +1,6 @@ class_name GridNode extends Node2D - -@export var vine : Vine + +# Setting location and offset automatically adjusts position @export var location : Vector2 : set(new_loc): location = Global.vec_mod(new_loc, Grid.num_collumns, true) @@ -11,32 +11,23 @@ class_name GridNode extends Node2D update_position() @export var depth : int -func _get(property: StringName) -> Variant: - if property == "position": - return position - if property == "global_position": - return global_position - return null - +# Setting the global position automatically adjusts location and offset func _set(property: StringName, value: Variant) -> bool: if property == "global_position": location = Grid.get_location_from_world_pos(value) offset = Grid.get_offset_from_world_pos(value) update_position() return true - if property == "position": - update_position() - return false return false +# Generates position from location and offset func update_position(): global_position = Grid.get_world_position(location, offset) func _enter_grid() -> void: update_position() -func _init(_vine = null, _location = Vector2.ZERO, _offset = Vector2.ZERO, _depth = 0): - vine = _vine +# Constructor for Grid Nodes +func _init(_location = Vector2.ZERO, _offset = Vector2.ZERO): location = _location offset = _offset - depth = _depth diff --git a/vines_petals/bud.gd b/vines_petals/bud.gd index a47f795..4bd3b02 100644 --- a/vines_petals/bud.gd +++ b/vines_petals/bud.gd @@ -1,14 +1,18 @@ class_name Bud extends GridNode signal opened var img_path +@export var vine : Vine # Triggers when a bud is hit. Spreads the vine, then removes the bud func _on_opened(): + $EnemyHurtbox.monitorable = false + $EnemyHurtbox.monitoring = false $AnimatedSprite2D.play("open") opened.emit() spread() await $AnimatedSprite2D.animation_finished - queue_free() + for child in get_children(): + queue_free() # Spread in all directions where the given vine is not yet present func spread(): diff --git a/vines_petals/petal.gd b/vines_petals/petal.gd index bc8932c..cc2a871 100644 --- a/vines_petals/petal.gd +++ b/vines_petals/petal.gd @@ -1,4 +1,5 @@ class_name Petal extends GridNode +@export var vine : Vine @export var vine_resource : PackedScene var activated = false diff --git a/vines_petals/vine.gd b/vines_petals/vine.gd index 0ede719..697d548 100644 --- a/vines_petals/vine.gd +++ b/vines_petals/vine.gd @@ -31,7 +31,7 @@ var status_params : Dictionary = {} # When max depth is reached, everything is active from then on. var active_depth = -1 var fully_active = false -var max_depth = 50 +var max_depth = 10 # Array containings lists of sprites, using their depths as index var vine_data = [] @@ -44,7 +44,7 @@ var vine_end_data = [] func draw_vine(pos1 : Vector2, pos2 : Vector2, depth : int): var sprite = Sprite2D.new() get_tree().get_root().get_node("main").add_child(sprite) - if active_depth >= depth: + if active_depth >= depth or fully_active: sprite.texture = ResourceLoader.load(img_path_active) else: sprite.texture = ResourceLoader.load(img_path_inactive) @@ -86,7 +86,7 @@ func grow_vine_sequence(start : GridNode, target: GridNode, grow_bud = false, qu if not quick_spawn: await get_tree().create_timer(0.2).timeout - if active_depth >= depth + num_segments: + if active_depth >= depth + num_segments or fully_active: if grow_bud and target.location.y > 0 and target.location.y <= Grid.max_bud_height: spawn_bud(target.location, target.offset, depth + num_segments) else: @@ -142,6 +142,7 @@ func update_active_depth(): if data.depth == active_depth: spawn_bud(data.location, data.offset, data.depth) update_active_depth() + else: fully_active = true func _enter_tree() -> void: var data : Dictionary = status_data.pick_random() @@ -152,7 +153,7 @@ func _enter_tree() -> void: func random_vine_node_at(location): var offset = random_offset() - return GridNode.new(self, location, offset) + return GridNode.new(location, offset) func init_random(): Grid.add_vine_to(self, petal.location)