LevelTransition.gd 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. class_name LevelTransition
  2. extends Node
  3. const PIPE_CUTSCENE_LEVELS := {
  4. "SMB1": [[1, 2], [2, 2], [4, 2], [7, 2]],
  5. "SMBLL": [[1, 2], [3, 2], [5, 2], [6, 2], [10, 2], [11, 2]],
  6. "SMBS": [[1, 2], [2, 2], [3, 1], [7, 2], [8, 3]],
  7. "SMBANN": []
  8. }
  9. const PIPE_CUTSCENE_OVERRIDE := {
  10. "SMB1": {[2, 2]: "res://Scenes/Levels/PipeCutsceneWater.tscn", [7, 2]: "res://Scenes/Levels/PipeCutsceneWater.tscn"},
  11. "SMBLL": {[3, 2]: "res://Scenes/Levels/PipeCutsceneWater.tscn", [11, 2]: "res://Scenes/Levels/PipeCutsceneWater.tscn"},
  12. "SMBS": {[3, 1]: "res://Scenes/Levels/SMBS/SPCastlePipeCutscene.tscn", [7, 2]: "res://Scenes/Levels/PipeCutsceneWater.tscn"},
  13. "SMBANN": {}
  14. }
  15. var can_transition := false
  16. var level_best_time := 0.0
  17. static var level_to_transition_to := "res://Scenes/Levels/World1/1-1.tscn":
  18. set(value):
  19. level_to_transition_to = value
  20. pass
  21. @export var text_shadows: Array[Label] = []
  22. func _ready() -> void:
  23. WarpPipeArea.has_warped = false
  24. Global.level_theme = "Underground"
  25. $BG/Control/MarathonPB.visible = Global.current_game_mode == Global.GameMode.MARATHON_PRACTICE
  26. $BG/Control/LivesCount.visible = Global.current_game_mode != Global.GameMode.MARATHON_PRACTICE
  27. Level.can_set_time = true
  28. ResourceSetterNew.cache.clear()
  29. ResourceSetterNew.property_cache.clear()
  30. AudioManager.current_level_theme = ""
  31. Level.vine_return_level = ""
  32. Level.vine_warp_level = ""
  33. Level.in_vine_level = false
  34. Global.p_switch_active = false
  35. Lakitu.present = false
  36. Global.p_switch_timer = -1
  37. if Global.current_campaign == "SMBANN":
  38. DiscoLevel.reset_values()
  39. DiscoLevel.first_load = true
  40. if Global.current_game_mode == Global.GameMode.MARATHON_PRACTICE:
  41. Global.clear_saved_values()
  42. if SpeedrunHandler.ghost_enabled:
  43. SpeedrunHandler.load_best_marathon()
  44. SpeedrunHandler.ghost_active = false
  45. show_best_time()
  46. Level.first_load = true
  47. SpeedrunHandler.ghost_idx = -1
  48. SpeedrunHandler.timer_active = false
  49. SpeedrunHandler.timer = 0
  50. get_tree().call_group("PlayerGhosts", "delete")
  51. get_tree().paused = false
  52. $Timer.start()
  53. AudioManager.stop_music_override(AudioManager.MUSIC_OVERRIDES.NONE, true)
  54. AudioManager.music_player.stop()
  55. PipeArea.exiting_pipe_id = -1
  56. var world_num = str(Global.world_num)
  57. if world_num == "-1":
  58. world_num = " "
  59. if Global.world_num >= 10:
  60. world_num = ["A", "B", "C", "D"][Global.world_num % 10]
  61. var lvl_idx := SaveManager.get_level_idx(Global.world_num, Global.level_num)
  62. SaveManager.visited_levels[lvl_idx] = "1"
  63. if Global.current_game_mode == Global.GameMode.CAMPAIGN:
  64. SaveManager.write_save(Global.current_campaign)
  65. Global.set_discord_status("Playing " + Global.current_campaign + ": " + str(world_num) + "-" + str(Global.level_num))
  66. $BG/Control/WorldNum.text = str(world_num) +"-" + str(Global.level_num)
  67. if Settings.file.difficulty.inf_lives:
  68. $BG/Control/LivesCount.text = "* ∞"
  69. elif Global.lives < 100:
  70. $BG/Control/LivesCount.text = "* " + (str(Global.lives).lpad(2, " "))
  71. else:
  72. $BG/Control/LivesCount.text = "* ♕"
  73. if Global.current_game_mode == Global.GameMode.CUSTOM_LEVEL:
  74. $BG/Control/World.hide()
  75. $BG/Control/WorldNum.hide()
  76. %CustomLevelAuthor.show()
  77. %CustomLevelName.show()
  78. %CustomLevelAuthor.text = "By " + LevelEditor.level_author
  79. %CustomLevelName.text = LevelEditor.level_name
  80. await get_tree().create_timer(0.1, false).timeout
  81. can_transition = true
  82. func transition() -> void:
  83. Global.can_time_tick = true
  84. if PIPE_CUTSCENE_LEVELS[Global.current_campaign].has([Global.world_num, Global.level_num]) and not PipeCutscene.seen_cutscene and Global.current_game_mode != Global.GameMode.MARATHON_PRACTICE and Global.current_game_mode !=Global.GameMode.BOO_RACE:
  85. if PIPE_CUTSCENE_OVERRIDE[Global.current_campaign].has([Global.world_num, Global.level_num]):
  86. Global.transition_to_scene(PIPE_CUTSCENE_OVERRIDE[Global.current_campaign][[Global.world_num, Global.level_num]])
  87. else:
  88. Global.transition_to_scene("res://Scenes/Levels/PipeCutscene.tscn")
  89. else:
  90. Global.transition_to_scene(level_to_transition_to)
  91. func show_best_time() -> void:
  92. var best_time = SpeedrunHandler.best_time
  93. if SpeedrunHandler.best_time <= 0:
  94. $BG/Control/MarathonPB.text = "\nNO PB"
  95. return
  96. var string = "PB\n" + SpeedrunHandler.gen_time_string(SpeedrunHandler.format_time(SpeedrunHandler.best_time))
  97. $BG/Control/MarathonPB.text = string
  98. func _process(_delta: float) -> void:
  99. if can_transition:
  100. if Input.is_action_just_pressed("jump_0"):
  101. transition()
  102. func _exit_tree() -> void:
  103. Global.death_load = false