the-crypt/Player/PlayerStats.gd

57 lines
1.5 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-23 19:08:59 -05:00
Player.health = Hearts.max_value
Player.energy = Energybar.max_value
2020-07-20 23:24:09 -05:00
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-23 19:08:59 -05:00
Player.health = clamp(value, Hearts.min_value, Hearts.max_value)
Hearts.value = Player.health
2020-07-17 19:18:59 -05:00
func get_health():
2020-07-23 19:08:59 -05:00
return Player.health
2020-07-17 19:18:59 -05:00
func set_energy(value):
2020-07-23 19:08:59 -05:00
Player.energy = clamp(value, Energybar.min_value, Energybar.max_value)
Energybar.value = Player.energy
if Player.energy == 0:
2020-07-19 19:15:43 -05:00
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
2020-07-23 19:08:59 -05:00
return Player.energy
2020-07-19 19:15:43 -05:00
func get_accurate_energy():
2020-07-23 19:08:59 -05:00
return Player.energy
2020-07-17 19:18:59 -05:00
func interrupt_regen():
Regen.start()