Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/coin/coin.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[sub_resource type="CircleShape2D" id="CircleShape2D_5w0o8"]
radius = 46.72

[node name="Coin" type="Area2D"]
[node name="Coin" type="Area2D" groups=["coins"]]
collision_layer = 2
script = ExtResource("1_4bks0")

Expand Down
1 change: 1 addition & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ window/stretch/mode="canvas_items"
[global_group]

players=""
coins="Coins that must be collected to win the level"

[input]

Expand Down
15 changes: 3 additions & 12 deletions scripts/rules_goals/game_logic.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ extends Node
## Should you win the game by collecting coins?
@export var win_by_collecting_coins: bool = false

# HACK: the step needs to be 0.9 for displaying a slider.
# TODO: When the game is updated to Godot 4.6, add prefer_slider hint
## How many coins to collect for winning?
## If zero, all the coins must be collected.[br]
## [b]Note:[/b] if you set this to a number bigger than the actual coins,
## the game won't be winnable.
@export_range(0, 100, 0.9, "or_greater") var coins_to_win: int = 0
@export_range(0, 100, 1, "or_greater") var coins_to_win: int = 0

## Should you win the game by reaching a flag?[br]
## If the option to win by collecting coins is also set, then it will only be
Expand Down Expand Up @@ -44,13 +44,6 @@ func _set_lives(new_lives):
Global.lives = lives


func _get_all_coins(node, accumulator = []):
if node is Coin:
accumulator.append(node)
for child in node.get_children():
_get_all_coins(child, accumulator)


# Called when the node enters the scene tree for the first time.
func _ready():
if Engine.is_editor_hint():
Expand All @@ -65,9 +58,7 @@ func _ready():
if win_by_collecting_coins:
Global.coin_collected.connect(_on_coin_collected)
if coins_to_win == 0:
var coins = []
_get_all_coins(get_parent(), coins)
coins_to_win = coins.size()
coins_to_win = get_tree().get_node_count_in_group(&"coins")
if win_by_reaching_flag:
Global.flag_raised.connect(_on_flag_raised)

Expand Down