summaryrefslogtreecommitdiff
path: root/Scenes/Entities/Objects/Vines.gd
blob: ac2c2497798e7ed208cc2ca058dbd889597c3adb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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()