Fixed vines spawning inactively at some point

This commit is contained in:
Melvin Weiß 2025-10-22 01:45:25 +02:00
parent 1ea01c30d6
commit 248b1915b6
4 changed files with 17 additions and 20 deletions

View file

@ -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

View file

@ -1,13 +1,17 @@
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
for child in get_children():
queue_free()
# Spread in all directions where the given vine is not yet present

View file

@ -1,4 +1,5 @@
class_name Petal extends GridNode
@export var vine : Vine
@export var vine_resource : PackedScene
var activated = false

View file

@ -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)