BulletBillCannon.gd 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. extends Node2D
  2. @export var item: PackedScene = preload("res://Scenes/Prefabs/Entities/Enemies/BulletBill.tscn")
  3. var timer := 15
  4. const MAX_TIME := 15
  5. const HARD_TIME := 7
  6. func _physics_process(_delta: float) -> void:
  7. if randi_range(0, 8) == 8:
  8. timer -= 1
  9. if timer <= 0:
  10. if Global.second_quest:
  11. timer = HARD_TIME
  12. else:
  13. timer = MAX_TIME
  14. fire()
  15. func fire() -> void:
  16. if BulletBill.amount >= 3 or $PlayerDetect.get_overlapping_areas().any(func(area: Area2D): return area.owner is Player) or is_inside_tree() == false:
  17. return
  18. var player: Player = get_tree().get_first_node_in_group("Players")
  19. var direction = sign(player.global_position.x - global_position.x)
  20. $BlockCheck.scale.x = direction
  21. $BlockCheck/RayCast2D.force_raycast_update()
  22. if $BlockCheck/RayCast2D.is_colliding():
  23. return
  24. var node = item.instantiate()
  25. node.global_position = global_position + Vector2(0, 8)
  26. node.set("direction", direction)
  27. if node is CharacterBody2D:
  28. node.position.x += 8 * direction
  29. node.set("velocity", Vector2(100 * direction, 0))
  30. if node is not BulletBill:
  31. AudioManager.play_sfx("cannon", global_position)
  32. else:
  33. node.cannon = true
  34. add_sibling(node)
  35. func flag_die() -> void:
  36. queue_free()