Refactored and documented blob_big.gd
This commit is contained in:
parent
b3b6998e14
commit
60e32002c1
1 changed files with 6 additions and 1 deletions
|
|
@ -5,7 +5,8 @@ var angular_speed = TAU/8
|
||||||
var lifetime = 5
|
var lifetime = 5
|
||||||
|
|
||||||
var ready_blobs = 0
|
var ready_blobs = 0
|
||||||
var num_blobs = 4
|
|
||||||
|
var num_blobs = 0
|
||||||
|
|
||||||
var particles_ended = false
|
var particles_ended = false
|
||||||
|
|
||||||
|
|
@ -13,16 +14,20 @@ func _on_target_reached():
|
||||||
ready_blobs += 1
|
ready_blobs += 1
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
# Count those children that have a "target reached" signal and connect them.
|
||||||
for child in get_children():
|
for child in get_children():
|
||||||
if "target_reached" in child:
|
if "target_reached" in child:
|
||||||
|
num_blobs += 1
|
||||||
child.connect("target_reached", _on_target_reached)
|
child.connect("target_reached", _on_target_reached)
|
||||||
$SplashSound.play()
|
$SplashSound.play()
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
|
# Once all child blobs have reached their target, start moving as one while slowly rotating.
|
||||||
if ready_blobs == num_blobs:
|
if ready_blobs == num_blobs:
|
||||||
position += (player.position - position).normalized() * speed * delta
|
position += (player.position - position).normalized() * speed * delta
|
||||||
rotate(angular_speed * delta)
|
rotate(angular_speed * delta)
|
||||||
lifetime -= delta
|
lifetime -= delta
|
||||||
|
# In the end, clear all child blobs, then the rest.
|
||||||
if lifetime < 0 and not particles_ended:
|
if lifetime < 0 and not particles_ended:
|
||||||
particles_ended = true
|
particles_ended = true
|
||||||
for child in get_children():
|
for child in get_children():
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue