global.gd 945 B

1234567891011121314151617181920212223242526272829303132333435
  1. extends Node
  2. const MAX_LEVEL = 3
  3. var current_scene = null
  4. var level = 1
  5. var spell_level = 1
  6. var learn_spell = [true, false, false, false, false, false, false, false]
  7. func _ready():
  8. var root = get_tree().get_root()
  9. current_scene = root.get_child(root.get_child_count() -1)
  10. func goto_scene(scene):
  11. var s = ResourceLoader.load(scene)
  12. print("Going from \"" + current_scene.get_filename() + "\"")
  13. print(" to \"" + scene + "\"")
  14. current_scene.queue_free()
  15. current_scene = s.instance()
  16. get_tree().get_root().add_child(current_scene)
  17. func next_level():
  18. if learn_spell[level - 1]:
  19. spell_level += 1
  20. level += 1
  21. var next_scene = ""
  22. if level <= MAX_LEVEL:
  23. next_scene = "res://Scenes/levels/level_" + str(level) + ".xscn"
  24. print("You beat the level!")
  25. else:
  26. next_scene = "res://Scenes/main_menu.xscn"
  27. print("You won the game!")
  28. goto_scene(next_scene)