blob: 5e36fc249d2d088f8801d707155d869e3c6af336 (
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
54
55
56
|
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()
|