Godot Version
4.3
Question
I have fully working UI with a singleton to keep information stored just I now to calculate at the end of the level the score, I can get it to transfer time left into the score, but it does it in one go, I want it to countdown the time left and at the same time add that to the score until the time reaches 0?
Here’s the UI code:
extends CanvasLayer
class_name UI
# References
@onready var Lives = $LIVES
@onready var Score = $SCORE
@onready var Coins = $COINS
@onready var TimeNo = $TIMENO
@onready var WorldNo = $WORLDNO
@onready var Timenode = $Timer
@onready var total_time_seconds : int = 400
@export var WorldName: String
func _ready():
WorldNo.text = WorldName
TimeNo.text = str(total_time_seconds)
total_time_seconds = LevelData.countdown_value
func _process(delta):
LevelData.countdown_value = total_time_seconds
update_coin_display(GameManager.coins)
update_life_display(GameManager.lives)
update_scored_display(GameManager.score)
GameManager.gain_coins.connect(update_coin_display)
GameManager.gain_life.connect(update_life_display)
GameManager.gain_points.connect(update_scored_display)
if GameManager.level_finished == true:
finished_level(delta)
GameManager.level_finished = false
return
func update_scored_display(points_scored):
Score.text = str(GameManager.score)
func update_coin_display(coins_gained):
Coins.text = str(GameManager.coins)
func update_life_display(life_gained):
Lives.text = str(GameManager.lives)
func reset_timer():
total_time_seconds = 400
func _on_timer_timeout():
total_time_seconds -= 1
var m = int(total_time_seconds / 60)
var s = total_time_seconds + m / 60
TimeNo.text = "%03d" % s
func finished_level(delta):
print("connected")
var countup_score = total_time_seconds
Timenode.stop()
GameManager.on_points_scored(countup_score)