diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-04-22 16:34:25 +0200 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-04-22 16:34:25 +0200 |
commit | c8a316e4b8987dad963656a34665fa0e23dedcb1 (patch) | |
tree | 569af4b4f37d21079b6aedfad5164e94b50b6cb8 /Scenes/Entities/Objects/Vines.gd | |
parent | f27937e6e9b6a7146dd09fc711d2d293ecf5abbf (diff) |
update
Diffstat (limited to 'Scenes/Entities/Objects/Vines.gd')
-rw-r--r-- | Scenes/Entities/Objects/Vines.gd | 53 |
1 files changed, 53 insertions, 0 deletions
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() |