LevelClass.gd 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. @icon("res://Assets/Sprites/Editor/Level.png")
  2. class_name Level
  3. extends Node
  4. @export var music: JSON = null
  5. @export_enum("Overworld", "Underground", "Desert", "Snow", "Jungle", "Beach", "Garden", "Mountain", "Skyland", "Autumn", "Pipeland", "Space", "Underwater", "Volcano", "Castle", "CastleWater", "Airship", "Bonus") var theme := "Overworld"
  6. @export_enum("Day", "Night") var theme_time := "Day"
  7. const THEME_IDXS := ["Overworld", "Underground", "Desert", "Snow", "Jungle", "Beach", "Garden", "Mountain", "Skyland", "Autumn", "Pipeland", "Space", "Underwater", "Volcano", "GhostHouse", "Castle", "CastleWater", "Airship", "Bonus"]
  8. const WORLD_THEMES := {
  9. "SMB1": SMB1_THEMES,
  10. "SMBLL": SMB1_THEMES,
  11. "SMBS": SMBS_THEMES,
  12. "SMBANN": SMB1_THEMES
  13. }
  14. const SMB1_THEMES := {
  15. -1: "Overworld",
  16. 1: "Overworld",
  17. 2: "Desert",
  18. 3: "Snow",
  19. 4: "Jungle",
  20. 5: "Desert",
  21. 6: "Snow",
  22. 7: "Jungle",
  23. 8: "Overworld",
  24. 9: "Space",
  25. 10: "Autumn",
  26. 11: "Pipeland",
  27. }
  28. const SMBS_THEMES := {
  29. 1: "Overworld",
  30. 2: "Garden",
  31. 3: "Beach",
  32. 4: "Mountain",
  33. 5: "Garden",
  34. 6: "Beach",
  35. 7: "Mountain",
  36. 8: "Overworld"
  37. }
  38. @export var auto_set_theme := false
  39. @export var time_limit := 400
  40. @export var campaign := "SMB1"
  41. @export var world_id := 1
  42. @export var level_id := 1
  43. @export var vertical_height := -208
  44. @export var can_backscroll := false
  45. static var next_world := 1
  46. static var next_level := 2
  47. static var next_level_file_path := ""
  48. static var first_load := true
  49. static var start_level_path := ""
  50. static var vine_warp_level := ""
  51. static var vine_return_level := ""
  52. static var in_vine_level := false
  53. static var can_set_time := true
  54. func _enter_tree() -> void:
  55. Global.current_level = self
  56. update_theme()
  57. SpeedrunHandler.timer_active = true
  58. SpeedrunHandler.ghost_active = true
  59. if can_set_time:
  60. can_set_time = false
  61. Global.time = time_limit
  62. if first_load:
  63. start_level_path = scene_file_path
  64. Global.can_time_tick = true
  65. Global.level_num = level_id
  66. Global.world_num = world_id
  67. PlayerGhost.idx = 0
  68. SpeedrunHandler.current_recording = ""
  69. if SpeedrunHandler.timer <= 0:
  70. SpeedrunHandler.start_time = Time.get_ticks_msec()
  71. else:
  72. level_id = Global.level_num
  73. world_id = Global.world_num
  74. if Settings.file.difficulty.back_scroll == 1 and Global.current_game_mode != Global.GameMode.CUSTOM_LEVEL:
  75. can_backscroll = true
  76. first_load = false
  77. if Global.connected_players > 1:
  78. spawn_in_extra_players()
  79. Global.current_campaign = campaign
  80. await get_tree().process_frame
  81. AudioManager.stop_music_override(AudioManager.MUSIC_OVERRIDES.NONE, true)
  82. const PLAYER = preload("res://Scenes/Prefabs/Entities/Player.tscn")
  83. func spawn_in_extra_players() -> void:
  84. await ready
  85. for i in Global.connected_players - 1:
  86. var player_node = PLAYER.instantiate()
  87. player_node.player_id = i + 1
  88. player_node.global_position = get_tree().get_first_node_in_group("Players").global_position + Vector2(16 * (i + 1), 0)
  89. add_child(player_node)
  90. func update_theme() -> void:
  91. if auto_set_theme:
  92. theme = WORLD_THEMES[Global.current_campaign][Global.world_num]
  93. campaign = Global.current_campaign
  94. if Global.world_num > 4 and Global.world_num < 9:
  95. theme_time = "Night"
  96. else:
  97. theme_time = "Day"
  98. if Global.current_campaign == "SMBANN":
  99. theme_time = "Night"
  100. ResourceSetterNew.cache.clear()
  101. Global.current_campaign = campaign
  102. Global.level_theme = theme
  103. Global.theme_time = theme_time
  104. TitleScreen.last_theme = theme
  105. $LevelBG.update_visuals()
  106. func update_next_level_info() -> void:
  107. next_level = wrap(level_id + 1, 1, 5)
  108. next_world = world_id if level_id != 4 else world_id + 1
  109. next_level_file_path = get_scene_string(next_world, next_level)
  110. LevelTransition.level_to_transition_to = next_level_file_path
  111. static func get_scene_string(world_num := 0, level_num := 0) -> String:
  112. return "res://Scenes/Levels/" + Global.current_campaign + "/World" + str(world_num) + "/" + str(world_num) + "-" + str(level_num) + ".tscn"
  113. func transition_to_next_level() -> void:
  114. if Global.current_game_mode == Global.GameMode.CHALLENGE:
  115. Global.transition_to_scene("res://Scenes/Levels/ChallengeModeResults.tscn")
  116. return
  117. if Global.current_game_mode == Global.GameMode.BOO_RACE:
  118. Global.transition_to_scene("res://Scenes/Levels/BooRaceMenu.tscn")
  119. return
  120. update_next_level_info()
  121. PipeCutscene.seen_cutscene = false
  122. if WarpPipeArea.has_warped == false:
  123. Global.level_num = next_level
  124. Global.world_num = next_world
  125. LevelTransition.level_to_transition_to = get_scene_string(next_world, next_level)
  126. first_load = true
  127. SaveManager.write_save()
  128. Global.transition_to_scene("res://Scenes/Levels/LevelTransition.tscn")
  129. Checkpoint.passed = false
  130. func reload_level() -> void:
  131. LevelTransition.level_to_transition_to = Level.start_level_path
  132. if Global.current_game_mode == Global.GameMode.CUSTOM_LEVEL:
  133. LevelTransition.level_to_transition_to = "res://Scenes/Levels/LevelEditor.tscn"
  134. if Global.current_game_mode == Global.GameMode.BOO_RACE:
  135. LevelPersistance.reset_states()
  136. Global.transition_to_scene(LevelTransition.level_to_transition_to)
  137. else:
  138. Global.transition_to_scene("res://Scenes/Levels/LevelTransition.tscn")