A game created for the Godot Wild Jam #21
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.

47 lines
1.0KB

  1. extends Node2D
  2. # The code in this script was adapted from Game Endeavor on YouTube
  3. # https://www.youtube.com/watch?v=_DAvzzJMko8
  4. # NOTE: This script and associated scene assumes it's parented to a camera object!
  5. const TRANS = Tween.TRANS_SINE
  6. const EASE = Tween.EASE_IN_OUT
  7. var _amplitude = 0
  8. var _priority = 0
  9. onready var _camera = get_parent()
  10. func start(duration = 0.2, frequency = 15, amplitude = 16, priority = 0):
  11. if priority >= _priority:
  12. _priority = priority
  13. _amplitude = amplitude
  14. $Duration.wait_time = duration
  15. $Frequency.wait_time = 1/float(frequency)
  16. $Duration.start()
  17. $Frequency.start()
  18. _shake()
  19. func _interpolate_to(v):
  20. $Shake.interpolate_property(_camera, "offset", _camera.offset, v, $Frequency.wait_time, TRANS, EASE)
  21. $Shake.start()
  22. func _shake():
  23. _interpolate_to(Vector2(
  24. rand_range(-_amplitude, _amplitude),
  25. rand_range(-_amplitude, _amplitude)
  26. ))
  27. func _on_Frequency_timeout():
  28. _shake()
  29. func _on_Duration_timeout():
  30. _interpolate_to(Vector2())
  31. $Frequency.stop()
  32. $Duration.stop()
  33. _priority = 0