A game created for the Godot Wild Jam #21
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

81 Zeilen
2.2KB

  1. extends Sprite
  2. const TRANS = Tween.TRANS_LINEAR
  3. const EASE = Tween.EASE_IN_OUT
  4. export var pulse_color:Color setget _set_pulse_color, _get_pulse_color
  5. export var pulse_in_time:float = 0.5
  6. export var pulse_out_time:float = 0.5
  7. export var pulse_in:float = 0.1
  8. export var pulse_out:float = 0.9
  9. export var pulse_offset:float = 0.1 setget _set_pulse_offset, _get_pulse_offset
  10. var _running = false
  11. func _camp(v, o_min, o_max):
  12. # Reduces v (clamped to 0 and 1) to the values between o_min and o_max
  13. return o_min + ((o_max - o_min) * clamp(v, 0.0, 1.0))
  14. func _ramp(v, f_min, f_max):
  15. # Expands v, spreading the values between f_min and f_max to be between 0 and 1.
  16. if f_min == f_max:
  17. return f_min
  18. return clamp((v - f_min) / (f_max - f_min), 0.0, 1.0)
  19. func _set_pulse_offset(v):
  20. material.set_shader_param("fade_offset", _camp(v, 0.1, 0.5))
  21. func _get_pulse_offset():
  22. if self.get_name() == "Dot21":
  23. print("PING")
  24. return _ramp(material.get_shader_param("fade_offset"), 0.1, 0.5)
  25. func _set_pulse_color(c):
  26. material.set_shader_param("primary_color", c)
  27. func _get_pulse_color():
  28. return material.get_shader_param("primary_color")
  29. func _ready():
  30. material.set_shader_param("primary_color", pulse_color)
  31. func start():
  32. _running = true
  33. _on_PulseOut_timeout()
  34. func stop():
  35. $PulseOut.stop()
  36. $PulseIn.stop()
  37. _running = false
  38. func _interpolate_to(v, t):
  39. $Pulse.interpolate_property(self, "pulse_offset", self.pulse_offset, v, t, TRANS, EASE)
  40. $Pulse.start()
  41. func _on_PulseIn_timeout():
  42. if _running:
  43. #print(self.get_name(), " Pulse Out Time: ", $PulseOut.wait_time)
  44. $PulseIn.stop()
  45. if _get_pulse_offset() == pulse_in:
  46. $PulseOut.wait_time = pulse_out_time
  47. else:
  48. $PulseOut.wait_time = (1.0 - ((_get_pulse_offset() - pulse_in) / (pulse_out / pulse_in))) * pulse_out_time
  49. _interpolate_to(pulse_out, $PulseOut.wait_time)
  50. $PulseOut.start()
  51. func _on_PulseOut_timeout():
  52. if _running:
  53. #print(self.get_name(), " Pulse In Time: ", $PulseOut.wait_time)
  54. $PulseOut.stop()
  55. if _get_pulse_offset() == pulse_out:
  56. $PulseIn.wait_time = pulse_in_time
  57. else:
  58. # Adjust time due to current offset.
  59. $PulseIn.wait_time = (_get_pulse_offset() - pulse_in) / (pulse_out / pulse_in) * pulse_in_time
  60. _interpolate_to(pulse_in, $PulseIn.wait_time)
  61. $PulseIn.start()