Health.gd 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. extends Node2D
  2. export var health_max = 0
  3. onready var health = health_max
  4. signal die
  5. signal damage(dmg)
  6. export(NodePath) var progressbar
  7. export(NodePath) var text
  8. var regen = 0.0
  9. var regen_time = 7
  10. var reactive_dmg = 0.0
  11. var buff = 0
  12. func _physics_process(delta):
  13. buff += 1
  14. if fmod(buff,regen_time*60) == 00:
  15. print('regen')
  16. _damage(-regen * health_max ,'',self)
  17. func _damage(dmg, effect, caller):
  18. health -= dmg
  19. health = min(health,health_max)
  20. # health = clamp(health,0,health_max)
  21. emit_signal('damage', dmg)
  22. print('dmg to ' + str(get_path()) + " : " + str(health) + " : " +str(dmg))
  23. if health <= 0:
  24. emit_signal('die')
  25. caller._expgain(get_parent().exppt)
  26. effect_processor(effect)
  27. if has_node(progressbar):
  28. get_node(progressbar).set_value( health )
  29. get_node(progressbar).set_max( health_max )
  30. get_node(text).set_text( str(health) )
  31. func _expgain(arg):
  32. pass
  33. func _ready():
  34. if has_node(progressbar):
  35. get_node(progressbar).set_value( health )
  36. get_node(progressbar).set_max( health_max )
  37. get_node(text).set_text( str(health_max) )
  38. func effect_processor(effect):
  39. pass