Skip to content

Instantly share code, notes, and snippets.

@default1200
Created July 11, 2023 23:00
Show Gist options
  • Save default1200/5cfe2cb8eae54831bafdc868f85ad0ca to your computer and use it in GitHub Desktop.
Save default1200/5cfe2cb8eae54831bafdc868f85ad0ca to your computer and use it in GitHub Desktop.
Health.gd for progress bar help
extends Node
signal max_changed(new_max)
signal changed(new_amount)
export(int) var max_amount = 10 setget set_max
onready var current = max_amount setget set_current
func _ready():
_initialize()
func set_max(new_max):
max_amount = new_max
max_amount = max(1, new_max)
emit_signal("max_changed", max_amount)
func set_current(new_value):
current = new_value
current = clamp(current, 0, max_amount)
emit_signal("changed", current)
if current == 0:
emit_signal("depleted")
func _initialize():
emit_signal("max_changed", max_amount)
emit_signal("changed", current)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment