EndCastle.gd 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. extends Node2D
  2. var time_save := 0
  3. signal finished_sequence
  4. const FIREWORK = preload("res://Scenes/Prefabs/Particles/Firework.tscn")
  5. var tally_finished := false
  6. var music_finished := false
  7. var tree = null
  8. var show_walls := false
  9. var doing_sequence := false
  10. var can_transition := false
  11. static var is_transitioning := false
  12. func _ready() -> void:
  13. await Global.level_complete_begin
  14. $Overlay.show()
  15. $OverlaySprite.show()
  16. $Overlay/PlayerDetection.set_collision_layer_value(1, true)
  17. Global.score_tally_finished.connect(on_tally_finished)
  18. if Global.current_game_mode == Global.GameMode.BOO_RACE:
  19. get_tree().create_timer(3.5, false).timeout.connect(on_music_finished)
  20. else:
  21. get_tree().create_timer(5.5, false).timeout.connect(on_music_finished)
  22. time_save = Global.time
  23. func update_cam_limit() -> void:
  24. $CameraRightLimit._enter_tree()
  25. func _process(_delta: float) -> void:
  26. $Overlay.modulate.a = int($SmallCastleVisual.use_sprite == false)
  27. if get_node_or_null("Wall") != null:
  28. %Wall.visible = show_walls
  29. func on_music_finished() -> void:
  30. do_sequence()
  31. func on_tally_finished() -> void:
  32. $FlagJoint/Flag/AnimationPlayer.play("Raise")
  33. func do_sequence() -> void:
  34. if Global.current_game_mode != Global.GameMode.BOO_RACE:
  35. await get_tree().create_timer(1, false).timeout
  36. if Global.current_campaign == "SMBLL":
  37. await do_lost_levels_firework_check()
  38. else:
  39. await do_firework_check()
  40. await get_tree().create_timer(1, false).timeout
  41. if is_transitioning == false:
  42. is_transitioning = true
  43. exit_level()
  44. func do_firework_check() -> void:
  45. var digit = time_save % 10
  46. if [1, 3, 6].has(digit):
  47. await show_fireworks(digit)
  48. return
  49. func do_lost_levels_firework_check() -> void:
  50. var coin_digit = Global.coins % 10
  51. var time_digit = time_save % 10
  52. if coin_digit == time_digit:
  53. if coin_digit % 2 == 0:
  54. await show_fireworks(6)
  55. if coin_digit % 11 == 0:
  56. spawn_one_up_note()
  57. AudioManager.play_sfx("1_up", global_position)
  58. Global.lives += 1
  59. else:
  60. await show_fireworks(3)
  61. const ONE_UP_NOTE = preload("uid://dopxwjj37gu0l")
  62. func spawn_one_up_note() -> void:
  63. var note = ONE_UP_NOTE.instantiate()
  64. note.global_position = global_position + Vector2(0, -16)
  65. owner.add_sibling(note)
  66. func _exit_tree() -> void:
  67. is_transitioning = false
  68. func show_fireworks(amount := 0) -> void:
  69. for i in amount:
  70. spawn_firework()
  71. await get_tree().create_timer(0.5, false).timeout
  72. func spawn_firework() -> void:
  73. var node = FIREWORK.instantiate()
  74. Global.score += 500
  75. node.position.x = randf_range(-48, 48)
  76. node.position.y = randf_range(-112, -150)
  77. add_child(node)
  78. AudioManager.play_sfx("firework", node.global_position)
  79. func exit_level() -> void:
  80. await Global.frame_rule
  81. match Global.current_game_mode:
  82. Global.GameMode.MARATHON_PRACTICE:
  83. Global.reset_values()
  84. Global.open_marathon_results()
  85. Global.GameMode.CUSTOM_LEVEL:
  86. Global.transition_to_scene("res://Scenes/Levels/CustomLevelMenu.tscn")
  87. Global.GameMode.LEVEL_EDITOR:
  88. Global.level_editor.stop_testing()
  89. _:
  90. if Global.current_campaign == "SMBANN":
  91. Global.open_disco_results()
  92. else:
  93. Global.current_level.transition_to_next_level()