project_teddy/scripts/HUD.gd

58 lines
1.7 KiB
GDScript3
Raw Normal View History

extends Control
2023-03-05 22:08:14 -07:00
var roundTimer := 600.0
var minutes
var seconds
2023-03-06 00:35:22 -07:00
var scores: Array[int] = []
var scoresInitalized = false
func _ready():
2023-03-05 22:08:14 -07:00
minutes = roundTimer / 60
seconds = fmod(roundTimer, 60)
$timer.text = "%02d:%02d" % [minutes, seconds]
func _process(delta):
2023-03-05 22:08:14 -07:00
$startLabel.text = Global.HUDStartLabelText
$Fatigue.value = Global.fatigue
$Health.value = Global.playerHealth
2023-03-05 22:08:14 -07:00
if Global.roundInSession == true and roundTimer >= 0:
2023-03-06 00:35:22 -07:00
if scoresInitalized == false:
scoresInitalized = true
fill_scores_with_zeros(Global.connectedPlayers.size())
2023-03-05 22:08:14 -07:00
$startLabel.text = ""
roundTimer -= delta
minutes = roundTimer / 60
seconds = fmod(roundTimer, 60)
$timer.text = "%02d:%02d" % [minutes, seconds]
if roundTimer <= 0.0:
Global.HUDStartLabelText = "GAME OVER"
2023-03-06 00:35:22 -07:00
if Global.HUDPlayerDied:
Global.HUDPlayerDied = false
rpc("update_scores", Global.lastPersonToHitMe)
update_scores(Global.lastPersonToHitMe)
if Global.roundInSession == false:
for i in range(Global.connectedPlayers.size()):
if Global.connectedPlayers[i]:
var objectLabel = "player" + str(i) + "Label"
var numlabel = i + 1
get_node("player" + str(numlabel) + "Label").text = Global.connectedPlayers[i] + ": " + "0"
@rpc("any_peer", "reliable")
func update_scores(name):
for i in range(Global.connectedPlayers.size()):
if Global.connectedPlayers[i] == str(name):
2023-03-06 00:35:22 -07:00
var objectLabel = "player" + str(i) + "Label"
var numlabel = i + 1
var currentScore = scores[i] + 1
scores[i] += 1
get_node("player" + str(numlabel) + "Label").text = Global.connectedPlayers[i] + ": " + str(currentScore)
else:
print("Name ", i, " wasn't found in the list!")
2023-03-06 00:35:22 -07:00
func fill_scores_with_zeros(num_of_players):
scores.resize(num_of_players)
for i in num_of_players:
scores[i] = 0