extends RichTextLabel @export var current_score = 0 @export var current_second_score = 0 @export var current_score_per_second: float = 0 @export var current_second_usage = 0 @export var current_usage_per_second: float = 0 @export var total_score = 0 @export var prev_second_scores: Array @export var prev_second_usages: Array @onready var score_per_second = $"../Score Per Second" @onready var sps_timer = $"../Score Per Second/SPSTimer" @onready var narration = $"../Narration" # Called when the node enters the scene tree for the first time. func _ready(): pass # Replace with function body. # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(_delta): pass func update(score): if score == 0: sps_timer.start() score_per_second.visible = true elif score >= 0: # only count positive scores in SPS current_second_score += score total_score += score current_score += score update_text(current_score) func update_text(_score_num): text = "Energy: " + str(current_score) score_per_second.text = "Energy per second: " + str(current_score_per_second) func _on_interface_ready(): pass # Replace with function body. func _on_score_update(click_value): update(click_value) func _on_level_1_gl_1_click(value): #print("Received value " + str(value) + " from level 1 generators") update(value) func _on_level_1_al_1_analyze(value): #print("Received value " + str(value) + " from level 1 analyzers") update(0-value) func _on_sps_timer_timeout(): var loc_current_second = current_second_score current_second_score = 0 if len(prev_second_scores) >= 5: prev_second_scores = prev_second_scores.slice(1,5) prev_second_scores.append(loc_current_second) var total_second_score = 0 var num_scores = 0 for s in prev_second_scores: total_second_score += s num_scores += 1 if num_scores <= 0: current_score_per_second = 0 else: var real_current_second_score: float = float(total_second_score) / num_scores print("Total second score: " + str(total_second_score) + ", number of scores: " + str(num_scores) + ", real score: " + str(real_current_second_score)) current_score_per_second = (floor(real_current_second_score * 100)/100) sps_timer.start()