lets-godot-roguelike
lets-godot-roguelike copied to clipboard
Fighter HP
Hitpoints should require little explanation.
Fighter should have two vars:
export(int) var max_HP = 10
var HP = 10 setget _set_HP
We will do some work with our HP var. This will follow the same workflow we will have for all variables that need this level of robustness.
We then want to define a setter function, that is called whenever our HP value is set:
func _set_HP( what ):
The setter function also emits a signal:
signal HP_changed( new_HP )
We also have the setter func check to see if our new HP is 0 (or lower). In that case, call a die()
function on our Fighter script:
func die():
Temporarily, the die() method will just print a statement.