You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

score.gd 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. extends RichTextLabel
  2. @export var current_score = 0
  3. @export var current_second_score = 0
  4. @export var current_score_per_second: float = 0
  5. @export var current_second_usage = 0
  6. @export var current_usage_per_second: float = 0
  7. @export var total_score = 0
  8. @export var prev_second_scores: Array
  9. @export var prev_second_usages: Array
  10. @onready var score_per_second = $"../Score Per Second"
  11. @onready var sps_timer = $"../Score Per Second/SPSTimer"
  12. @onready var narration = $"../Narration"
  13. # Called when the node enters the scene tree for the first time.
  14. func _ready():
  15. pass # Replace with function body.
  16. # Called every frame. 'delta' is the elapsed time since the previous frame.
  17. func _process(_delta):
  18. pass
  19. func update(score):
  20. if score == 0:
  21. sps_timer.start()
  22. score_per_second.visible = true
  23. elif score >= 0:
  24. # only count positive scores in SPS
  25. current_second_score += score
  26. total_score += score
  27. current_score += score
  28. update_text(current_score)
  29. func update_text(_score_num):
  30. text = "Energy: " + str(current_score)
  31. score_per_second.text = "Energy per second: " + str(current_score_per_second)
  32. func _on_interface_ready():
  33. pass # Replace with function body.
  34. func _on_score_update(click_value):
  35. update(click_value)
  36. func _on_level_1_gl_1_click(value):
  37. #print("Received value " + str(value) + " from level 1 generators")
  38. update(value)
  39. func _on_level_1_al_1_analyze(value):
  40. #print("Received value " + str(value) + " from level 1 analyzers")
  41. update(0-value)
  42. func _on_sps_timer_timeout():
  43. var loc_current_second = current_second_score
  44. current_second_score = 0
  45. if len(prev_second_scores) >= 5:
  46. prev_second_scores = prev_second_scores.slice(1,5)
  47. prev_second_scores.append(loc_current_second)
  48. var total_second_score = 0
  49. var num_scores = 0
  50. for s in prev_second_scores:
  51. total_second_score += s
  52. num_scores += 1
  53. if num_scores <= 0:
  54. current_score_per_second = 0
  55. else:
  56. var real_current_second_score: float = float(total_second_score) / num_scores
  57. print("Total second score: " + str(total_second_score) + ", number of scores: " + str(num_scores) + ", real score: " + str(real_current_second_score))
  58. current_score_per_second = (floor(real_current_second_score * 100)/100)
  59. sps_timer.start()