the-crypt/ui/PlayerStats.gd

43 lines
1.1 KiB
GDScript3
Raw Normal View History

2020-07-17 19:18:59 -05:00
extends CanvasLayer
2020-07-18 00:07:44 -05:00
onready var Hearts: TextureProgress = $"Player UI Frame 2/Hearts"
onready var Energybar: TextureProgress = $"Player UI Frame 2/Energy"
2020-07-17 19:18:59 -05:00
onready var Regen: Timer = $Regen
2020-07-19 19:15:43 -05:00
onready var BurnoutSprite: Sprite = $"Player UI Frame 2/Energy Burnout"
2020-07-17 19:18:59 -05:00
var health = 3 setget set_health, get_health
2020-07-18 00:07:44 -05:00
var energy = 5 setget set_energy, get_energy
2020-07-19 19:15:43 -05:00
var is_burnout = false
2020-07-17 19:18:59 -05:00
func _on_Regen_timeout():
2020-07-19 19:15:43 -05:00
set_energy(get_accurate_energy() + 1)
if get_accurate_energy() == Energybar.max_value:
is_burnout = false
2020-07-17 19:18:59 -05:00
func _process(delta):
2020-07-19 19:15:43 -05:00
if get_accurate_energy() < Energybar.max_value and Regen.is_stopped():
2020-07-17 19:18:59 -05:00
Regen.start()
2020-07-19 19:57:34 -05:00
BurnoutSprite.visible = is_burnout
2020-07-17 19:18:59 -05:00
func set_health(value):
Hearts.value = clamp(value, Hearts.min_value, Hearts.max_value)
func get_health():
return Hearts.value
func set_energy(value):
Energybar.value = clamp(value, Energybar.min_value, Energybar.max_value)
2020-07-19 19:15:43 -05:00
if Energybar.value == 0:
is_burnout = true
2020-07-17 19:18:59 -05:00
func get_energy():
2020-07-19 19:15:43 -05:00
if is_burnout == true:
return 0
return Energybar.value
func get_accurate_energy():
2020-07-17 19:18:59 -05:00
return Energybar.value
func interrupt_regen():
Regen.start()