From c8a316e4b8987dad963656a34665fa0e23dedcb1 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Mon, 22 Apr 2024 16:34:25 +0200 Subject: update --- Scenes/Entities/Objects/Vines.gd | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Scenes/Entities/Objects/Vines.gd (limited to 'Scenes/Entities/Objects/Vines.gd') diff --git a/Scenes/Entities/Objects/Vines.gd b/Scenes/Entities/Objects/Vines.gd new file mode 100644 index 0000000..ac2c249 --- /dev/null +++ b/Scenes/Entities/Objects/Vines.gd @@ -0,0 +1,53 @@ +extends StaticBody2D + + +@export_enum("up", "down", "left", "right") var spread_direction: String = "right" + + +# Called when the node enters the scene tree for the first time. +func _ready(): + add_to_group("hitables") + + if spread_direction == "up": + rotate(deg_to_rad(-90)) + elif spread_direction == "down": + rotate(deg_to_rad(90)) + elif spread_direction == "left": + rotate(deg_to_rad(180)) + elif spread_direction == "right": + rotate(deg_to_rad(0)) + + spread() + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(_delta): + pass + + +func spread(): + var grow = func(): + $CollisionShape2D.shape.size.x += 16 * $AnimatedSprite2D.frame + + $AnimatedSprite2D.frame_changed.connect(grow) + $AnimatedSprite2D.play() + await $AnimatedSprite2D.animation_finished + $AnimatedSprite2D.frame_changed.disconnect(grow) + + +func retract(): + var shrink = func(): + $CollisionShape2D.shape.size.x -= 16 * ($AnimatedSprite2D.frame + 1) + + $AnimatedSprite2D.frame_changed.connect(shrink) + $AnimatedSprite2D.play_backwards() + await $AnimatedSprite2D.animation_finished + $AnimatedSprite2D.frame_changed.disconnect(shrink) + + await get_tree().create_timer(3).timeout + spread() + + +func hit_by_explosion(): + if not $AnimatedSprite2D.is_playing(): + retract() -- cgit v1.2.3