void Update() { // TODO : Multi to be handle if (!GameManager.Instance.PlayerStart.PlayersReference[0].GetComponent <PlayerController>().PlayerIndexSet) { return; } if (GameManager.Instance.PlayerStart.PlayersReference[0].GetComponent <PlayerController>().IsUsingAController) { if (GamePad.GetState(GameManager.Instance.PlayerStart.PlayersReference[0].GetComponent <PlayerController>().playerIndex).Buttons.Start == ButtonState.Pressed) { if (SceneManager.GetActiveScene().name == MinigameManager.GetSceneNameFromMinigame(MiniGame.KickThemAll)) { SceneManager.LoadScene(1); // ugly? } //ExitToMainMenu(); } } else { if (Input.GetKeyDown(KeyCode.Escape)) { ExitToMainMenu(); } } // TODO: handle pause input here? }
////////////////////////////////////// EVENTS ////////////////////////////////////////// public void HasFinishedProcess(Player _player) { if (SceneManager.GetActiveScene().name == MinigameManager.GetSceneNameFromMinigame(MiniGame.KickThemAll)) { GameManager.Instance.ScoreScreenReference.RankPlayersByPoints(); } else { _player.HasFinishedTheRun = true; GameManager.Instance.ScoreScreenReference.RefreshScores(_player); } }
public void UnlockAssociatedMinigame() { if (costAreaType == CostAreaType.PayAndUnlockMiniGame) { isActive = false; teleporterToMiniGame.TeleportToMinigame(MinigameManager.GetSceneNameFromMinigame(minigameToUnlock)); // Replace by the child costText.transform.parent.gameObject.SetActive(false); rewardPreview.gameObject.SetActive(false); halo.gameObject.SetActive(false); teleporterToMiniGame.gameObject.SetActive(true); } }
public void RefreshScores(Player player) { float time = Time.timeSinceLevelLoad; int minutes = Mathf.FloorToInt(time / 60); int seconds = (int)time % 60; rank++; if (rank > 4) { Debug.LogWarning("RefreshScores should not have been called or rank has not been reset ..."); rank = 0; return; } String timeStr = string.Format("{0:00} : {1:00}", minutes, seconds); if (SceneManager.GetActiveScene().name == MinigameManager.GetSceneNameFromMinigame(MiniGame.KickThemAll)) { Debug.Log(transform.childCount); if (transform.childCount >= rank - 1) // who did this ugly line? { transform.GetChild(rank - 1).GetComponent <PlayerScore>().SetScoreMiniGamePtsOnly( (int)player.PlayerController.PlayerIndex, (player.Collectables[(int)CollectableType.Points]).ToString() ); transform.GetChild(rank - 1).gameObject.SetActive(true); } } else { if (rank == 1) { GameManager.Instance.LaunchFinalTimer(); } if (transform.childCount >= rank - 1) // who did this ugly line? { transform.GetChild(rank - 1).GetComponent <PlayerScore>().SetScoreDefault( (int)player.PlayerController.PlayerIndex, GameManager.Instance.isTimeOver ? "Timeout" : timeStr, (player.Collectables[(int)CollectableType.Points]).ToString() ); transform.GetChild(rank - 1).gameObject.SetActive(true); } } player.rank = rank; if (rank == 1) { player.Anim.SetBool("hasFinishedFirst", true); } else if (rank == 4) { player.Anim.SetBool("hasFinishedLast", true); } else { player.Anim.SetBool("hasFinished", true); } nbrOfPlayersAtTheEnd++; CheckEndGame(); }
void Update() { // Activation/Deactivation debug mode if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.RightShift)) { ActivateDebugMode(); } if (isDebugModeActive) { // TODO Antho: Handle evolution mode switch // Add evolution to current player if (Input.GetKey(KeyCode.Alpha1)) { if (Input.GetKeyDown(KeyCode.Alpha2)) { if (DebugPlayerSelected.GetComponent <EvolutionStrength>() == null) { GameManager.EvolutionManager.AddEvolutionComponent(DebugPlayerSelected.gameObject, GameManager.EvolutionManager.GetEvolutionByPowerName(Powers.Strength)); } Debug.Log("Added Strength on player " + DebugPlayerSelected.GetComponent <PlayerController>().PlayerIndex); } if (Input.GetKeyDown(KeyCode.Alpha3)) { if (DebugPlayerSelected.GetComponent <EvolutionAgile>() == null) { GameManager.EvolutionManager.AddEvolutionComponent(DebugPlayerSelected.gameObject, GameManager.EvolutionManager.GetEvolutionByPowerName(Powers.Agile)); } Debug.Log("Added Agile on player " + DebugPlayerSelected.GetComponent <PlayerController>().PlayerIndex); } if (Input.GetKeyDown(KeyCode.Alpha4)) { if (DebugPlayerSelected.GetComponent <EvolutionPlatformist>() == null) { GameManager.EvolutionManager.AddEvolutionComponent(DebugPlayerSelected.gameObject, GameManager.EvolutionManager.GetEvolutionByPowerName(Powers.Platformist)); } Debug.Log("Added Platformist on player " + DebugPlayerSelected.GetComponent <PlayerController>().PlayerIndex); } if (Input.GetKeyDown(KeyCode.Alpha5)) { if (DebugPlayerSelected.GetComponent <EvolutionGhost>() == null) { GameManager.EvolutionManager.AddEvolutionComponent(DebugPlayerSelected.gameObject, GameManager.EvolutionManager.GetEvolutionByPowerName(Powers.Ghost)); } Debug.Log("Added Ghost on player" + DebugPlayerSelected.GetComponent <PlayerController>().PlayerIndex); } // Debug platformist if (Input.GetKeyDown(KeyCode.Alpha6)) { if (DebugPlayerSelected.GetComponent <EvolutionPlatformist>() == null) { GameManager.EvolutionManager.AddEvolutionComponent(DebugPlayerSelected.gameObject, GameManager.EvolutionManager.GetEvolutionByPowerName(Powers.Platformist)); } EvolutionPlatformist evolution = DebugPlayerSelected.GetComponent <EvolutionPlatformist>(); evolution.CooldownCharge = 1.0f; evolution.PlatformLifetime = 300.0f; Debug.Log("Added Platformist on player " + DebugPlayerSelected.GetComponent <PlayerController>().PlayerIndex); } } // Spawn a collectable else if (Input.GetKey(KeyCode.Alpha2)) { if (Input.GetKeyDown(KeyCode.Alpha8)) { // TODO: broken //ResourceUtils.Instance.refPrefabLoot.SpawnCollectableInstance( // DebugPlayerSelected.transform.position + DebugPlayerSelected.transform.forward * 4.0f, Quaternion.identity, null, CollectableType.Points).GetComponent<Collectable>().Init(); DebugPlayerSelected.UpdateCollectableValue(CollectableType.Points, 10); Debug.Log("Pop some " + CollectableType.Points + " on the ground!"); } if (Input.GetKeyDown(KeyCode.Alpha3)) { // TODO: broken //ResourceUtils.Instance.refPrefabLoot.SpawnCollectableInstance( // DebugPlayerSelected.transform.position + DebugPlayerSelected.transform.forward * 4.0f, Quaternion.identity, null, CollectableType.Key).GetComponent<Collectable>().Init(); DebugPlayerSelected.UpdateCollectableValue(CollectableType.Key, 1); Debug.Log("Pop some " + CollectableType.Key + " on the ground!"); } if (Input.GetKeyDown(KeyCode.Alpha4)) { ResourceUtils.Instance.refPrefabLoot.SpawnCollectableInstance( DebugPlayerSelected.transform.position + DebugPlayerSelected.transform.forward * 4.0f, Quaternion.identity, null, CollectableType.StrengthEvolution1).GetComponent <Collectable>().Init(); Debug.Log("Pop some " + CollectableType.StrengthEvolution1 + " on the ground!"); } if (Input.GetKeyDown(KeyCode.Alpha5)) { ResourceUtils.Instance.refPrefabLoot.SpawnCollectableInstance( DebugPlayerSelected.transform.position + DebugPlayerSelected.transform.forward * 4.0f, Quaternion.identity, null, CollectableType.PlatformistEvolution1).GetComponent <Collectable>().Init(); Debug.Log("Pop some " + CollectableType.PlatformistEvolution1 + " on the ground!"); } if (Input.GetKeyDown(KeyCode.Alpha6)) { ResourceUtils.Instance.refPrefabLoot.SpawnCollectableInstance( DebugPlayerSelected.transform.position + DebugPlayerSelected.transform.forward * 4.0f, Quaternion.identity, null, CollectableType.AgileEvolution1).GetComponent <Collectable>().Init(); Debug.Log("Pop some " + CollectableType.AgileEvolution1 + " on the ground!"); } if (Input.GetKeyDown(KeyCode.Alpha7)) { ResourceUtils.Instance.refPrefabLoot.SpawnCollectableInstance( DebugPlayerSelected.transform.position + DebugPlayerSelected.transform.forward * 4.0f, Quaternion.identity, null, CollectableType.GhostEvolution1).GetComponent <Collectable>().Init(); Debug.Log("Pop some " + CollectableType.GhostEvolution1 + " on the ground!"); } } else { // Reset player if (Input.GetKeyDown(KeyCode.Alpha0)) { DebugPlayerSelected.Collectables = new int[(int)CollectableType.Size]; if (DebugPlayerSelected.GetComponent <EvolutionStrength>()) { Destroy(DebugPlayerSelected.GetComponent <EvolutionStrength>()); } if (DebugPlayerSelected.GetComponent <EvolutionAgile>()) { Destroy(DebugPlayerSelected.GetComponent <EvolutionAgile>()); } if (DebugPlayerSelected.GetComponent <EvolutionPlatformist>()) { Destroy(DebugPlayerSelected.GetComponent <EvolutionPlatformist>()); } if (DebugPlayerSelected.GetComponent <EvolutionGhost>()) { Destroy(DebugPlayerSelected.GetComponent <EvolutionGhost>()); } DebugPlayerSelected.Rb.velocity = Vector3.zero; Debug.Log("Reset current player! " + DebugPlayerSelected.GetComponent <PlayerController>().PlayerIndex); } // Respawn player if (Input.GetKeyDown(KeyCode.Alpha9)) { Respawner.RespawnProcess(DebugPlayerSelected); DebugPlayerSelected.Rb.velocity = Vector3.zero; Debug.Log("Reset current player to last respawn point! " + DebugPlayerSelected.GetComponent <PlayerController>().PlayerIndex); } // Pop player if (Input.GetKeyDown(KeyCode.Space)) { GameObject go = Instantiate(GameManager.Instance.PlayerStart.playerPrefab); go.transform.position = DebugPlayerSelected.transform.position + DebugPlayerSelected.transform.forward * 4.0f; go.transform.rotation = Quaternion.identity; Player currentPlayer = go.GetComponent <Player>(); currentPlayer.respawnPoint = DebugPlayerSelected.respawnPoint; PlayerController playerController = go.GetComponent <PlayerController>(); playerController.DEBUG_hasBeenSpawnedFromTool = true; playerController.PlayerIndex = (PlayerIndex)5; playerController.IsUsingAController = true; playerController.PlayerIndexSet = true; GameManager.Instance.PlayerStart.PlayersReference.Add(go); debugSpawnedPlayer = go.GetComponent <Player>(); Debug.Log("Player spawned! " + DebugPlayerSelected.GetComponent <PlayerController>().PlayerIndex); } if (Input.GetKeyDown(KeyCode.P)) { if (debugSpawnedPlayer == null) { Debug.Log("No spawned player to possess"); return; } if (!possessASpawnedPlayer) { PlayerController playerControllerOne = DebugPlayerSelected.GetComponent <PlayerController>(); playerControllerOne.DEBUG_hasBeenSpawnedFromTool = true; playerControllerOne.PlayerIndex = (PlayerIndex)5; GameObject tmpCamRef = DebugPlayerSelected.cameraReference; DebugPlayerSelected.cameraReference = debugSpawnedPlayer.cameraReference; debugSpawnedPlayer.cameraReference = tmpCamRef; if (DebugPlayerSelected.cameraReference != null) { DebugPlayerSelected.cameraReference.transform.GetChild(1).GetComponent <Cinemachine.CinemachineFreeLook>().LookAt = DebugPlayerSelected.transform; DebugPlayerSelected.cameraReference.transform.GetChild(1).GetComponent <Cinemachine.CinemachineFreeLook>().Follow = DebugPlayerSelected.transform; } if (debugSpawnedPlayer.cameraReference != null) { debugSpawnedPlayer.cameraReference.transform.GetChild(1).GetComponent <Cinemachine.CinemachineFreeLook>().LookAt = debugSpawnedPlayer.transform; debugSpawnedPlayer.cameraReference.transform.GetChild(1).GetComponent <Cinemachine.CinemachineFreeLook>().Follow = debugSpawnedPlayer.transform; } PlayerController playerControllerSpwn = debugSpawnedPlayer.GetComponent <PlayerController>(); playerControllerSpwn.DEBUG_hasBeenSpawnedFromTool = false; playerControllerSpwn.PlayerIndex = (PlayerIndex)0; Debug.Log("Possess player one! "); } else { PlayerController playerControllerSpwn = debugSpawnedPlayer.GetComponent <PlayerController>(); playerControllerSpwn.DEBUG_hasBeenSpawnedFromTool = true; playerControllerSpwn.PlayerIndex = (PlayerIndex)5; GameObject tmpCamRef = DebugPlayerSelected.cameraReference; DebugPlayerSelected.cameraReference = debugSpawnedPlayer.cameraReference; debugSpawnedPlayer.cameraReference = tmpCamRef; if (DebugPlayerSelected.cameraReference != null) { DebugPlayerSelected.cameraReference.transform.GetChild(1).GetComponent <Cinemachine.CinemachineFreeLook>().LookAt = DebugPlayerSelected.transform; DebugPlayerSelected.cameraReference.transform.GetChild(1).GetComponent <Cinemachine.CinemachineFreeLook>().Follow = DebugPlayerSelected.transform; } if (debugSpawnedPlayer.cameraReference != null) { debugSpawnedPlayer.cameraReference.transform.GetChild(1).GetComponent <Cinemachine.CinemachineFreeLook>().LookAt = debugSpawnedPlayer.transform; debugSpawnedPlayer.cameraReference.transform.GetChild(1).GetComponent <Cinemachine.CinemachineFreeLook>().Follow = debugSpawnedPlayer.transform; } PlayerController playerControllerOne = DebugPlayerSelected.GetComponent <PlayerController>(); playerControllerOne.DEBUG_hasBeenSpawnedFromTool = false; playerControllerOne.PlayerIndex = (PlayerIndex)0; Debug.Log("Possess a spawned player! "); } possessASpawnedPlayer = !possessASpawnedPlayer; } // Reload all powers if (Input.GetKeyDown(KeyCode.LeftAlt)) { if (DebugPlayerSelected.GetComponent <EvolutionPlatformist>()) { DebugPlayerSelected.GetComponent <EvolutionPlatformist>().Charges = 3; } Debug.Log("Powers reloaded for player " + DebugPlayerSelected.GetComponent <PlayerController>().PlayerIndex); } // Change debug player selected if (Input.GetKeyDown(KeyCode.N)) { SwitchPlayer(); Debug.Log("Switch to player index: " + DebugPlayerSelected.GetComponent <PlayerController>().PlayerIndex); } if (Input.GetKeyDown(KeyCode.T)) { if (teleportPlayerPositionsList == null || teleportPlayerPositionsList.Count == 0) { Debug.LogWarning("No transform specified for teleportation."); return; } DebugPlayerSelected.transform.position = teleportPlayerPositionsList[currentTeleportIndex].position; DebugPlayerSelected.transform.rotation = teleportPlayerPositionsList[currentTeleportIndex].rotation; currentTeleportIndex = (currentTeleportIndex + 1) % teleportPlayerPositionsList.Count; } if (Input.GetKeyDown(KeyCode.L)) { if (torchLights == null || torchLights.Count == 0) { Debug.LogWarning("No torchlight prefabs specified"); return; } if (!lightsEnabled) { foreach (GameObject torch in torchLights) { GameObject go = Instantiate(torch, DebugPlayerSelected.transform); go.transform.localPosition = torch.transform.localPosition; go.transform.localRotation = torch.transform.localRotation; } } else { Light[] lights = DebugPlayerSelected.GetComponentsInChildren <Light>(); for (int i = 0; i < lights.Length; i++) { Destroy(lights[i].gameObject); } } lightsEnabled = !lightsEnabled; } if (Input.GetKey(KeyCode.U) && Input.GetKeyDown(KeyCode.I)) { bool changeState = !DebugPanelReference.GetComponent <DebugPanel>().evolutions.gameObject.activeInHierarchy; DebugPanelReference.GetComponent <DebugPanel>().evolutions.gameObject.SetActive(changeState); DebugPanelReference.GetComponent <DebugPanel>().collectables.gameObject.SetActive(changeState); DebugPanelReference.GetComponent <DebugPanel>().playerInfo.gameObject.SetActive(changeState); } if (Input.GetKey(KeyCode.H)) { DebugPanelReference.GetComponent <DebugPanel>().helpPanel.gameObject.SetActive(true); } if (Input.GetKeyUp(KeyCode.H)) { hasReleasedHelpButton = true; } // Finish current mini game if (Input.GetKeyDown(KeyCode.F)) { if (SceneManager.GetActiveScene().name == MinigameManager.GetSceneNameFromMinigame(MiniGame.KickThemAll)) { GameManager.Instance.ScoreScreenReference.RankPlayersByPoints(); } } } } if (hasReleasedHelpButton) { currentTimerShowHelp += Time.deltaTime; if (currentTimerShowHelp > timerShowHelp) { DebugPanelReference.GetComponent <DebugPanel>().helpPanel.gameObject.SetActive(false); hasReleasedHelpButton = false; currentTimerShowHelp = 0.0f; } } }