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 += 8 * $AnimatedSprite2D.frame $CollisionShape2D.position.x += 8 $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 -= 8 * ($AnimatedSprite2D.frame + 1) $CollisionShape2D.position.x -= 8 $AnimatedSprite2D.frame_changed.connect(shrink) $AnimatedSprite2D.play_backwards() await $AnimatedSprite2D.animation_finished $AnimatedSprite2D.frame_changed.disconnect(shrink) $Timer.start() await $Timer.timeout spread() func hit_by_explosion(): if not $AnimatedSprite2D.is_playing() and $Timer.is_stopped(): retract()