Last active
April 15, 2019 21:50
-
-
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..^^)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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