@@ -7,12 +7,12 @@ extends Node
77## Should you win the game by collecting coins?
88@export var win_by_collecting_coins : bool = false
99
10- # HACK: the step needs to be 0.9 for displaying a slider.
10+ # TODO: When the game is updated to Godot 4.6, add prefer_slider hint
1111## How many coins to collect for winning?
1212## If zero, all the coins must be collected.[br]
1313## [b]Note:[/b] if you set this to a number bigger than the actual coins,
1414## the game won't be winnable.
15- @export_range (0 , 100 , 0.9 , "or_greater" ) var coins_to_win : int = 0
15+ @export_range (0 , 100 , 1 , "or_greater" ) var coins_to_win : int = 0
1616
1717## Should you win the game by reaching a flag?[br]
1818## If the option to win by collecting coins is also set, then it will only be
@@ -44,13 +44,6 @@ func _set_lives(new_lives):
4444 Global .lives = lives
4545
4646
47- func _get_all_coins (node , accumulator = []):
48- if node is Coin :
49- accumulator .append (node )
50- for child in node .get_children ():
51- _get_all_coins (child , accumulator )
52-
53-
5447# Called when the node enters the scene tree for the first time.
5548func _ready ():
5649 if Engine .is_editor_hint ():
@@ -65,9 +58,7 @@ func _ready():
6558 if win_by_collecting_coins :
6659 Global .coin_collected .connect (_on_coin_collected )
6760 if coins_to_win == 0 :
68- var coins = []
69- _get_all_coins (get_parent (), coins )
70- coins_to_win = coins .size ()
61+ coins_to_win = get_tree ().get_node_count_in_group (& "coins" )
7162 if win_by_reaching_flag :
7263 Global .flag_raised .connect (_on_flag_raised )
7364
0 commit comments