summaryrefslogtreecommitdiff
path: root/scenes/UI
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-05-21 20:45:06 -0400
committerbd <bdunahu@operationnull.com>2025-05-21 20:45:06 -0400
commit80e145ba2b85e08f895e76ba6a03bb67bc9ce9ea (patch)
treeff5f15bedd718d0cfc9daf2963dcf8b3fec88e69 /scenes/UI
parenta00b14bcf2084a1e68f57620e27956813d469aad (diff)
Add basic UI, morale / life logic
Diffstat (limited to 'scenes/UI')
-rw-r--r--scenes/UI/cursor.gd24
-rw-r--r--scenes/UI/life.gd11
-rw-r--r--scenes/UI/life.gd.uid1
-rw-r--r--scenes/UI/morale.gd11
-rw-r--r--scenes/UI/morale.gd.uid1
-rw-r--r--scenes/UI/ui.tscn39
6 files changed, 79 insertions, 8 deletions
diff --git a/scenes/UI/cursor.gd b/scenes/UI/cursor.gd
index cb0d0b4..c71eaa2 100644
--- a/scenes/UI/cursor.gd
+++ b/scenes/UI/cursor.gd
@@ -11,17 +11,23 @@ var dirs = {"move_right": Vector2.RIGHT,
"move_left": Vector2.LEFT,
"move_up": Vector2.UP,
"move_down": Vector2.DOWN}
-var towers : Dictionary
+var towers : Dictionary = {
+ "place_warlock": {
+ "scene": preload("res://scenes/defenders/warlock.tscn"),
+ "cost": 10
+ },
+ "place_wyvern": {
+ "scene": preload("res://scenes/defenders/wyvern.tscn"),
+ "cost": 15
+ }
+}
func _ready():
tile_size = grid_manager.tile_size
max_x = 20 * tile_size
max_y = 15 * tile_size
-
- towers["place_warlock"] = preload("res://scenes/defenders/warlock.tscn")
- towers["place_wyvern"] = preload("res://scenes/defenders/wyvern.tscn")
position = position.snapped(Vector2.ONE * tile_size)
- position += Vector2.ONE * tile_size / 2
+ position += Vector2(max_x / 2, max_y / 2) + Vector2(1, 0) * tile_size / 2
func _unhandled_input(event):
for dir in dirs.keys():
@@ -34,17 +40,19 @@ func _unhandled_input(event):
return
func handle_tower(tower):
- if is_valid_placement_tile():
- var tmp = tower.instantiate()
+ var tower_cost = tower["cost"]
+ if is_valid_placement_tile() && GameData.get_life() >= tower_cost:
+ var tmp = tower["scene"].instantiate()
var path = get_tree().get_root().get_node("Main/Defenders")
path.add_child(tmp)
tmp.global_position = position
grid_manager.occupy_tile(position)
+ GameData.subtract_life(tower_cost)
func handle_move(dir):
position += dir * tile_size
position.x = max(position.x, tile_size / 2)
- position.y = max(position.y, tile_size / 2)
+ position.y = max(position.y, tile_size + tile_size / 2)
position.x = min(position.x, max_x - (tile_size / 2))
position.y = min(position.y, max_y - (tile_size / 2))
diff --git a/scenes/UI/life.gd b/scenes/UI/life.gd
new file mode 100644
index 0000000..b185cda
--- /dev/null
+++ b/scenes/UI/life.gd
@@ -0,0 +1,11 @@
+extends Label
+
+func _ready():
+ GameData.connect("life_changed", Callable(self, "_on_life_changed"))
+ update_label(GameData.get_life())
+
+func _on_life_changed(new_life: int) -> void:
+ update_label(new_life)
+
+func update_label(new_life: int) -> void:
+ text = "Life:" + str(new_life)
diff --git a/scenes/UI/life.gd.uid b/scenes/UI/life.gd.uid
new file mode 100644
index 0000000..6666d8d
--- /dev/null
+++ b/scenes/UI/life.gd.uid
@@ -0,0 +1 @@
+uid://dtj2opmwvh4y1
diff --git a/scenes/UI/morale.gd b/scenes/UI/morale.gd
new file mode 100644
index 0000000..d5a8046
--- /dev/null
+++ b/scenes/UI/morale.gd
@@ -0,0 +1,11 @@
+extends Label
+
+func _ready():
+ GameData.connect("morale_changed", Callable(self, "_on_morale_changed"))
+ update_label(GameData.get_morale())
+
+func _on_life_changed(new_morale: int) -> void:
+ update_label(new_morale)
+
+func update_label(new_morale: int) -> void:
+ text = "Morale:" + str(new_morale)
diff --git a/scenes/UI/morale.gd.uid b/scenes/UI/morale.gd.uid
new file mode 100644
index 0000000..2424396
--- /dev/null
+++ b/scenes/UI/morale.gd.uid
@@ -0,0 +1 @@
+uid://b8urrbmynk327
diff --git a/scenes/UI/ui.tscn b/scenes/UI/ui.tscn
new file mode 100644
index 0000000..8e6a36b
--- /dev/null
+++ b/scenes/UI/ui.tscn
@@ -0,0 +1,39 @@
+[gd_scene load_steps=4 format=3 uid="uid://dycgp3yept14k"]
+
+[ext_resource type="Script" uid="uid://dtj2opmwvh4y1" path="res://scenes/UI/life.gd" id="1_suays"]
+[ext_resource type="Script" uid="uid://b8urrbmynk327" path="res://scenes/UI/morale.gd" id="1_yb1mt"]
+
+[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_nt14h"]
+bg_color = Color(0, 0.0117647, 0.552941, 1)
+
+[node name="PanelContainer" type="PanelContainer"]
+anchors_preset = 10
+anchor_right = 1.0
+offset_bottom = 17.0
+grow_horizontal = 2
+size_flags_vertical = 0
+theme_override_styles/panel = SubResource("StyleBoxFlat_nt14h")
+
+[node name="MarginContainer" type="MarginContainer" parent="."]
+layout_mode = 2
+theme_override_constants/margin_left = 6
+theme_override_constants/margin_top = 0
+
+[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer"]
+layout_mode = 2
+
+[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/HBoxContainer"]
+layout_mode = 2
+theme_override_constants/separation = -3
+
+[node name="Morale" type="Label" parent="MarginContainer/HBoxContainer/VBoxContainer"]
+layout_mode = 2
+theme_override_font_sizes/font_size = 8
+text = "Morale: 10"
+script = ExtResource("1_yb1mt")
+
+[node name="Life" type="Label" parent="MarginContainer/HBoxContainer/VBoxContainer"]
+layout_mode = 2
+theme_override_font_sizes/font_size = 8
+text = "Life: 20"
+script = ExtResource("1_suays")