public void EndTurn() { canShoot = true; //reset flag for next turn spaceBootsUsed = false; fireTriggered = false; //reset flag for next turn targetSelected = false; //reset flag for next turn canChangeWeapons = true; //reset flag for next turn AudioManager.instance.Stop("Carros_De_Fuego"); playerSettings.EndTurn(); //call master clean up function for all other scripts }
void Die() { AudioManager.instance.Play("Fatality"); //Added this just in case we want to add a deathEffect later if (deathEffect != null) { Instantiate(deathEffect, transform.position, Quaternion.identity); } if (ps.isMyTurn) { ps.EndTurn(); } //wait 6 seconds before destroyng this game object, to let the animations play //WARNING, this is a calculated time, if death animation changes, then this code needs to be generalized //but for now this will do the trick just fine Destroy(gameObject, 6f); }
void Update() { //Check if game is over deadTeamsCounter = 0; winningTeamID = -1; for (int i = 0; i < GLOBALS.numTeams; i++) { if (teamsHealth[i] <= 0) { deadTeamsCounter++; } else if (winningTeamID == -1 || teamsHealth[i] > teamsHealth[winningTeamID]) { winningTeamID = i; } } //Check if there is 1 or less players alive if (deadTeamsCounter >= GLOBALS.numTeams - 1) { if (gameState == GameState.GameOver || gameState == GameState.LoadingScene) { gameState = GameState.LoadingScene; //change state to prevent repetitive calls to gameOver } else { gameState = GameState.GameOver; } } //Check for Pause input if we are not in the pause state if (Input.GetKeyDown(KeyCode.P) && gameState != GameState.Pause) { prevGameState = gameState; //save prevGameState gameState = GameState.Pause; //Change to Pause state pauseMenuCanvas.gameObject.SetActive(true); //enable Pause Menu } //State Machine switch (gameState) { case GameState.TurnTransition: // Start timer for next turn. if (!coroutineStarted) { coroutineStarted = true; coroutineTurnClock = SetTurnClock(GLOBALS.timeBetweenTurns); //time between turns should be 1 to 5 sec StartCoroutine(coroutineTurnClock); if (suddenDeath) { StartCoroutine(ShowSuddenDeathCanvas(2f)); } } if (isTurnFinished) { coroutineStarted = false; //Reset coroutine check isTurnFinished = false; //Reset check before changing state gameState = GameState.TurnInProgress; //change State //Find out which team is next in turn. By looping thru the number of teams - 1 //If we don't get to the break statement, then game is over isOneTeamAlive = !FindNextTeam(); if (isOneTeamAlive) { //Check if all teams are dead by checking the last team currTeamTurn = (currTeamTurn + 1) % GLOBALS.numTeams; if (teamsHealth[currTeamTurn] <= 0) { //Everyone died //This is the flag for the game over screen currTeamTurn = -1; //else nextTeamTurn stays the same } //Trigger GameOver state gameState = GameState.GameOver; break; } //Depending on the next Teams turn, find out which soldier is next on their team for (int j = 0; j < GLOBALS.teamSize; j++) { //go to the next player alive in that turn currSoldierTurn[currTeamTurn] = (currSoldierTurn[currTeamTurn] + 1) % GLOBALS.teamSize; //check if Soldier is alive before choosing it for next turn if (soldiersHealth[currTeamTurn, currSoldierTurn[currTeamTurn]] > 0) { break; } } // Activate movement Script for player or AI to play and tell camera go = teams[currTeamTurn, currSoldierTurn[currTeamTurn]]; if (go != null) { go.GetComponent <PlayerSettings>().isMyTurn = true; //Tell camera which player is next in turn cam.soldier = teams[currTeamTurn, currSoldierTurn[currTeamTurn]]; cam.shouldFollowTarget = true; cam.SetZoom(10f); } else { Debug.LogError("Next Soldier in turn is dead, this state should never be reached"); } } break; case GameState.TurnInProgress: //Start timer to change state if (!coroutineStarted) { coroutineStarted = true; coroutineTurnClock = SetTurnClock(GLOBALS.timePerTurn); //timePerTurn should be 30 - 120 sec StartCoroutine(coroutineTurnClock); } //Check if turn suddenly stops because premature death or self injure and StopCoroutine() if (isTurnFinished) { coroutineStarted = false; //Reset coroutine check //Stop Coroutine just in case of premature death or self injure StopCoroutine(coroutineTurnClock); //If there is a projectile, follow it if (projectile != null) { cam.soldier = projectile; cam.shouldFollowTarget = true; //follow projectile gameState = GameState.WhatchingShot; } else { gameState = GameState.TurnTransition; } //Deactivate movement Script for player or AI to play go = teams[currTeamTurn, currSoldierTurn[currTeamTurn]]; if (go != null) { ps = go.GetComponent <PlayerSettings>(); if (ps != null) { ps.EndTurn(); //call clean up function for players end turn } //else //we do nothing since the player is gone anyway } isTurnFinished = false; //Reset check before changing state. THIS must be CALLED at the END of this state! } break; case GameState.WhatchingShot: //Once projectile is null, change state if (projectile == null) { gameState = GameState.WhatchingDamage; } else if (cam.soldier == null) { cam.soldier = projectile; //this is in case the initial projectile releases more projectiles } break; case GameState.WhatchingDamage: //Start timer to change state if (!coroutineStarted) { coroutineStarted = true; coroutineTurnClock = SetTurnClock(timeWatchingDamage); //timePerTurn should be 30 - 120 sec StartCoroutine(coroutineTurnClock); coroutineEnded = false; } if (coroutineEnded) { coroutineStarted = false; //Reset coroutine check isTurnFinished = false; //Reset check before changing state gameState = GameState.TurnTransition; } break; case GameState.Pause: //Adjust timer to not being affected by the pause and save the current game state if (!stateSaved) { stateSaved = true; //Update flag Time.timeScale = 0.0f; //Stop time AudioListener.pause = true; //pause all sound affected by time turnClockWhenPause = turnClock; //Save turnClock StopCoroutine(coroutineTurnClock); //And stop the turn Coroutine gameClockWhenPause = gameClock; //Save gameClock StopCoroutine(coroutineGameClock); //And stop the game Coroutine isTurnFinishedWhenPaused = isTurnFinished; //Save turn state currTeamTurnWhenPause = currTeamTurn; //Save current Team Turn //Check for out of bounce errors if (currTeamTurn < 0 || currSoldierTurn[currTeamTurn] < 0) { return; } //Force player to change to the gauntlet weapon go = teams[currTeamTurn, currSoldierTurn[currTeamTurn]]; if (go != null && !GLOBALS.isTeamAI[currTeamTurn]) { WeaponController wc = go.GetComponent <WeaponController>(); if (wc != null) { wc.ChangeWeapon((int)WeaponCodes.Gauntlet); // Weapon Code for the gauntlet is 0 } } } else if (Input.GetKeyDown(KeyCode.P) || !pauseMenuCanvas.gameObject.activeInHierarchy) { stateSaved = false; //reset flag AudioListener.pause = false; //un-pause all sound affected by time isTurnFinished = isTurnFinishedWhenPaused; //Recover this variable state //Check if the coroutine was in progress or not, this only happens in exactly 1 frame if (!isTurnFinishedWhenPaused) { //Resume gameClock Timer coroutineGameClock = SetGameClock(gameClockWhenPause); StartCoroutine(coroutineGameClock); //Resume turnClock Timer coroutineTurnClock = SetTurnClock(turnClockWhenPause); //time between turns should be 1 to 5 sec StartCoroutine(coroutineTurnClock); } Time.timeScale = 1.0f; //Unfreeze time gameState = prevGameState; //Resume the game pauseMenuCanvas.gameObject.SetActive(false); //disable Pause Menu } break; case GameState.LoadingScene: //***************************TODO************************** /* * */ break; case GameState.GameOver: Debug.Log("Game Over"); //Get reference to GameOverScreen component GameOverScreen gos = gameOverCanvas.GetComponent <GameOverScreen>(); //pass the teamID gos.winningTeamID = winningTeamID; if (winningTeamID != -1) { //Pass the name of the winning team if there is one if (GLOBALS.teams[winningTeamID] != null) { gos.winningTeamName = GLOBALS.teams[winningTeamID].teamName; } //pass winning team color gos.winTeamColor = GLOBALS.teamColors[winningTeamID]; } //Enable the game over canvas to trigger the end of the game gameOverCanvas.gameObject.SetActive(true); break; default: Debug.LogError("Invalid State reached... but HOW??!!"); break; } }