summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2022-06-02 02:35:03 -0600
committerDavid Luevano Alvarado <david@luevano.xyz>2022-06-02 02:35:03 -0600
commit898877f09808691a5e5d45850d27ae85f270db16 (patch)
treee4f9005273815c35327b5bdf65026c93301cb593 /src/ui
parent2c5d588bc593929a96f0e58d7d1ab52f269add55 (diff)
add food system
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/UI.tscn24
-rw-r--r--src/ui/ui.gd17
2 files changed, 41 insertions, 0 deletions
diff --git a/src/ui/UI.tscn b/src/ui/UI.tscn
new file mode 100644
index 0000000..f5b0ac3
--- /dev/null
+++ b/src/ui/UI.tscn
@@ -0,0 +1,24 @@
+[gd_scene load_steps=2 format=2]
+
+[ext_resource path="res://ui/ui.gd" type="Script" id=1]
+
+[node name="UI" type="CanvasLayer"]
+script = ExtResource( 1 )
+
+[node name="Root" type="Control" parent="."]
+anchor_right = 1.0
+anchor_bottom = 1.0
+
+[node name="StatsHUD" type="MarginContainer" parent="Root"]
+margin_left = 10.0
+margin_top = 10.0
+margin_right = 310.0
+margin_bottom = 110.0
+
+[node name="VBox" type="VBoxContainer" parent="Root/StatsHUD"]
+margin_right = 300.0
+margin_bottom = 100.0
+
+[node name="SnakeSize" type="Label" parent="Root/StatsHUD/VBox"]
+margin_right = 300.0
+margin_bottom = 14.0
diff --git a/src/ui/ui.gd b/src/ui/ui.gd
new file mode 100644
index 0000000..cb7353e
--- /dev/null
+++ b/src/ui/ui.gd
@@ -0,0 +1,17 @@
+class_name UI
+extends CanvasLayer
+
+onready var _snake_size_label: Label = $Root/StatsHUD/VBox/SnakeSize
+
+var snake_size: int = 0
+var _snake_size_fmt: String = "Snake size: %s"
+
+
+func _ready():
+ Event.connect("snake_added_new_segment", self, "_on_Snake_added_new_segment")
+ _snake_size_label.text =_snake_size_fmt % snake_size
+
+
+func _on_Snake_added_new_segment(type: String) -> void:
+ snake_size += 1
+ _snake_size_label.text =_snake_size_fmt % snake_size