project_teddy/scripts/HUD.gd

128 lines
3.9 KiB
GDScript3
Raw Normal View History

extends Control
2023-03-16 13:37:17 -06:00
var roundTimer := 300.0
2023-03-05 22:08:14 -07:00
var minutes
var seconds
2023-03-06 00:35:22 -07:00
var scores: Array[int] = []
var scoresInitalized = false
2023-03-16 13:37:17 -06:00
var runnerSelected = false
2023-03-06 00:35:22 -07:00
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-16 13:37:17 -06:00
if Global.iAmRunner:
rpc("sync_runner_hp", $Health.value)
2023-03-11 18:50:43 -07:00
if Global.musicUpdated == true:
Global.musicUpdated = false
$musicPanel/playingLabel.text = Global.musicName
$musicPanel/authorLabel.text = Global.musicAuthor
$musicPanel.visible = true
await get_tree().create_timer(3).timeout
$musicPanel.visible = false
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())
if Global.gamemode == "Deathmatch":
Global.HUDStartLabelText = ""
2023-03-16 13:37:17 -06:00
if Global.gamemode == "Runner":
2023-03-16 21:42:32 -06:00
if Global.teddyAuthorityID == 1:
if runnerSelected == false:
runnerSelected = true
select_runner(Global.connectedPlayers, Global.connectedPlayersByPeerID)
2023-03-16 13:37:17 -06:00
if Global.runnerDead == true:
print("RUNNER IS DEAD")
rpc("runner_dead", Global.chosenRunner)
runner_dead(Global.chosenRunner)
2023-03-05 22:08:14 -07:00
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)
2023-03-16 23:40:33 -06:00
rpc("killed_text", Global.lastPersonToHitMe, Global.playerName)
killed_text(Global.lastPersonToHitMe, Global.playerName)
2023-03-06 00:35:22 -07:00
if Global.roundInSession == false:
for i in range(Global.connectedPlayers.size()):
if Global.connectedPlayers[i]:
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 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
2023-03-16 13:37:17 -06:00
func select_runner(players, playersID):
var numOfPlayers = players.size()
var getIndexSize = numOfPlayers - 1
var playerChosen = RandomNumberGenerator.new().randi_range(0, getIndexSize)
var runner = players[playerChosen]
Global.chosenRunner = runner
rpc("selected_runner", runner)
selected_runner(runner)
2023-03-16 21:42:32 -06:00
var runnerID = playersID[playerChosen]
2023-03-16 13:37:17 -06:00
if runnerID == 1:
runner_stats()
else:
rpc_id(runnerID, "runner_stats")
print("Runner: ", runner, ", ID: ", runnerID)
@rpc("any_peer", "reliable")
func selected_runner(player):
2023-03-16 21:42:32 -06:00
print(Global.connectedPlayersByPeerID)
2023-03-16 13:37:17 -06:00
Global.chosenRunner = player
2023-03-16 21:42:32 -06:00
if Global.playerName != player:
not_runner(player)
2023-03-16 13:37:17 -06:00
func not_runner(player):
$RunnerPanel.visible = true
Global.HUDStartLabelText = str(player + " is the runner!")
@rpc("any_peer", "reliable")
func runner_stats():
await get_tree().create_timer(0.1).timeout
Global.iAmRunner = true
$Health.max_value = 2000
Global.playerHealth = 2000
Global.HUDStartLabelText = "You are the runner!"
$RunnerPanel.visible = false
print(Global.HUDStartLabelText)
@rpc("any_peer", "reliable")
func runner_dead(runner):
Global.roundInSession = false
Global.HUDStartLabelText = "Runner has died! Killers win!"
@rpc("any_peer", "reliable")
func sync_runner_hp(value):
$RunnerPanel/Health.value = value
2023-03-16 23:40:33 -06:00
@rpc("any_peer", "reliable")
func killed_text(killer, killed):
$killedLabel.text = killer + " killed " + killed