|
|
@@ -0,0 +1,31 @@ |
|
|
|
extends Node |
|
|
|
|
|
|
|
signal all_coins_picked_up |
|
|
|
|
|
|
|
export var coin_scene : PackedScene |
|
|
|
|
|
|
|
var prout := false |
|
|
|
|
|
|
|
export var spawn_on_ready := false |
|
|
|
|
|
|
|
var coins := -1 |
|
|
|
|
|
|
|
func _ready(): |
|
|
|
if spawn_on_ready: |
|
|
|
spawn_coins(null) |
|
|
|
|
|
|
|
func spawn_coins(args): |
|
|
|
yield(get_tree(), "idle_frame") |
|
|
|
if not prout: |
|
|
|
coins = 0 |
|
|
|
for spawn in get_children(): |
|
|
|
var coin = coin_scene.instance() |
|
|
|
coin.connect("picked_up", self, "on_coin_picked_up") |
|
|
|
coins += 1 |
|
|
|
spawn.add_child(coin) |
|
|
|
prout = true |
|
|
|
|
|
|
|
func on_coin_picked_up(): |
|
|
|
coins -= 1 |
|
|
|
if coins == 0: |
|
|
|
emit_signal("all_coins_picked_up") |