pir-serious-game-ethics/mini-game/scenes/decor/scoreUI.gd

55 lines
847 B
GDScript

extends Control
onready var label : Label = $MarginContainer/Label
onready var timer = $Timer
var game_mode
var max_time = 30
var current_time = 0
func _ready():
Signals.connect("update_score",self,"update_score")
func update_score(score: int):
label.text = String(score)
func start(mode: String):
match mode:
"score":
update_score(0)
show()
"time":
update_score(max_time)
show()
current_time = 0
timer.start()
_:
print("game_mode not recognized by scoreUI")
func set_max_time(time: int):
max_time = time
func init(mode, goal: int):
game_mode = mode
if (goal != 0):
max_time = goal
hide()
func stop():
timer.stop()
func _on_Timer_timeout() -> void:
current_time += 1
var n = max_time - current_time
if n < 0:
n = 0
update_score(n)
if n == 0:
Signals.emit_signal("win")
timer.stop()