Add countdown timer for each stage

This commit is contained in:
Moe Poi ~ 2023-10-19 00:37:40 +07:00
parent 1eb77ac6b8
commit e84c9f4996
20 changed files with 169 additions and 6 deletions

View file

@ -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"]

View file

@ -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"]

View file

@ -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"]

View file

@ -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"]

View file

@ -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"]

View file

@ -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"]

View file

@ -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

View file

@ -2,6 +2,7 @@ extends Node
var game = {
"duration": 300,
"health": 6,
"resource": 100,
"spawn_timer": 3.0,

View file

@ -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")

View file

@ -2,6 +2,7 @@ extends Node
var game = {
"duration": 300,
"health": 6,
"resource": 100,
"spawn_timer": 3.0,

View file

@ -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")

View file

@ -2,6 +2,7 @@ extends Node
var game = {
"duration": 300,
"health": 6,
"resource": 100,
"spawn_timer": 3.0,

View file

@ -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")

View file

@ -2,6 +2,7 @@ extends Node
var game = {
"duration": 300,
"health": 6,
"resource": 100,
"spawn_timer": 3.0,

View file

@ -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")

View file

@ -2,6 +2,7 @@ extends Node
var game = {
"duration": 300,
"health": 6,
"resource": 100,
"spawn_timer": 3.0,

View file

@ -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")

View file

@ -2,6 +2,7 @@ extends Node
var game = {
"duration": 300,
"health": 6,
"resource": 100,
"spawn_timer": 3.0,

View file

@ -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")

View file

@ -0,0 +1,5 @@
extends Control
func update_duration(time: float):
$Duration/Label.text = "%d:%02d" % [floor(time / 60), int(time) % 60]