2025-10-21 17:54:43 +02:00
|
|
|
class_name Bud extends GridNode
|
2025-10-03 16:36:28 +02:00
|
|
|
signal opened
|
2025-10-03 17:09:51 +02:00
|
|
|
var img_path
|
2025-10-03 11:31:45 +02:00
|
|
|
|
2025-10-17 12:57:41 +02:00
|
|
|
# Triggers when a bud is hit. Spreads the vine, then removes the bud
|
2025-10-03 11:31:45 +02:00
|
|
|
func _on_opened():
|
|
|
|
|
$AnimatedSprite2D.play("open")
|
2025-10-03 16:36:28 +02:00
|
|
|
opened.emit()
|
|
|
|
|
spread()
|
2025-10-03 11:31:45 +02:00
|
|
|
await $AnimatedSprite2D.animation_finished
|
|
|
|
|
queue_free()
|
2025-10-03 16:36:28 +02:00
|
|
|
|
2025-10-17 12:57:41 +02:00
|
|
|
# Spread in all directions where the given vine is not yet present
|
2025-10-03 16:36:28 +02:00
|
|
|
func spread():
|
|
|
|
|
for dir in [Vector2.UP, Vector2.DOWN, Vector2.RIGHT, Vector2.LEFT]:
|
2025-10-21 16:06:16 +02:00
|
|
|
if not vine.vine_locations.has(Global.vec_mod(location + dir, Grid.num_collumns, true)):
|
2025-10-03 16:36:28 +02:00
|
|
|
grow_to_next_bud(dir)
|
|
|
|
|
|
2025-10-17 12:57:41 +02:00
|
|
|
# Grow a vine
|
2025-10-03 16:36:28 +02:00
|
|
|
func grow_to_next_bud(dir):
|
2025-10-21 16:06:16 +02:00
|
|
|
var target_location = Global.vec_mod(location + dir, Grid.num_collumns, true)
|
|
|
|
|
var target = vine.random_vine_node_at(target_location)
|
|
|
|
|
await vine.grow_vine_sequence(self, target, true, false)
|