the-crypt/ui/PlayerStats.gd

62 lines
1.6 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
2020-07-20 23:24:09 -05:00
func _ready():
2020-07-21 00:13:31 -05:00
if Player.health == null:
2020-07-20 23:24:09 -05:00
Player.health = Hearts.max_value
2020-07-21 00:13:31 -05:00
if Player.energy == null:
2020-07-20 23:24:09 -05:00
Player.energy = Energybar.max_value
print("max")
set_health(Player.health)
set_energy(Player.energy)
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-21 00:13:31 -05:00
if Player.health == null:
Player.health = Hearts.max_value
if Player.energy == null:
Player.energy = Energybar.max_value
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-20 23:24:09 -05:00
set_health(Player.health)
set_energy(Player.energy)
2020-07-17 19:18:59 -05:00
func set_health(value):
2020-07-21 15:50:32 -05:00
if Hearts.value > value:
get_parent().play_hitsound()
2020-07-17 19:18:59 -05:00
Hearts.value = clamp(value, Hearts.min_value, Hearts.max_value)
2020-07-20 23:24:09 -05:00
Player.health = get_health()
2020-07-17 19:18:59 -05:00
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-20 23:24:09 -05:00
Player.energy = get_accurate_energy()
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()