Fire.gd 871 B

123456789101112131415161718192021
  1. extends PowerUpState
  2. var fireball_amount := 0
  3. const FIREBALL = preload("res://Scenes/Prefabs/Entities/Items/Fireball.tscn")
  4. func update(_delta: float) -> void:
  5. if Global.player_action_just_pressed("action", player.player_id) and fireball_amount < 2 and player.state_machine.state.name == "Normal":
  6. throw_fireball()
  7. func throw_fireball() -> void:
  8. var node = FIREBALL.instantiate()
  9. node.character = player.character
  10. node.global_position = player.global_position - Vector2(-4 * player.direction, 16 * player.gravity_vector.y)
  11. node.direction = player.direction
  12. node.velocity.y = 100
  13. player.call_deferred("add_sibling", node)
  14. fireball_amount += 1
  15. node.tree_exited.connect(func(): fireball_amount -= 1)
  16. AudioManager.play_sfx("fireball", player.global_position)
  17. player.attacking = true
  18. await get_tree().create_timer(0.1, false).timeout
  19. player.attacking = false