Skip to content

Instantly share code, notes, and snippets.

@CSaratakij
Last active April 15, 2019 21:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CSaratakij/bf842305cc3be830738fe8293858bd36 to your computer and use it in GitHub Desktop.
Save CSaratakij/bf842305cc3be830738fe8293858bd36 to your computer and use it in GitHub Desktop.
GDScript - Health script with no if-else statement (man...I should have used clamp method for a long long time..^^)
extends Node
const MIN_HEALTH = 0
const MAX_HEALTH = 100
export var current_health = MAX_HEALTH
func _ready():
current_health = clamp(current_health, MIN_HEALTH, MAX_HEALTH)
func is_alive():
return current_health > 0
func full_regen():
current_health = MAX_HEALTH
func clear():
current_health = MIN_HEALTH
func regen(point):
current_health = clamp((current_health + point), MIN_HEALTH, MAX_HEALTH)
func remove(point):
current_health = clamp((current_health - point), MIN_HEALTH, MAX_HEALTH)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment