JAM_PROGRESS_BAR.gd 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. extends ColorRect
  2. class_name JamProgressBar
  3. onready var TOP_PANEL = find_parent("top_panel")
  4. var intersect_color = Color8(10,10,10,255)
  5. var intersect_width = 2
  6. var progress = 0.0
  7. var progress_rate = 0.2
  8. var active = false
  9. var ping_rect
  10. var time_bonus = 0.040 # per second of jam time
  11. var reward = 0
  12. var reward_sections = [
  13. 0,
  14. 0.5,
  15. 0.8,
  16. 1
  17. ]
  18. var reward_base_amounts = [
  19. 0.0,
  20. 0.3,
  21. 0.6,
  22. ]
  23. var actual_amounts = []
  24. var rates = [
  25. 2.0,
  26. 1.3,
  27. 0.4,
  28. ]
  29. var reward_colors = [
  30. Color8(50,50,50,255),
  31. Color8(250,250,0,255),
  32. Color8(250,150,0,255),
  33. ]
  34. var jam_progress_bar_color = ColorN("white")
  35. var progress_bar
  36. var reward_labels = []
  37. var ping_label
  38. # Called when the node enters the scene tree for the first time.
  39. func _ready():
  40. color = ColorN("black")
  41. progress_bar = ColorRect.new()
  42. progress_bar.color = jam_progress_bar_color
  43. progress_bar.rect_size.y = rect_size.y
  44. call_deferred("add_child",progress_bar)
  45. for i in range(reward_colors.size()):
  46. var r = ColorRect.new()
  47. r.color = reward_colors[i]
  48. var p = reward_sections[i] * rect_size.x
  49. r.rect_position.x = p
  50. var size = Vector2(reward_sections[i+1] * rect_size.x - p, rect_size.y)
  51. r.rect_size = size
  52. var shadermat = ShaderMaterial.new()
  53. shadermat.shader = load("res://multiplier.shader")
  54. r.material = shadermat
  55. call_deferred("add_child",r)
  56. var ping_label = FontedLabel.new()
  57. ping_label.rect_position.x = p
  58. ping_label.rect_size = size
  59. ping_label.font_size = rect_size.y * 0.5
  60. ping_label.align = Label.ALIGN_CENTER
  61. ping_label.valign = Label.ALIGN_CENTER
  62. ping_label.text = "ping"
  63. call_deferred("add_child",ping_label)
  64. reward_labels.append(ping_label)
  65. func activate():
  66. reward = 0
  67. actual_amounts.clear()
  68. active = true
  69. var planet = TOP_PANEL.planet
  70. for r in reward_base_amounts:
  71. var reward_with_time = r * (1 + TOP_PANEL.time_left_bar.max_time_left*time_bonus)
  72. var adjusted_per_type = reward_with_time * planet.jam_rewards[planet.jam]
  73. actual_amounts.append( adjusted_per_type)
  74. update_labels()
  75. pass
  76. func deactivate():
  77. active = false
  78. find_parent("SHIP").fuel = clamp(find_parent("SHIP").fuel +reward,0.0,1.0)
  79. reward = 0
  80. func update_labels():
  81. for l in range(len(reward_labels)):
  82. reward_labels[l].text = "+"+str(floor(actual_amounts[l] *100)/100.0)
  83. func _process(delta):
  84. if active:
  85. if ping_rect == null:
  86. ping_rect = TOP_PANEL.ping_rect
  87. progress_rate = rates[ping_rect.ring_index] / TOP_PANEL.time_left_bar.max_time_left
  88. progress_bar.rect_size.x = progress * rect_size.x
  89. progress += progress_rate * delta
  90. for i in range(len(actual_amounts)):
  91. if progress >= reward_sections[i]:
  92. print(reward)
  93. reward = max(reward,actual_amounts[i])