GameOver.gd 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. extends Node
  2. @export var reset_level := false
  3. @export var has_menu := false
  4. var can_continue := false
  5. func _enter_tree() -> void:
  6. Global.level_theme = "Underground"
  7. Global.level_theme_changed.emit()
  8. AudioManager.stop_all_music()
  9. func _ready() -> void:
  10. get_tree().paused = false
  11. Global.lives = clamp(Global.lives, 0, 99)
  12. SpeedrunHandler.timer_active = false
  13. await get_tree().create_timer(0.1).timeout
  14. can_continue = true
  15. func _process(_delta: float) -> void:
  16. print(can_continue)
  17. if Input.is_action_just_pressed("jump_0") and can_continue:
  18. go_back_to_title()
  19. can_continue = false
  20. func go_back_to_title() -> void:
  21. if has_menu:
  22. $Timer.queue_free()
  23. has_menu = false
  24. $CanvasLayer/VBoxContainer.show()
  25. $CanvasLayer/VBoxContainer/SelectableLabel.grab_focus()
  26. elif not reset_level:
  27. quit_to_menu()
  28. else:
  29. continue_on()
  30. func continue_on() -> void:
  31. reset_values()
  32. LevelTransition.level_to_transition_to = Level.get_scene_string(Global.world_num, Global.level_num)
  33. Global.transition_to_scene("res://Scenes/Levels/LevelTransition.tscn")
  34. func quit_to_menu() -> void:
  35. reset_values()
  36. Global.transition_to_scene("res://Scenes/Levels/TitleScreen.tscn")
  37. func reset_values() -> void:
  38. if Global.world_num <= 8:
  39. ChallengeModeHandler.current_run_red_coins_collected = ChallengeModeHandler.red_coins_collected[Global.world_num - 1][Global.level_num - 1]
  40. Global.lives = 3
  41. Global.score = 0
  42. Global.player_power_states = "0000"
  43. Global.coins = 0
  44. if Global.current_game_mode == Global.GameMode.CHALLENGE:
  45. return
  46. match Settings.file.difficulty.game_over_behaviour:
  47. 0:
  48. Global.level_num = 1
  49. 1:
  50. pass
  51. 2:
  52. Global.level_num = 1
  53. Global.world_num = 1
  54. Global.reset_values()
  55. SaveManager.write_save()