the screen clock now has random glitches
authorEduardo <[email protected]>
Fri, 9 Feb 2024 02:00:18 +0000 (03:00 +0100)
committerEduardo <[email protected]>
Fri, 9 Feb 2024 02:00:18 +0000 (03:00 +0100)
levels/ui.gd [new file with mode: 0644]

diff --git a/levels/ui.gd b/levels/ui.gd
new file mode 100644 (file)
index 0000000..9838283
--- /dev/null
@@ -0,0 +1,65 @@
+extends Control
+
+@export var battery := 100
+@onready var dateLabel := $HBoxContainer/Date
+@onready var batteryLabel := $HBoxContainer/Battery
+@onready var timeLabel := $Time
+@onready var nightmareLabel := $NightmareText
+@onready var rightTopLabel := $RightTopText
+@onready var rightBottomLabel := $RightBottomText
+
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+       batteryLabel.text = "  ⚡ " + str(battery) + "%"
+
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+func _process(delta):
+       pass
+
+
+# each second
+func _on_timer_timeout():
+       timeLabel.set_text(set_rand_timer())
+
+
+func set_rand_timer() -> String:
+       var random := randf()
+       var block: String = "?"
+       var text: String
+
+       if .01 < random && random < .02:
+               block = "▓"
+       elif .02 < random && random < .03:
+               block = "▒"
+       elif .03 < random && random < .04:
+               block = "░"
+       elif .04 < random && random < .05:
+               block = "█"
+
+       random = randf() * 10
+       if 0 < random && random < 1:
+               text = block + "?:??"
+       elif 1 < random && random < 2:
+               text = "?" + block + ":??"
+       elif 2 < random && random < 3:
+               text = "??:" + block + "?"
+       elif 3 < random && random < 4:
+               text = "??:?" + block
+       else:
+               text = "??:??"
+
+       random = randf() * 10
+       if 0 < random && random < 1:
+               text += " AM"
+       elif 2 < random && random < 3:
+               text += " PM"
+       elif 6 < random && random < 7:
+               text += " " + block + "M"
+       else:
+               text += timeLabel.get_text().substr(
+                       len(timeLabel.get_text()) - 3, len(timeLabel.get_text()) - 1
+               )
+
+       return text