summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/game_data.gd13
-rw-r--r--scripts/game_over.gd5
-rw-r--r--scripts/game_over.gd.uid1
-rw-r--r--scripts/player.gd1
-rw-r--r--scripts/title.gd5
-rw-r--r--scripts/title.gd.uid1
-rw-r--r--scripts/ui_panel.gd12
7 files changed, 35 insertions, 3 deletions
diff --git a/scripts/game_data.gd b/scripts/game_data.gd
index 0ed0f61..f03eaa7 100644
--- a/scripts/game_data.gd
+++ b/scripts/game_data.gd
@@ -4,9 +4,14 @@ var game_stats_config = preload("res://resources/game_stats_config.tres")
signal life_changed
signal morale_changed
-var _life : int = game_stats_config.starting_life
-var _morale : int = game_stats_config.starting_morale
-var _current_wave : int = 1
+var _life : int
+var _morale : int
+var _current_wave : int
+
+func reset():
+ _life = game_stats_config.starting_life
+ _morale = game_stats_config.starting_morale
+ _current_wave = 1
func get_life() -> int:
return _life
@@ -29,6 +34,8 @@ func add_morale(amount: int):
func subtract_morale(amount: int):
_morale -= amount
emit_signal("morale_changed")
+ if (_morale < 1):
+ get_tree().change_scene_to_file("res://scenes/game_over.tscn")
func get_current_wave() -> int:
return _current_wave
diff --git a/scripts/game_over.gd b/scripts/game_over.gd
new file mode 100644
index 0000000..9e00c37
--- /dev/null
+++ b/scripts/game_over.gd
@@ -0,0 +1,5 @@
+extends Control
+
+func _input(event):
+ if event.is_action_pressed("ui_accept"):
+ get_tree().change_scene_to_file("res://scenes/title.tscn")
diff --git a/scripts/game_over.gd.uid b/scripts/game_over.gd.uid
new file mode 100644
index 0000000..b126122
--- /dev/null
+++ b/scripts/game_over.gd.uid
@@ -0,0 +1 @@
+uid://d4ayvqargsfbd
diff --git a/scripts/player.gd b/scripts/player.gd
index f399f02..b26beac 100644
--- a/scripts/player.gd
+++ b/scripts/player.gd
@@ -24,6 +24,7 @@ var tower_ids = {
signal curr_tile(tile_state)
func _ready():
+ GameData.reset()
_max_x = map_config.grid_width * map_config.tile_size
_max_y = map_config.grid_height * map_config.tile_size
position = position.snapped(Vector2.ONE * map_config.tile_size)
diff --git a/scripts/title.gd b/scripts/title.gd
new file mode 100644
index 0000000..8242145
--- /dev/null
+++ b/scripts/title.gd
@@ -0,0 +1,5 @@
+extends Control
+
+func _input(event):
+ if event.is_action_pressed("ui_accept"):
+ get_tree().change_scene_to_file("res://scenes/game.tscn")
diff --git a/scripts/title.gd.uid b/scripts/title.gd.uid
new file mode 100644
index 0000000..163f43d
--- /dev/null
+++ b/scripts/title.gd.uid
@@ -0,0 +1 @@
+uid://cxmpltan4gkpt
diff --git a/scripts/ui_panel.gd b/scripts/ui_panel.gd
index 6d3ea5a..d28812b 100644
--- a/scripts/ui_panel.gd
+++ b/scripts/ui_panel.gd
@@ -12,3 +12,15 @@ func _ready():
$HBoxContainer/Texture.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
$HBoxContainer/VBoxContainer/Label.text = desc
$HBoxContainer/VBoxContainer/Label2.text = str(cost)
+ print(get_theme_stylebox("panel").bg_color)
+ $ColorRect.color = get_theme_stylebox("panel").bg_color
+ $ColorRect.modulate.a = 0.0
+
+ GameData.connect("life_changed", Callable(self, "_update_affordability"))
+ _update_affordability()
+
+func _update_affordability():
+ if (GameData.get_life() >= cost):
+ $ColorRect.modulate.a = 0.0
+ else:
+ $ColorRect.modulate.a = 0.75