project_teddy/scripts/HUD.gd
2023-03-19 13:56:40 -06:00

322 lines
9.5 KiB
GDScript

extends Control
var roundTimer = Global.roundTimer
var minutes
var seconds
var scores: Array[int] = []
var scoresInitalized = false
var runnerSelected = false
func _ready():
await get_tree().create_timer(0.1).timeout
roundTimer = Global.roundTimer
minutes = roundTimer / 60
seconds = fmod(roundTimer, 60)
$timer.text = "%02d:%02d" % [minutes, seconds]
func _process(delta):
$startLabel.text = Global.HUDStartLabelText
$Fatigue.value = Global.fatigue
$Health.value = Global.playerHealth
if Global.mapName == "Tutorial":
tutorial()
if not Global.tutorialComplete:
$musicPanel.visible = false
if Global.iAmRunner:
rpc("sync_runner_hp", $Health.value)
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
if Global.roundInSession == true and roundTimer >= 0:
if scoresInitalized == false:
scoresInitalized = true
fill_scores_with_zeros(Global.connectedPlayers.size())
if Global.gamemode == "Deathmatch":
Global.HUDStartLabelText = ""
if Global.gamemode == "Runner":
if Global.teddyAuthorityID == 1:
if runnerSelected == false:
runnerSelected = true
select_runner(Global.connectedPlayers, Global.connectedPlayersByPeerID)
if Global.runnerDead == true:
print("RUNNER IS DEAD")
rpc("runner_dead", Global.chosenRunner)
runner_dead(Global.chosenRunner)
if Global.mapName == "Tutorial":
pass
roundTimer -= delta
minutes = roundTimer / 60
seconds = fmod(roundTimer, 60)
$timer.text = "%02d:%02d" % [minutes, seconds]
if roundTimer <= 0.0:
Global.HUDStartLabelText = "GAME OVER"
if Global.HUDPlayerDied:
Global.HUDPlayerDied = false
rpc("update_scores", Global.lastPersonToHitMe)
update_scores(Global.lastPersonToHitMe)
rpc("killed_text", Global.lastPersonToHitMe, Global.playerName)
killed_text(Global.lastPersonToHitMe, Global.playerName)
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):
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!")
func fill_scores_with_zeros(num_of_players):
scores.resize(num_of_players)
for i in num_of_players:
scores[i] = 0
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)
var runnerID = playersID[playerChosen]
if runnerID == 1:
runner_stats()
else:
rpc_id(runnerID, "runner_stats")
print("Runner: ", runner, ", ID: ", runnerID)
@rpc("any_peer", "reliable")
func selected_runner(player):
print(Global.connectedPlayersByPeerID)
Global.chosenRunner = player
if Global.playerName != player:
not_runner(player)
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
@rpc("any_peer", "reliable")
func killed_text(killer, killed):
$killedLabel.text = killer + " killed " + killed
### TUTORIAL STUFF ###
var audio_stream_player = AudioStreamPlayer.new()
var w = false
var a = false
var s = false
var d = false
var ran_timer = false
var stage1 = false
func tutorial():
if not stage1:
stage1 = true
$TutorialPanel/camera.visible = false
$TutorialPanel/Mouse.visible = false
$TutorialPanel/Arrow_up.visible = false
$TutorialPanel/Arrow_left.visible = false
$TutorialPanel/Arrow_down.visible = false
$TutorialPanel/Arrow_right.visible = false
$TutorialPanel/shoot.visible = false
$TutorialPanel/Leftmouse.visible = false
$TutorialPanel/start.visible = false
$TutorialPanel/enter.visible = false
$TutorialPanel/EnterKey.visible = false
$TutorialPanel/learning.visible = false
$TutorialPanel/aim.visible = false
$TutorialPanel/timer.visible = false
$TutorialPanel/zero.visible = false
$TutorialPanel/done.visible = false
$TutorialPanel.visible = true
$TutorialPanel/welcome.visible = true
$TutorialPanel/move.visible = true
$TutorialPanel/Wasd.visible = true
$player1Label.text = Global.playerName
Global.HUDStartLabelText = " "
play_audio(load("res://voice/tutorial/tutorial_1.mp3"))
if not w:
if Input.is_action_just_pressed("player_forward"):
w = true
$TutorialPanel/W.visible = true
if not a:
if Input.is_action_just_pressed("player_left"):
a = true
$TutorialPanel/A.visible = true
if not s:
if Input.is_action_just_pressed("player_backward"):
s = true
$TutorialPanel/S.visible = true
if not d:
if Input.is_action_just_pressed("player_right"):
d = true
$TutorialPanel/D.visible = true
if w and a and s and d:
if not ran_timer:
await get_tree().create_timer(0.5).timeout
ran_timer = true
else:
tutorial_2()
var up = false
var left = false
var down = false
var right = false
@onready var prev_cam_rot = get_node(str(Global.selfTeddy) + '/CollisionShape3D/Neck/Camera3D').global_rotation
var ran_timer2 = false
var ran_timer3 = false
var stage2 = false
func tutorial_2():
if not stage2:
stage2 = true
$TutorialPanel/W.visible = false
$TutorialPanel/A.visible = false
$TutorialPanel/S.visible = false
$TutorialPanel/D.visible = false
$TutorialPanel/Wasd.visible = false
$TutorialPanel/welcome.visible = false
$TutorialPanel/move.visible = false
$TutorialPanel/camera.visible = true
$TutorialPanel/Mouse.visible = true
$TutorialPanel/Arrow_up.visible = true
$TutorialPanel/Arrow_left.visible = true
$TutorialPanel/Arrow_down.visible = true
$TutorialPanel/Arrow_right.visible = true
play_audio(load("res://voice/tutorial/tutorial_2.mp3"))
if not ran_timer2:
await get_tree().create_timer(0.5).timeout
ran_timer2 = true
else:
var cam_rot = get_node(str(Global.selfTeddy) + '/CollisionShape3D/Neck/Camera3D').global_rotation
if not up:
if cam_rot.x > prev_cam_rot.x:
up = true
$TutorialPanel/ArrowFilled_up.visible = true
if not down:
if cam_rot.x < prev_cam_rot.x:
down = true
$TutorialPanel/ArrowFilled_down.visible = true
if not left:
if cam_rot.y > prev_cam_rot.y:
left = true
$TutorialPanel/ArrowFilled_left.visible = true
if not right:
if cam_rot.y < prev_cam_rot.y:
right = true
$TutorialPanel/ArrowFilled_right.visible = true
prev_cam_rot = cam_rot
if up and left and right and down:
if not ran_timer3:
await get_tree().create_timer(0.5).timeout
ran_timer3 = true
else:
tutorial_3()
var stage3_continue = false
var stage3 = false
func tutorial_3():
if not stage3:
stage3 = true
$TutorialPanel/camera.visible = false
$TutorialPanel/Mouse.visible = false
$TutorialPanel/Arrow_up.visible = false
$TutorialPanel/Arrow_left.visible = false
$TutorialPanel/Arrow_down.visible = false
$TutorialPanel/Arrow_right.visible = false
$TutorialPanel/ArrowFilled_up.visible = false
$TutorialPanel/ArrowFilled_left.visible = false
$TutorialPanel/ArrowFilled_down.visible = false
$TutorialPanel/ArrowFilled_right.visible = false
$TutorialPanel/start.visible = true
$TutorialPanel/enter.visible = true
$TutorialPanel/EnterKey.visible = true
Global.HUDStartLabelText = "PRESS ENTER/RETURN TO START THE ROUND"
play_audio(load("res://voice/tutorial/tutorial_3.mp3"))
if Input.is_action_just_pressed("start_game"):
stage3_continue = true
$player2Label.text = "AI"
if stage3_continue:
tutorial_4()
var stage4_continue = false
var stage4 = false
func tutorial_4():
if not stage4:
stage4 = true
$TutorialPanel/start.visible = false
$TutorialPanel/enter.visible = false
$TutorialPanel/EnterKey.visible = false
$TutorialPanel/shoot.visible = true
$TutorialPanel/Leftmouse.visible = true
play_audio(load("res://voice/tutorial/tutorial_4.mp3"))
if Input.is_action_just_pressed("shoot"):
stage4_continue = true
if stage4_continue:
tutorial_5()
var stage5 = false
func tutorial_5():
if not stage5:
stage5 = true
$TutorialPanel/shoot.visible = false
$TutorialPanel/Leftmouse.visible = false
$TutorialPanel/learning.visible = true
$TutorialPanel/aim.visible = true
$TutorialPanel/timer.visible = true
$TutorialPanel/zero.visible = true
$TutorialPanel/done.visible = true
play_audio(load("res://voice/tutorial/tutorial_5.mp3"))
await get_tree().create_timer(14).timeout
$TutorialPanel.visible = false
Global.tutorialComplete = true
func play_audio(audio):
audio_stream_player.set_stream(audio)
add_child(audio_stream_player)
audio_stream_player.play()