Fireball.gd 879 B

12345678910111213141516171819202122232425262728293031323334
  1. class_name FireBall
  2. extends CharacterBody2D
  3. const CHARACTERS := ["Mario", "Luigi", "Toad", "Toadette"]
  4. var character := "Mario"
  5. var direction := 1
  6. const FIREBALL_EXPLOSION = preload("res://Scenes/Prefabs/Particles/FireballExplosion.tscn")
  7. const MOVE_SPEED := 220
  8. func _physics_process(delta: float) -> void:
  9. $Sprite.scale.x = direction
  10. $Sprite/Animation.speed_scale = direction * 2
  11. velocity.x = MOVE_SPEED * direction
  12. velocity.y += (15 / delta) * delta
  13. velocity.y = clamp(velocity.y, -INF, 150)
  14. if is_on_floor():
  15. velocity.y = -150
  16. if is_on_wall() or is_on_ceiling():
  17. hit()
  18. move_and_slide()
  19. func hit(play_sfx := true) -> void:
  20. if play_sfx:
  21. AudioManager.play_sfx("bump", global_position)
  22. summon_explosion()
  23. queue_free()
  24. func summon_explosion() -> void:
  25. var node = FIREBALL_EXPLOSION.instantiate()
  26. node.global_position = global_position
  27. add_sibling(node)