balle_spectrale.gd 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. class_name BalleSpectrale
  2. extends Balle
  3. const BalleDeSpectraleScene: PackedScene = preload("res://composants/objets/balle/balle_spectrale/balle_spectrale.tscn")
  4. const CALQUE_COLLISION_BRIQUE_INDEXE: int = 5
  5. const CALQUE_COLLISION_BRIQUE_ACTIVATION: int = pow(2, CALQUE_COLLISION_BRIQUE_INDEXE - 1)
  6. var _est_tangible: bool = true
  7. @onready var image_tangible: Sprite2D = $ImageTangible
  8. @onready var image_spectre: Sprite2D = $ImageSpectre
  9. func rendre_tangible(doit_etre_tangible: bool) -> void:
  10. if doit_etre_tangible == _est_tangible:
  11. return # etat demande deja atteint
  12. image_tangible.visible = doit_etre_tangible
  13. image_spectre.visible = not doit_etre_tangible
  14. if doit_etre_tangible:
  15. collision_mask += CALQUE_COLLISION_BRIQUE_ACTIVATION
  16. else:
  17. collision_mask -= CALQUE_COLLISION_BRIQUE_ACTIVATION
  18. _est_tangible = doit_etre_tangible # l'etat courant a change
  19. ## La spectrale redevient tangible au premier rebond
  20. func _rebondir(impact: KinematicCollision2D) -> void:
  21. rendre_tangible(not impact.get_collider() is Raquette)
  22. super._rebondir(impact)
  23. ## Transforme une balle quelconque en balle de feu
  24. static func transformer(balle: Balle) -> void:
  25. var balle_spectrale: BalleSpectrale = BalleDeSpectraleScene.instantiate()
  26. balle.add_sibling.call_deferred(balle_spectrale) # Appeler plus tard sinon Godot pas content
  27. balle_spectrale.recopier(balle)
  28. balle.queue_free()