diff --git a/scenes/stages/stage_1.tscn b/scenes/stages/stage_1.tscn index c60d7ec..1eb6273 100644 --- a/scenes/stages/stage_1.tscn +++ b/scenes/stages/stage_1.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=10 format=3 uid="uid://btdewn34d67m"] +[gd_scene load_steps=11 format=3 uid="uid://btdewn34d67m"] [ext_resource type="Script" path="res://scripts/stages/1/game_manager.gd" id="1_aosti"] [ext_resource type="TileSet" uid="uid://2u7m4ggcr08j" path="res://scenes/stages/stage_1.tres" id="2_3jjum"] @@ -7,6 +7,7 @@ [ext_resource type="PackedScene" uid="uid://cd5r1v6f8hahx" path="res://scenes/ui/tower_menu.tscn" id="5_3w5lp"] [ext_resource type="PackedScene" uid="uid://cy88k4uxt1v37" path="res://scenes/ui/game_stats.tscn" id="6_hbxxi"] [ext_resource type="PackedScene" uid="uid://bvoenhbaqiqj2" path="res://scenes/towers/placement/placement.tscn" id="6_mao4r"] +[ext_resource type="PackedScene" uid="uid://bigsx1yvw0pvg" path="res://scenes/ui/game_duration.tscn" id="7_8kqnd"] [ext_resource type="PackedScene" uid="uid://cikgeqqhctm7k" path="res://scenes/base/base.tscn" id="8_rsf1n"] [sub_resource type="Curve2D" id="Curve2D_csucy"] @@ -50,6 +51,8 @@ visible = false [node name="GameStats" parent="CanvasLayer" instance=ExtResource("6_hbxxi")] metadata/_edit_use_anchors_ = true +[node name="GameDuration" parent="CanvasLayer" instance=ExtResource("7_8kqnd")] + [node name="Placements" type="Node2D" parent="."] [node name="placement" parent="Placements" instance=ExtResource("6_mao4r")] @@ -72,4 +75,8 @@ position = Vector2(1179, 543) [node name="base3" parent="Bases" instance=ExtResource("8_rsf1n")] position = Vector2(1178, 460) +[node name="Duration" type="Timer" parent="."] +one_shot = true + [connection signal="timeout" from="Path2D/Timer" to="Path2D" method="_on_timer_timeout"] +[connection signal="timeout" from="Duration" to="." method="_on_duration_timeout"] diff --git a/scenes/stages/stage_2.tscn b/scenes/stages/stage_2.tscn index a431f75..61a467a 100644 --- a/scenes/stages/stage_2.tscn +++ b/scenes/stages/stage_2.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=13 format=3 uid="uid://bj5auw303w08w"] +[gd_scene load_steps=14 format=3 uid="uid://bj5auw303w08w"] [ext_resource type="Script" path="res://scripts/stages/2/game_manager.gd" id="1_4r6ye"] [ext_resource type="Texture2D" uid="uid://bq6hnxbt4w37u" path="res://assets/tileset/snowland/Snowland@64x64.png" id="1_d077v"] @@ -8,6 +8,7 @@ [ext_resource type="PackedScene" uid="uid://cd5r1v6f8hahx" path="res://scenes/ui/tower_menu.tscn" id="3_wmghq"] [ext_resource type="PackedScene" uid="uid://cy88k4uxt1v37" path="res://scenes/ui/game_stats.tscn" id="4_puhii"] [ext_resource type="PackedScene" uid="uid://cikgeqqhctm7k" path="res://scenes/base/base.tscn" id="6_e20hd"] +[ext_resource type="PackedScene" uid="uid://bigsx1yvw0pvg" path="res://scenes/ui/game_duration.tscn" id="7_y7bof"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_amj2r"] texture = ExtResource("1_d077v") @@ -287,6 +288,8 @@ visible = false [node name="GameStats" parent="CanvasLayer" instance=ExtResource("4_puhii")] metadata/_edit_use_anchors_ = true +[node name="GameDuration" parent="CanvasLayer" instance=ExtResource("7_y7bof")] + [node name="Placements" type="Node2D" parent="."] [node name="placement" parent="Placements" instance=ExtResource("2_4fmnc")] @@ -315,5 +318,9 @@ position = Vector2(552, 679) [node name="base4" parent="Bases" instance=ExtResource("6_e20hd")] position = Vector2(509, 680) +[node name="Duration" type="Timer" parent="."] +one_shot = true + [connection signal="timeout" from="Path2D/Timer" to="Path2D" method="_on_timer_timeout"] [connection signal="timeout" from="Path2D2/Timer" to="Path2D2" method="_on_timer_timeout"] +[connection signal="timeout" from="Duration" to="." method="_on_duration_timeout"] diff --git a/scenes/stages/stage_3.tscn b/scenes/stages/stage_3.tscn index ebe70ad..ac68d55 100644 --- a/scenes/stages/stage_3.tscn +++ b/scenes/stages/stage_3.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=3 uid="uid://bxk5llqn5csgu"] +[gd_scene load_steps=13 format=3 uid="uid://bxk5llqn5csgu"] [ext_resource type="Texture2D" uid="uid://bq6hnxbt4w37u" path="res://assets/tileset/snowland/Snowland@64x64.png" id="1_l1d1t"] [ext_resource type="Script" path="res://scripts/stages/3/game_manager.gd" id="1_u4jwa"] @@ -6,6 +6,7 @@ [ext_resource type="PackedScene" uid="uid://cd5r1v6f8hahx" path="res://scenes/ui/tower_menu.tscn" id="3_eupq3"] [ext_resource type="Script" path="res://scripts/stages/3/summon.gd" id="3_wyim2"] [ext_resource type="PackedScene" uid="uid://cy88k4uxt1v37" path="res://scenes/ui/game_stats.tscn" id="4_2c35u"] +[ext_resource type="PackedScene" uid="uid://bigsx1yvw0pvg" path="res://scenes/ui/game_duration.tscn" id="7_w8rhw"] [ext_resource type="PackedScene" uid="uid://bvoenhbaqiqj2" path="res://scenes/towers/placement/placement.tscn" id="8_mm6r8"] [ext_resource type="PackedScene" uid="uid://cikgeqqhctm7k" path="res://scenes/base/base.tscn" id="9_057um"] @@ -274,6 +275,8 @@ visible = false [node name="GameStats" parent="CanvasLayer" instance=ExtResource("4_2c35u")] metadata/_edit_use_anchors_ = true +[node name="GameDuration" parent="CanvasLayer" instance=ExtResource("7_w8rhw")] + [node name="Placements" type="Node2D" parent="."] [node name="placement" parent="Placements" instance=ExtResource("8_mm6r8")] @@ -296,4 +299,8 @@ position = Vector2(-37, 541) [node name="base3" parent="Bases" instance=ExtResource("9_057um")] position = Vector2(-36, 587) +[node name="Duration" type="Timer" parent="."] +one_shot = true + [connection signal="timeout" from="Path2D/Timer" to="Path2D" method="_on_timer_timeout"] +[connection signal="timeout" from="Duration" to="." method="_on_duration_timeout"] diff --git a/scenes/stages/stage_4.tscn b/scenes/stages/stage_4.tscn index 5f05d51..20a9a88 100644 --- a/scenes/stages/stage_4.tscn +++ b/scenes/stages/stage_4.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=13 format=3 uid="uid://cxo5fh50r6uxs"] +[gd_scene load_steps=14 format=3 uid="uid://cxo5fh50r6uxs"] [ext_resource type="Texture2D" uid="uid://bq6hnxbt4w37u" path="res://assets/tileset/snowland/Snowland@64x64.png" id="1_436vn"] [ext_resource type="Script" path="res://scripts/stages/4/game_manager.gd" id="1_lhtrq"] @@ -6,6 +6,7 @@ [ext_resource type="PackedScene" uid="uid://bhnv1dsggssil" path="res://scenes/ui/pause_menu.tscn" id="4_ahd74"] [ext_resource type="PackedScene" uid="uid://cd5r1v6f8hahx" path="res://scenes/ui/tower_menu.tscn" id="5_31eq4"] [ext_resource type="PackedScene" uid="uid://cy88k4uxt1v37" path="res://scenes/ui/game_stats.tscn" id="6_hgjt3"] +[ext_resource type="PackedScene" uid="uid://bigsx1yvw0pvg" path="res://scenes/ui/game_duration.tscn" id="7_5comn"] [ext_resource type="PackedScene" uid="uid://bvoenhbaqiqj2" path="res://scenes/towers/placement/placement.tscn" id="7_v8e5o"] [ext_resource type="PackedScene" uid="uid://cikgeqqhctm7k" path="res://scenes/base/base.tscn" id="8_trc1r"] @@ -281,6 +282,8 @@ visible = false [node name="GameStats" parent="CanvasLayer" instance=ExtResource("6_hgjt3")] metadata/_edit_use_anchors_ = true +[node name="GameDuration" parent="CanvasLayer" instance=ExtResource("7_5comn")] + [node name="Placements" type="Node2D" parent="."] [node name="placement" parent="Placements" instance=ExtResource("7_v8e5o")] @@ -309,5 +312,9 @@ position = Vector2(910, -44) [node name="base4" parent="Bases" instance=ExtResource("8_trc1r")] position = Vector2(951, -44) +[node name="Duration" type="Timer" parent="."] +one_shot = true + [connection signal="timeout" from="Path2D/Timer" to="Path2D" method="_on_timer_timeout"] [connection signal="timeout" from="Path2D2/Timer" to="Path2D2" method="_on_timer_timeout"] +[connection signal="timeout" from="Duration" to="." method="_on_duration_timeout"] diff --git a/scenes/stages/stage_5.tscn b/scenes/stages/stage_5.tscn index c3df829..8dc6e1a 100644 --- a/scenes/stages/stage_5.tscn +++ b/scenes/stages/stage_5.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=13 format=3 uid="uid://i18iy1wmek4s"] +[gd_scene load_steps=14 format=3 uid="uid://i18iy1wmek4s"] [ext_resource type="Script" path="res://scripts/stages/5/game_manager.gd" id="1_kectu"] [ext_resource type="Texture2D" uid="uid://bq6hnxbt4w37u" path="res://assets/tileset/snowland/Snowland@64x64.png" id="1_s0uo6"] @@ -8,6 +8,7 @@ [ext_resource type="PackedScene" uid="uid://cy88k4uxt1v37" path="res://scenes/ui/game_stats.tscn" id="4_qm2yl"] [ext_resource type="PackedScene" uid="uid://bvoenhbaqiqj2" path="res://scenes/towers/placement/placement.tscn" id="5_vmpbi"] [ext_resource type="PackedScene" uid="uid://cikgeqqhctm7k" path="res://scenes/base/base.tscn" id="6_yj08v"] +[ext_resource type="PackedScene" uid="uid://bigsx1yvw0pvg" path="res://scenes/ui/game_duration.tscn" id="7_khyn2"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_pf042"] texture = ExtResource("1_s0uo6") @@ -288,6 +289,8 @@ visible = false [node name="GameStats" parent="CanvasLayer" instance=ExtResource("4_qm2yl")] metadata/_edit_use_anchors_ = true +[node name="GameDuration" parent="CanvasLayer" instance=ExtResource("7_khyn2")] + [node name="Placements" type="Node2D" parent="."] [node name="placement" parent="Placements" instance=ExtResource("5_vmpbi")] @@ -310,5 +313,9 @@ position = Vector2(902, 682) [node name="base2" parent="Bases" instance=ExtResource("6_yj08v")] position = Vector2(947, 681) +[node name="Duration" type="Timer" parent="."] +one_shot = true + [connection signal="timeout" from="Path2D/Timer" to="Path2D" method="_on_timer_timeout"] [connection signal="timeout" from="Path2D2/Timer" to="Path2D2" method="_on_timer_timeout"] +[connection signal="timeout" from="Duration" to="." method="_on_duration_timeout"] diff --git a/scenes/stages/stage_6.tscn b/scenes/stages/stage_6.tscn index 4ef0d13..e83747c 100644 --- a/scenes/stages/stage_6.tscn +++ b/scenes/stages/stage_6.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=15 format=3 uid="uid://dcecwku0if8tg"] +[gd_scene load_steps=16 format=3 uid="uid://dcecwku0if8tg"] [ext_resource type="Script" path="res://scripts/stages/6/game_manager.gd" id="1_04mdc"] [ext_resource type="Texture2D" uid="uid://d36b03p0hs8kw" path="res://assets/tileset/ashlands/ashlands-32x32.png" id="1_a4nl1"] @@ -9,6 +9,7 @@ [ext_resource type="PackedScene" uid="uid://dud7to2ncqrqe" path="res://scenes/enemies/demon_shark.tscn" id="4_kv0eg"] [ext_resource type="PackedScene" uid="uid://bvoenhbaqiqj2" path="res://scenes/towers/placement/placement.tscn" id="5_ypi0p"] [ext_resource type="PackedScene" uid="uid://cikgeqqhctm7k" path="res://scenes/base/base.tscn" id="6_h3kdb"] +[ext_resource type="PackedScene" uid="uid://bigsx1yvw0pvg" path="res://scenes/ui/game_duration.tscn" id="8_tv86d"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_ebym7"] texture = ExtResource("1_a4nl1") @@ -683,6 +684,8 @@ visible = false [node name="GameStats" parent="CanvasLayer" instance=ExtResource("4_k4wyn")] metadata/_edit_use_anchors_ = true +[node name="GameDuration" parent="CanvasLayer" instance=ExtResource("8_tv86d")] + [node name="Placements" type="Node2D" parent="."] [node name="placement" parent="Placements" instance=ExtResource("5_ypi0p")] @@ -714,6 +717,10 @@ position = Vector2(106, 667) [node name="base4" parent="Bases" instance=ExtResource("6_h3kdb")] position = Vector2(149, 667) +[node name="Duration" type="Timer" parent="."] +one_shot = true + [connection signal="timeout" from="Path2D/Timer" to="Path2D" method="_on_timer_timeout"] [connection signal="timeout" from="Path2D2/Timer" to="Path2D2" method="_on_timer_timeout"] [connection signal="timeout" from="Path2D3/Timer" to="Path2D3" method="_on_timer_timeout"] +[connection signal="timeout" from="Duration" to="." method="_on_duration_timeout"] diff --git a/scenes/ui/game_duration.tscn b/scenes/ui/game_duration.tscn new file mode 100644 index 0000000..4779d84 --- /dev/null +++ b/scenes/ui/game_duration.tscn @@ -0,0 +1,32 @@ +[gd_scene load_steps=3 format=3 uid="uid://bigsx1yvw0pvg"] + +[ext_resource type="Script" path="res://scripts/ui/game_duration.gd" id="1_4xh30"] +[ext_resource type="Texture2D" uid="uid://d2d7ab8q2vik4" path="res://assets/icons/label_bg.png" id="2_wqq5w"] + +[node name="GameDuration" type="Control"] +layout_mode = 3 +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 0 +script = ExtResource("1_4xh30") + +[node name="Duration" type="NinePatchRect" parent="."] +offset_left = 1054.0 +offset_top = -46.0 +offset_right = 1141.0 +offset_bottom = -12.0 +texture = ExtResource("2_wqq5w") + +[node name="Label" type="Label" parent="Duration"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +text = "-" +horizontal_alignment = 1 +vertical_alignment = 1 diff --git a/scripts/stages/1/config.gd b/scripts/stages/1/config.gd index 4dbdb4d..8eaeccd 100644 --- a/scripts/stages/1/config.gd +++ b/scripts/stages/1/config.gd @@ -2,6 +2,7 @@ extends Node var game = { + "duration": 300, "health": 6, "resource": 100, "spawn_timer": 3.0, diff --git a/scripts/stages/1/game_manager.gd b/scripts/stages/1/game_manager.gd index 22de5e5..c8f98f4 100644 --- a/scripts/stages/1/game_manager.gd +++ b/scripts/stages/1/game_manager.gd @@ -4,6 +4,8 @@ extends Node2D var config_path = "res://scripts/stages/1/config.gd" var config = load(config_path).new() +@onready var duration = $Duration + var data = { "paused": false, "tower": {}, @@ -12,6 +14,11 @@ var data = { } func _ready(): + # Set Duration & Start Timer + duration.wait_time = config.game['duration'] + duration.start() + + # Connect to Signal $CanvasLayer/GameStats.connect("on_paused", on_game_paused) $CanvasLayer/PauseMenu.connect("on_resume", on_game_resume) $CanvasLayer/GameStats.set_resource(data['resource']) @@ -23,6 +30,9 @@ func _ready(): placement.connect("on_placement", on_tower_placement) $CanvasLayer/TowerMenu.connect("build_tower", on_build_tower) +func _process(_delta): + $CanvasLayer/GameDuration.update_duration($Duration.time_left) + func on_game_paused(): data['paused'] = !data['paused'] get_tree().paused = data['paused'] @@ -96,3 +106,6 @@ func on_enemy_entered_base(enemy): func on_enemy_reward(value: int): data['resource'] += value $CanvasLayer/GameStats.set_resource(data['resource']) + +func _on_duration_timeout(): + get_tree().change_scene_to_file("res://scenes/ui/victory.tscn") diff --git a/scripts/stages/2/config.gd b/scripts/stages/2/config.gd index 913133c..9c4adb2 100644 --- a/scripts/stages/2/config.gd +++ b/scripts/stages/2/config.gd @@ -2,6 +2,7 @@ extends Node var game = { + "duration": 300, "health": 6, "resource": 100, "spawn_timer": 3.0, diff --git a/scripts/stages/2/game_manager.gd b/scripts/stages/2/game_manager.gd index 67b5771..047cae6 100644 --- a/scripts/stages/2/game_manager.gd +++ b/scripts/stages/2/game_manager.gd @@ -3,6 +3,8 @@ extends Node2D var config_path = "res://scripts/stages/2/config.gd" var config = load(config_path).new() +@onready var duration = $Duration + var data = { "paused": false, "tower": {}, @@ -11,6 +13,11 @@ var data = { } func _ready(): + # Set Duration & Start Timer + duration.wait_time = config.game['duration'] + duration.start() + + # Connect to Signal $CanvasLayer/GameStats.connect("on_paused", on_game_paused) $CanvasLayer/PauseMenu.connect("on_resume", on_game_resume) $CanvasLayer/GameStats.set_resource(data['resource']) @@ -22,6 +29,9 @@ func _ready(): placement.connect("on_placement", on_tower_placement) $CanvasLayer/TowerMenu.connect("build_tower", on_build_tower) +func _process(_delta): + $CanvasLayer/GameDuration.update_duration($Duration.time_left) + func on_game_paused(): data['paused'] = !data['paused'] get_tree().paused = data['paused'] @@ -95,3 +105,6 @@ func on_enemy_entered_base(enemy): func on_enemy_reward(value: int): data['resource'] += value $CanvasLayer/GameStats.set_resource(data['resource']) + +func _on_duration_timeout(): + get_tree().change_scene_to_file("res://scenes/ui/victory.tscn") \ No newline at end of file diff --git a/scripts/stages/3/config.gd b/scripts/stages/3/config.gd index 62a30d4..e823843 100644 --- a/scripts/stages/3/config.gd +++ b/scripts/stages/3/config.gd @@ -2,6 +2,7 @@ extends Node var game = { + "duration": 300, "health": 6, "resource": 100, "spawn_timer": 3.0, diff --git a/scripts/stages/3/game_manager.gd b/scripts/stages/3/game_manager.gd index 09f30ae..e8b1a10 100644 --- a/scripts/stages/3/game_manager.gd +++ b/scripts/stages/3/game_manager.gd @@ -3,6 +3,8 @@ extends Node2D var config_path = "res://scripts/stages/3/config.gd" var config = load(config_path).new() +@onready var duration = $Duration + var data = { "paused": false, "tower": {}, @@ -11,6 +13,11 @@ var data = { } func _ready(): + # Set Duration & Start Timer + duration.wait_time = config.game['duration'] + duration.start() + + # Connect to Signal $CanvasLayer/GameStats.connect("on_paused", on_game_paused) $CanvasLayer/PauseMenu.connect("on_resume", on_game_resume) $CanvasLayer/GameStats.set_resource(data['resource']) @@ -22,6 +29,9 @@ func _ready(): placement.connect("on_placement", on_tower_placement) $CanvasLayer/TowerMenu.connect("build_tower", on_build_tower) +func _process(_delta): + $CanvasLayer/GameDuration.update_duration($Duration.time_left) + func on_game_paused(): data['paused'] = !data['paused'] get_tree().paused = data['paused'] @@ -95,3 +105,6 @@ func on_enemy_entered_base(enemy): func on_enemy_reward(value: int): data['resource'] += value $CanvasLayer/GameStats.set_resource(data['resource']) + +func _on_duration_timeout(): + get_tree().change_scene_to_file("res://scenes/ui/victory.tscn") diff --git a/scripts/stages/4/config.gd b/scripts/stages/4/config.gd index 2562a62..7e2e333 100644 --- a/scripts/stages/4/config.gd +++ b/scripts/stages/4/config.gd @@ -2,6 +2,7 @@ extends Node var game = { + "duration": 300, "health": 6, "resource": 100, "spawn_timer": 3.0, diff --git a/scripts/stages/4/game_manager.gd b/scripts/stages/4/game_manager.gd index ecb0eed..6e68087 100644 --- a/scripts/stages/4/game_manager.gd +++ b/scripts/stages/4/game_manager.gd @@ -3,6 +3,8 @@ extends Node2D var config_path = "res://scripts/stages/4/config.gd" var config = load(config_path).new() +@onready var duration = $Duration + var data = { "paused": false, "tower": {}, @@ -11,6 +13,11 @@ var data = { } func _ready(): + # Set Duration & Start Timer + duration.wait_time = config.game['duration'] + duration.start() + + # Connect to Signal $CanvasLayer/GameStats.connect("on_paused", on_game_paused) $CanvasLayer/PauseMenu.connect("on_resume", on_game_resume) $CanvasLayer/GameStats.set_resource(data['resource']) @@ -22,6 +29,9 @@ func _ready(): placement.connect("on_placement", on_tower_placement) $CanvasLayer/TowerMenu.connect("build_tower", on_build_tower) +func _process(_delta): + $CanvasLayer/GameDuration.update_duration($Duration.time_left) + func on_game_paused(): data['paused'] = !data['paused'] get_tree().paused = data['paused'] @@ -95,3 +105,6 @@ func on_enemy_entered_base(enemy): func on_enemy_reward(value: int): data['resource'] += value $CanvasLayer/GameStats.set_resource(data['resource']) + +func _on_duration_timeout(): + get_tree().change_scene_to_file("res://scenes/ui/victory.tscn") \ No newline at end of file diff --git a/scripts/stages/5/config.gd b/scripts/stages/5/config.gd index 6ed3426..ae83739 100644 --- a/scripts/stages/5/config.gd +++ b/scripts/stages/5/config.gd @@ -2,6 +2,7 @@ extends Node var game = { + "duration": 300, "health": 6, "resource": 100, "spawn_timer": 3.0, diff --git a/scripts/stages/5/game_manager.gd b/scripts/stages/5/game_manager.gd index 7b895b6..f9eee8e 100644 --- a/scripts/stages/5/game_manager.gd +++ b/scripts/stages/5/game_manager.gd @@ -3,6 +3,8 @@ extends Node2D var config_path = "res://scripts/stages/5/config.gd" var config = load(config_path).new() +@onready var duration = $Duration + var data = { "paused": false, "tower": {}, @@ -11,6 +13,11 @@ var data = { } func _ready(): + # Set Duration & Start Timer + duration.wait_time = config.game['duration'] + duration.start() + + # Connect to Signal $CanvasLayer/GameStats.connect("on_paused", on_game_paused) $CanvasLayer/PauseMenu.connect("on_resume", on_game_resume) $CanvasLayer/GameStats.set_resource(data['resource']) @@ -22,6 +29,9 @@ func _ready(): placement.connect("on_placement", on_tower_placement) $CanvasLayer/TowerMenu.connect("build_tower", on_build_tower) +func _process(_delta): + $CanvasLayer/GameDuration.update_duration($Duration.time_left) + func on_game_paused(): data['paused'] = !data['paused'] get_tree().paused = data['paused'] @@ -95,3 +105,6 @@ func on_enemy_entered_base(enemy): func on_enemy_reward(value: int): data['resource'] += value $CanvasLayer/GameStats.set_resource(data['resource']) + +func _on_duration_timeout(): + get_tree().change_scene_to_file("res://scenes/ui/victory.tscn") \ No newline at end of file diff --git a/scripts/stages/6/config.gd b/scripts/stages/6/config.gd index 322455b..0f4c17f 100644 --- a/scripts/stages/6/config.gd +++ b/scripts/stages/6/config.gd @@ -2,6 +2,7 @@ extends Node var game = { + "duration": 300, "health": 6, "resource": 100, "spawn_timer": 3.0, diff --git a/scripts/stages/6/game_manager.gd b/scripts/stages/6/game_manager.gd index 0be272a..5c77668 100644 --- a/scripts/stages/6/game_manager.gd +++ b/scripts/stages/6/game_manager.gd @@ -3,6 +3,8 @@ extends Node2D var config_path = "res://scripts/stages/6/config.gd" var config = load(config_path).new() +@onready var duration = $Duration + var data = { "paused": false, "tower": {}, @@ -11,6 +13,11 @@ var data = { } func _ready(): + # Set Duration & Start Timer + duration.wait_time = config.game['duration'] + duration.start() + + # Connect to Signal $CanvasLayer/GameStats.connect("on_paused", on_game_paused) $CanvasLayer/PauseMenu.connect("on_resume", on_game_resume) $CanvasLayer/GameStats.set_resource(data['resource']) @@ -22,6 +29,9 @@ func _ready(): placement.connect("on_placement", on_tower_placement) $CanvasLayer/TowerMenu.connect("build_tower", on_build_tower) +func _process(_delta): + $CanvasLayer/GameDuration.update_duration($Duration.time_left) + func on_game_paused(): data['paused'] = !data['paused'] get_tree().paused = data['paused'] @@ -95,3 +105,6 @@ func on_enemy_entered_base(enemy): func on_enemy_reward(value: int): data['resource'] += value $CanvasLayer/GameStats.set_resource(data['resource']) + +func _on_duration_timeout(): + get_tree().change_scene_to_file("res://scenes/ui/victory.tscn") \ No newline at end of file diff --git a/scripts/ui/game_duration.gd b/scripts/ui/game_duration.gd new file mode 100644 index 0000000..253565d --- /dev/null +++ b/scripts/ui/game_duration.gd @@ -0,0 +1,5 @@ +extends Control + + +func update_duration(time: float): + $Duration/Label.text = "%d:%02d" % [floor(time / 60), int(time) % 60] \ No newline at end of file