Skip to content

Instantly share code, notes, and snippets.

@default1200
Created July 12, 2023 18:40
Show Gist options
  • Save default1200/107c1ba5f0128fd25448c0d26a5ee7cb to your computer and use it in GitHub Desktop.
Save default1200/107c1ba5f0128fd25448c0d26a5ee7cb to your computer and use it in GitHub Desktop.
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
var current_hp
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)
func hp_changed(_value : int):
current_hp += _value
$progress_bar.value = current_hp
func _on_Area2D_body_entered(body: Node) -> void:
print("lol")
current += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment