CastleToad.gd 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. extends Node2D
  2. @export var play_end_music := false
  3. var can_menu := false
  4. const ENDING = preload("res://Assets/Audio/BGM/Ending.mp3")
  5. func _ready() -> void:
  6. if $Sprite is AnimatedSprite2D and Global.current_campaign == "SMBANN":
  7. $Sprite.play("Idle")
  8. Global.level_complete_begin.connect(begin)
  9. for i in [$SpeedrunMSG/ThankYou, $StandardMSG/ThankYou]:
  10. i.text = tr(i.text).replace("{PLAYER}", tr(Player.CHARACTER_NAMES[int(Global.player_characters[0])]))
  11. func begin() -> void:
  12. $StaticBody2D/CollisionShape2D.set_deferred("disabled", false)
  13. %PBMessage.modulate.a = int(SpeedrunHandler.timer < SpeedrunHandler.best_time)
  14. if play_end_music:
  15. Global.game_beaten = true
  16. SaveManager.write_save()
  17. play_music()
  18. %Time.text = tr(%Time.text).replace("{TIME}", SpeedrunHandler.gen_time_string(SpeedrunHandler.format_time(SpeedrunHandler.timer)))
  19. $CameraRightLimit._enter_tree()
  20. await get_tree().create_timer(3, false).timeout
  21. if Global.current_game_mode == Global.GameMode.MARATHON_PRACTICE or (Global.current_game_mode == Global.GameMode.MARATHON and play_end_music):
  22. show_message($SpeedrunMSG)
  23. else:
  24. show_message($StandardMSG)
  25. if not play_end_music:
  26. await get_tree().create_timer(7, false).timeout
  27. exit_level()
  28. func exit_level() -> void:
  29. match Global.current_game_mode:
  30. Global.GameMode.MARATHON_PRACTICE:
  31. Global.open_marathon_results()
  32. Global.GameMode.CUSTOM_LEVEL:
  33. Global.transition_to_scene("res://Scenes/Levels/CustomLevelMenu.tscn")
  34. Global.GameMode.LEVEL_EDITOR:
  35. Global.level_editor.stop_testing()
  36. _:
  37. if Global.current_campaign == "SMBANN":
  38. Global.open_disco_results()
  39. return
  40. if Global.world_num < 1:
  41. Global.transition_to_scene("res://Scenes/Levels/TitleScreen.tscn")
  42. else:
  43. Global.current_level.transition_to_next_level()
  44. func do_tally() -> void:
  45. pass
  46. func play_music() -> void:
  47. await AudioManager.music_override_player.finished
  48. AudioManager.set_music_override(AudioManager.MUSIC_OVERRIDES.ENDING, 999999, false)
  49. if [Global.GameMode.MARATHON, Global.GameMode.MARATHON_PRACTICE].has(Global.current_game_mode) == false:
  50. show_message($EndingSpeech)
  51. await get_tree().create_timer(5, false).timeout
  52. can_menu = true
  53. else:
  54. can_menu = true
  55. func _process(_delta: float) -> void:
  56. if can_menu and Input.is_action_just_pressed("jump_0"):
  57. can_menu = false
  58. peach_level_exit()
  59. func show_message(message_node: Node) -> void:
  60. for i in message_node.get_children():
  61. i.show()
  62. await get_tree().create_timer(1).timeout
  63. func peach_level_exit() -> void:
  64. match Global.current_game_mode:
  65. Global.GameMode.MARATHON:
  66. Global.open_marathon_results()
  67. Global.GameMode.MARATHON_PRACTICE:
  68. Global.open_marathon_results()
  69. Global.GameMode.CUSTOM_LEVEL:
  70. Global.transition_to_scene("res://Scenes/Levels/CustomLevelMenu.tscn")
  71. Global.GameMode.LEVEL_EDITOR:
  72. Global.level_editor.play_toggle()
  73. _:
  74. if Global.current_campaign == "SMBLL" and Global.world_num == 8:
  75. Global.current_level.transition_to_next_level()
  76. elif Global.current_game_mode == Global.GameMode.CAMPAIGN:
  77. CreditsLevel.go_to_title_screen = true
  78. Global.transition_to_scene("res://Scenes/Levels/Credits.tscn")
  79. else: Global.transition_to_scene("res://Scenes/Levels/TitleScreen.tscn")