Guest User

Untitled

a guest
Mar 4th, 2022
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class_name AnchorDetector2D
  2. extends Area2D
  3.  
  4. signal anchor_detached
  5. signal anchor_updated(anchor)
  6.  
  7. var current_anchor = null setget update_anchor
  8. var candidate_anchor = null
  9.  
  10. func _ready():
  11.     connect("anchor_updated", GameManager, "on_room_changed")
  12.  
  13. func update_anchor(new):
  14.     current_anchor = new
  15.     new.room_entered()
  16.     emit_signal("anchor_updated", new)
  17.  
  18.  
  19. func _on_AnchorDetector2d_area_entered(area: Anchor2D) -> void:
  20.     area.room_pre_entered() #Для подгрузки комнаты в память
  21.     if current_anchor == null:
  22.         update_anchor(area)
  23.     else:
  24.         candidate_anchor = area
  25.  
  26.  
  27. func _on_AnchorDetector2d_area_exited(area: Anchor2D) -> void:
  28.     if candidate_anchor == null:
  29.         current_anchor = null
  30.         emit_signal("anchor_detached")
  31.     else:
  32.         if area == current_anchor:
  33.             update_anchor(candidate_anchor)
  34.             area.room_exited()
  35.         candidate_anchor = null
Advertisement
Add Comment
Please, Sign In to add comment