conteneur_briques.gd 660 B

123456789101112131415161718192021222324
  1. class_name ConteneurDeBriques
  2. extends Node2D
  3. signal plus_de_briques
  4. @onready var nombre_enfants: int = get_children().size()
  5. func _ready() -> void:
  6. for node: Node in get_children():
  7. assert(node is Brique or node is ConteneurDeBriques, "Ne peut contenir que des briques")
  8. if node is Brique:
  9. var brique: Brique = node as Brique
  10. brique.eclatee.connect(_quand_enfant_detruit)
  11. elif node is ConteneurDeBriques:
  12. var contenant: ConteneurDeBriques = node as ConteneurDeBriques
  13. contenant.plus_de_briques.connect(_quand_enfant_detruit)
  14. func _quand_enfant_detruit() -> void:
  15. nombre_enfants -= 1
  16. if nombre_enfants <= 0:
  17. plus_de_briques.emit()