From cc5cb04f0faa9529521de03b85abc97721673857 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Mon, 9 Jan 2023 18:10:15 +0000 Subject: [PATCH] Add winning condition --- levels/Level0A.tscn | 1 + ui/Hud.gd | 9 ++++++++- ui/Hud.tscn | 13 ++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/levels/Level0A.tscn b/levels/Level0A.tscn index 6ff0154..b8abc7e 100644 --- a/levels/Level0A.tscn +++ b/levels/Level0A.tscn @@ -120,3 +120,4 @@ navpoly = SubResource( 4 ) navpoly = SubResource( 3 ) [node name="Hud" parent="." instance=ExtResource( 8 )] +needed_coins = 20 diff --git a/ui/Hud.gd b/ui/Hud.gd index a296a39..00c98f0 100644 --- a/ui/Hud.gd +++ b/ui/Hud.gd @@ -8,9 +8,14 @@ export var num_days = 5 export var next_level = "" +export var needed_coins = 50 + func add_coin(amount: int): coin += amount $HudInner/Panel/LabelCoin.text = str(coin) + + if coin >= needed_coins: + self._win() var hp: int = 3 @@ -46,9 +51,11 @@ func _ready(): sch.postie_times = postie_times sch.days_on_this_level = num_days + $HudInner/Panel/LabelCoinNeed.text = "need: " + str(needed_coins) + var w2d: World2D = get_world_2d() - # random place to put it, but needed to get our navigation working: Navigation2DServer.map_set_edge_connection_margin(w2d.navigation_map, 10.0) + # random place to put it, but needed to get our navigation working: func _on_TryAgainButton_pressed() -> void: diff --git a/ui/Hud.tscn b/ui/Hud.tscn index 4e4d2be..b371131 100644 --- a/ui/Hud.tscn +++ b/ui/Hud.tscn @@ -29,9 +29,19 @@ margin_left = 50.0 margin_top = 24.0 margin_right = 90.0 margin_bottom = 51.0 +rect_pivot_offset = Vector2( 6, 23 ) custom_fonts/font = ExtResource( 1 ) text = "0" +[node name="LabelCoinNeed" type="Label" parent="HudInner/Panel"] +margin_left = 21.0 +margin_top = 53.0 +margin_right = 61.0 +margin_bottom = 80.0 +rect_pivot_offset = Vector2( 6, 23 ) +custom_fonts/font = ExtResource( 1 ) +text = "need: 0" + [node name="Coin" type="Sprite" parent="HudInner/Panel"] position = Vector2( 31, 37 ) texture = ExtResource( 2 ) @@ -43,7 +53,7 @@ margin_right = -8.0 margin_bottom = -88.0 [node name="HpBar" type="Node2D" parent="HudInner/Panel"] -position = Vector2( 31, 69 ) +position = Vector2( 31, 106 ) [node name="Sprite" type="Sprite" parent="HudInner/Panel/HpBar"] texture = ExtResource( 5 ) @@ -58,6 +68,7 @@ texture = ExtResource( 5 ) [node name="GameOverDialogue" type="Panel" parent="HudInner"] pause_mode = 2 +visible = false margin_left = 544.0 margin_top = 360.0 margin_right = 1064.0