extends Control var roundTimer = Global.roundTimer var minutes var seconds var scores: Array[int] = [] var scoresInitalized = false var playerSelected = false var roundOver = false var TraitorPlayersKilled = 0 var TTTInnocentDead = false var oldPlayerSize = 0 var initalizedPlayerPanelSize = 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 roundOver: if Input.is_action_just_pressed("start_game"): print("Player with authority ID of " + str(Global.teddyAuthorityID) + " attempted to restart the round!") if Global.teddyAuthorityID == 1: restart_round() rpc("restart_round") if Global.mapName == "Tutorial": if not Global.playerDisable: tutorial() if not Global.tutorialComplete: $musicPanel.visible = false 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 playerSelected == false: playerSelected = true select_runner(Global.connectedPlayers, Global.connectedPlayersByPeerID) if Global.specialDead == true: print("RUNNER IS DEAD") rpc("runner_dead", Global.chosenPlayer) runner_dead(Global.chosenPlayer) if Global.iAmSpecial: rpc("sync_runner_hp", $Health.value) if Global.gamemode == "TTT": $connectedPlayers.visible = false if Global.teddyAuthorityID == 1: if playerSelected == false: playerSelected = true select_traitor(Global.connectedPlayers, Global.connectedPlayersByPeerID) if Global.iAmSpecial: if TraitorPlayersKilled >= (Global.connectedPlayers.size() - 1): rpc("traitor_wins") traitor_wins() if Global.iAmDeadAndInnocent: Global.iAmDeadAndInnocent = false TraitorPlayersKilled += 1 if Global.specialDead: rpc("traitor_dead") traitor_dead() if Global.iAmDeadAndInnocent and not Global.iAmSpecial: Global.iAmDeadAndInnocent = false if not TTTInnocentDead: TTTInnocentDead = true rpc("innocent_dead") roundTimer -= delta minutes = roundTimer / 60 seconds = fmod(roundTimer, 60) $timer.text = "%02d:%02d" % [minutes, seconds] if roundTimer <= 0.0: if not roundOver: roundOver = true Global.roundInSession = false if Global.gamemode == "Deathmatch": Global.HUDStartLabelText = "GAME OVER" elif Global.gamemode == "Runner": Global.HUDStartLabelText = "RUNNER WINS" elif Global.gamemode == "TTT": Global.HUDStartLabelText = "TRAITOR LOOSES" play_audio(load("res://sounds/buzzer.mp3")) 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.AIKilled: Global.AIKilled = false update_scores(Global.playerName) killed_text(Global.playerName, "AI") if Global.roundInSession == false: if not roundOver: for i in range(Global.connectedPlayers.size()): if i <= 9: if Global.connectedPlayers[i]: var numlabel = i + 1 get_node("connectedPlayers/player" + str(numlabel) + "Label").text = Global.connectedPlayers[i] + ": " + "0" roundTimer = Global.roundTimer if oldPlayerSize != Global.connectedPlayers.size(): oldPlayerSize = Global.connectedPlayers.size() if not Global.connectedPlayers.size() > 10: if initalizedPlayerPanelSize == false: initalizedPlayerPanelSize = true for i in Global.connectedPlayers.size(): $connectedPlayers.size.y += 26 else: $connectedPlayers.size.y += 26 @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 if numlabel <= 10: get_node("connectedPlayers/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) if num_of_players <= 10: 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.chosenPlayer = 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.chosenPlayer = player if Global.playerName != player: not_runner(player) func not_runner(player): $RunnerPanel.visible = true $killedLabel.visible = false Global.HUDStartLabelText = str(player + " is the runner!") var runnerHealth = 0 @rpc("any_peer", "reliable") func runner_stats(): await get_tree().create_timer(0.1).timeout Global.iAmSpecial = true for i in Global.connectedPlayers.size(): runnerHealth += 500 $Health.max_value = runnerHealth Global.playerHealth = runnerHealth Global.HUDStartLabelText = "You are the runner!" $RunnerPanel.visible = false print(Global.HUDStartLabelText) print("Runner created with ", runnerHealth, " health!") var map = Global.currentMapNode.get_path() var playerID = Global.teddyAuthorityID var gun = get_node(str(map) + '/' + str(playerID) + '/CollisionShape3D/Neck/Camera3D/Gun') gun.visible = false rpc("sync_runner_health", runnerHealth) @rpc("any_peer", "reliable") func sync_runner_health(health): $RunnerPanel/Health.max_value = health @rpc("any_peer", "reliable") func runner_dead(runner): Global.specialDead = false Global.roundInSession = false Global.iAmSpecial = false Global.chosenPlayer = null playerSelected = false Global.HUDStartLabelText = "Runner has died! Killers win!" func select_traitor(players, playersID): var numOfPlayers = players.size() var getIndexSize = numOfPlayers - 1 var playerChosen = RandomNumberGenerator.new().randi_range(0, getIndexSize) var traitor = players[playerChosen] Global.chosenPlayer = traitor rpc("selected_traitor", traitor) selected_traitor(traitor) var traitorID = playersID[playerChosen] if traitorID == 1: traitor() else: rpc_id(traitorID, "traitor") print("Traitor: ", traitor, ", ID: ", traitorID) @rpc("any_peer", "reliable") func selected_traitor(player): print(Global.connectedPlayersByPeerID) Global.chosenPlayer = player if Global.playerName != player: not_traitor() @rpc("any_peer", "reliable") func traitor(): await get_tree().create_timer(0.1).timeout Global.iAmSpecial = true Global.HUDStartLabelText = "You are the traitor!" func not_traitor(): Global.HUDStartLabelText = str("You are innocent!") @rpc("any_peer", "reliable") func innocent_dead(): Global.iAmDeadAndInnocent = true @rpc("any_peer", "reliable") func traitor_wins(): Global.roundInSession = false Global.HUDStartLabelText = "Traitor wins! Round is over!" @rpc("any_peer", "reliable") func traitor_dead(): Global.roundInSession = false Global.HUDStartLabelText = "Traitor is dead! Innocents 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 @rpc("any_peer", "reliable") func restart_round(): for i in range(Global.connectedPlayers.size()): if Global.connectedPlayers[i]: var numlabel = i + 1 get_node("connectedPlayers/player" + str(numlabel) + "Label").text = Global.connectedPlayers[i] + ": " + "0" $connectedPlayers.visible = true scoresInitalized = false $Health.max_value = 100 Global.playerHealth = 100 Global.chosenPlayer = null playerSelected = false Global.iAmSpecial = false Global.specialDead = false Global.iAmDeadAndInnocent = false var map = Global.currentMapNode.get_path() var playerID = Global.teddyAuthorityID var gun = get_node(str(map) + '/' + str(playerID) + '/CollisionShape3D/Neck/Camera3D/Gun') gun.visible = true roundOver = false Global.roundInSession = true func gun_visible(status): var map = Global.currentMapNode.get_path() var playerID = Global.teddyAuthorityID var gun = get_node(str(map) + '/' + str(playerID) + '/CollisionShape3D/Neck/Camera3D/Gun') if status == true: gun.visible = false elif status == false: gun.visible = true ### 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 $connectedPlayers/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 var prev_cam_rot 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")) prev_cam_rot = get_node(str(Global.selfTeddy) + '/CollisionShape3D/Neck/Camera3D').global_rotation 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 not stage3_continue: if Input.is_action_just_pressed("start_game"): stage3_continue = true $connectedPlayers.size.y += 26 $connectedPlayers/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(17).timeout $TutorialPanel.visible = false Global.tutorialComplete = true tutorial_6() var stage6 = false var stage6_continue = false func tutorial_6(): if not stage6 and roundTimer <= 1.0: print("stage6 fr") stage6 = true await get_tree().create_timer(3).timeout play_audio(load("res://voice/tutorial/tutorial_6.mp3")) Global.tutorialTimerCompleted = true if Input.is_action_just_pressed("start_game"): stage6_continue = true if stage6_continue: stage6_continue = false Global.tutorialTimerCompleted = false func play_audio(audio): audio_stream_player.set_stream(audio) add_child(audio_stream_player) audio_stream_player.play()