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.

54 lines
1.2KB

  1. extends StaticBody2D
  2. const OPENED_POSITION = Vector2(-47, 0)
  3. const CLOSED_POSITION = Vector2(-6, 0)
  4. const POSITION_DIFF = 41
  5. export var color:Color
  6. export var transition_rate = 0.75
  7. var _control_state = 0 # 0 = No-OP | 1 = Open | 2 = Close
  8. func _ready():
  9. set_color(color)
  10. func set_color(c):
  11. $Doorway/Glow.pulse_color = c
  12. func is_opening():
  13. if $Tween.is_active():
  14. return _control_state == 1
  15. return false
  16. func is_closing():
  17. if $Tween.is_active():
  18. return _control_state == 2
  19. return false
  20. func open():
  21. var t = transition_rate
  22. var cdiff = ($Doorway.position - OPENED_POSITION).length()
  23. if cdiff > 0.001:
  24. t = transition_rate * (cdiff / POSITION_DIFF)
  25. $Tween.interpolate_property($Doorway, "position", $Doorway.position, OPENED_POSITION, t, Tween.TRANS_LINEAR, Tween.EASE_IN)
  26. $Tween.start()
  27. $Audio.play()
  28. _control_state = 1
  29. func close():
  30. var t = transition_rate
  31. var cdiff = ($Doorway.position - CLOSED_POSITION).length()
  32. if cdiff > 0.001:
  33. t = transition_rate * (cdiff / POSITION_DIFF)
  34. $Tween.interpolate_property($Doorway, "position", $Doorway.position, CLOSED_POSITION, t, Tween.TRANS_LINEAR, Tween.EASE_IN)
  35. $Tween.start()
  36. $Audio.play()
  37. _control_state = 2
  38. func stop():
  39. $Tween.stop($Doorway, "position")
  40. $Audio.stop()
  41. _control_state = 0