Portal.gd 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. extends Area
  2. export (String) var level
  3. export (String) var spawn
  4. signal on_level_change
  5. func _ready():
  6. # Called when the node is added to the scene for the first time.
  7. # Initialization here
  8. pass
  9. func _process(delta):
  10. for body in get_overlapping_bodies ( ):
  11. if body.name == "Player" :
  12. if Input.is_action_just_pressed("ui_accept") and Input.is_key_pressed(KEY_ENTER):
  13. loadLevel(body)
  14. func loadLevel(body):
  15. if spawn != null:
  16. pass
  17. #print ("spawn found")
  18. if level != null:
  19. #print ("load map now!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
  20. #FIXME: put code in extra function used for saving data before exiting a map,
  21. #maybe create signal that level changes soon and data has to be changed
  22. #when using a signal make sure that everything is saved before new level is loaded!
  23. emit_signal("on_level_change")
  24. var collectorNode = body.find_node("PlayerInventory", true, false)
  25. if collectorNode != null:
  26. #print ("collNode found in portal")
  27. get_node("/root/Save").save_node_data(collectorNode)
  28. get_node("/root/global").loadLevel("res://Scenes/World.tscn", level, spawn, true)