ScoreNoteSpawner.gd 893 B

123456789101112131415161718192021222324252627
  1. class_name ScoreNoteSpawner
  2. extends Node
  3. const ONE_UP_NOTE = preload("res://Scenes/Parts/OneUpNote.tscn")
  4. const SCORE_NOTE = preload("res://Scenes/Parts/ScoreNote.tscn")
  5. @export var note_offset := Vector2(0, -8)
  6. @export var add_score := false
  7. @export var play_sfx := false
  8. func spawn_note(amount = 100, amount_2 := 0) -> void:
  9. if amount is not int or amount_2 != 0:
  10. amount = amount_2
  11. var note = SCORE_NOTE.instantiate()
  12. note.global_position = owner.global_position + note_offset
  13. if add_score:
  14. Global.score += amount
  15. note.get_node("Container/Label").text = str(amount)
  16. if play_sfx:
  17. play_death_sfx()
  18. Global.current_level.add_child(note)
  19. func play_death_sfx() -> void:
  20. AudioManager.play_sfx("kick", owner.global_position)
  21. func spawn_one_up_note() -> void:
  22. var note = ONE_UP_NOTE.instantiate()
  23. note.global_position = owner.global_position + note_offset
  24. owner.add_sibling(note)