combatant.gd 705 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. class_name Combatant
  2. extends Node
  3. signal turn_finished
  4. @export var damage := 1
  5. @export var defense := 1
  6. var active := false: set = set_active
  7. func set_active(value: bool) -> void:
  8. active = value
  9. set_process(value)
  10. set_process_input(value)
  11. if not active:
  12. return
  13. if $Health.armor >= $Health.base_armor + defense:
  14. $Health.armor = $Health.base_armor
  15. func attack(target: Combatant) -> void:
  16. target.take_damage(damage)
  17. turn_finished.emit()
  18. func defend() -> void:
  19. $Health.armor += defense
  20. turn_finished.emit()
  21. func flee() -> void:
  22. turn_finished.emit()
  23. func take_damage(damage_to_take: float) -> void:
  24. $Health.take_damage(damage_to_take)
  25. $Sprite2D/AnimationPlayer.play("take_damage")