Lakitu.gd 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. class_name Lakitu
  2. extends Enemy
  3. static var present := false:
  4. set(value):
  5. if value == true:
  6. pass
  7. present = value
  8. var screen_center := Vector2.ZERO
  9. var lakitu_point := Vector2.ZERO
  10. const BLOCK_DISTANCE := 64
  11. static var fixed_throw := true
  12. var player: Player = null
  13. var retreat := false
  14. var can_enter := false
  15. static var spiny_amount := 0
  16. @export var item: PackedScene = null
  17. @export var retreat_x := 3072
  18. func _ready() -> void:
  19. can_enter = false
  20. $ThrowTimer.start()
  21. lakitu_point = to_local(global_position)
  22. fixed_throw = Settings.file.difficulty.lakitu_style == 1
  23. get_parent().move_child(self, 0)
  24. func _process(_delta: float) -> void:
  25. screen_center = get_viewport().get_camera_2d().get_screen_center_position()
  26. func _physics_process(delta: float) -> void:
  27. player = get_tree().get_first_node_in_group("Players")
  28. handle_movement(delta)
  29. func handle_movement(_delta: float) -> void:
  30. retreat = get_viewport().get_camera_2d().get_screen_center_position().x >= retreat_x
  31. var player_x = player.global_position.x + ((player.velocity.x))
  32. var distance = abs(global_position.x - player_x)
  33. get_direction(player_x)
  34. if direction == 1:
  35. velocity.x = int(clamp((distance - 16) * 2, 48, INF))
  36. else:
  37. velocity.x = -48
  38. $Cloud.scale.x = direction
  39. move_and_slide()
  40. func get_direction(player_x := 0.0) -> void:
  41. if retreat:
  42. present = false
  43. direction = -1
  44. return
  45. if direction == -1 and global_position.x < player_x - BLOCK_DISTANCE:
  46. direction = 1
  47. elif direction == 1 and global_position.x > player_x + BLOCK_DISTANCE:
  48. direction = -1
  49. func summon_cloud_particle() -> void:
  50. var node = preload("res://Scenes/Prefabs/Particles/LakituCloudBurst.tscn").instantiate()
  51. node.global_position = $Cloud.global_position
  52. add_sibling(node)
  53. func on_timeout() -> void:
  54. if spiny_amount >= 3 or retreat or $WallCheck.is_colliding():
  55. return
  56. $Cloud/Sprite.play("Throw")
  57. await get_tree().create_timer(0.5, false).timeout
  58. if $WallCheck.is_colliding() == false:
  59. throw_spiny()
  60. $Cloud/Sprite.play("Idle")
  61. func throw_spiny() -> void:
  62. var node = item.instantiate()
  63. spiny_amount += 1
  64. node.set("in_egg", true)
  65. node.global_position = $Cloud/Sprite.global_position
  66. node.velocity = Vector2(0, -150)
  67. if fixed_throw:
  68. node.velocity.x = 50 * (sign(player.global_position.x - global_position.x))
  69. node.set("direction", sign(node.velocity.x))
  70. add_sibling(node)
  71. if Settings.file.audio.extra_sfx == 1:
  72. AudioManager.play_sfx("lakitu_throw", global_position)
  73. node.tree_exited.connect(func(): spiny_amount -= 1)
  74. func on_screen_entered() -> void:
  75. if Global.level_editor != null:
  76. if Global.level_editor.playing_level == false:
  77. return
  78. add_to_group("Lakitus")
  79. if get_tree().get_node_count_in_group("Lakitus") >= 2:
  80. queue_free()