30 lines
942 B
GDScript
30 lines
942 B
GDScript
extends Control
|
|
@onready var global = $"/root/Player"
|
|
var countingGameTime:bool
|
|
var gameTimer = 0.0
|
|
var killCount = 0
|
|
signal deathMenu(time,kills)
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
global.connect("playerHealth",updateHealthBar)
|
|
global.connect("playerDeath",playerDeath)
|
|
countingGameTime = true
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
if countingGameTime == true:
|
|
gameTimer += delta
|
|
$"topLeft/debug".text = str(snappedf(gameTimer,0.1))
|
|
|
|
func updateHealthBar(health):
|
|
var healthBarTween = get_tree().create_tween()
|
|
healthBarTween.set_trans(Tween.TRANS_EXPO)
|
|
healthBarTween.tween_property($"topLeft/health","value",health,0.1)
|
|
$"topLeft/health/healthText".text = str(health)
|
|
|
|
func playerDeath():
|
|
deathMenu.emit(snappedf(gameTimer,0.1),killCount)
|
|
gameTimer = 0.0
|
|
killCount = 0
|
|
countingGameTime = false
|