public void LoadGameBoyTurns() { // get our player character and our enemy character currentPlayer = GameObject.FindGameObjectWithTag("GameBoyUnit"); currentEnemy = GameObject.FindGameObjectWithTag("Enemy"); GameBoyUnit ourPlayerUnit = currentPlayer.GetComponent <GameBoyUnit> (); GameBoyUnit ourEnemyUnit = currentEnemy.GetComponent <GameBoyUnit> (); ourPlayerUnit.Flip(); ourPlayerUnit.targetUnit = ourEnemyUnit; ourEnemyUnit.targetUnit = ourPlayerUnit; ourPlayerUnit.healthLeft = GameObject.Find("LeftHealthText").GetComponent <Text>(); ourEnemyUnit.healthLeft = GameObject.Find("RightHealthText").GetComponent <Text>(); ourPlayerUnit.healthBarTick = healthBarTick; ourEnemyUnit.healthBarTick = healthBarTick; ourPlayerUnit.CreateHealth(); ourEnemyUnit.CreateHealth(); ourEnemyUnit.healthBarLostTick = healthBarLostTick; ourPlayerUnit.healthBarLostTick = healthBarLostTick; // characterconversable[] allCombatants = new List <GameObject> (); allCombatants.Add(currentPlayer); allCombatants.Add(currentEnemy); turnOrder.Add(ourPlayerUnit); turnOrder.Add(ourEnemyUnit); // we need to be able to loop over and instantiate prefabs. GameObject.Find("HeroText").GetComponent <Text>().text = ourPlayerUnit.playerName; GameObject.Find("VillainText").GetComponent <Text>().text = ourEnemyUnit.playerName; }
/// <summary> /// Update this instance. Controls our state machine. Uses ToolBox /// </summary> // Update is called once per frame void Update() { // if we are locked, can't go forward if (Toolbox.Instance.isLocked) { return; } // lock our toolbox Toolbox.Instance.isLocked = true; Toolbox toolboxInstance = Toolbox.Instance; // switch over our battle state switch (currentState) { // load our scene and move our battle forward case BATTLE_STATES.START: playAgainChoiceMade = false; currentTurn = 0; // if we don't have turns loaded, load the turns if (!turnsLoaded) { sceneInit.LoadGameBoyTurns(); turnsLoaded = true; Toolbox.Instance.isLocked = false; } // if we have turns loaded, load the battle scene and move into deciding // whose turn it is else { sceneInit.LoadBattleSceneItems(); currentState = BATTLE_STATES.DECIDE_TURN; battleTurnOrder = sceneInit.turnOrder; Toolbox.Instance.isLocked = false; } break; // decide whose turn it is case BATTLE_STATES.DECIDE_TURN: Debug.Log("We are deciding turn " + currentTurn); currentState = BATTLE_STATES.DECIDE_ATTACK; // pick the turn person currentPlayerTurn = battleTurnOrder [currentTurn]; // update our current turn to the next player in the queue // and cycle if we are at the end. currentTurn++; if (currentTurn >= battleTurnOrder.Count) { currentTurn = 0; } turnFinished = false; waitingForTurn = false; Toolbox.Instance.isLocked = false; break; // decide which attack we are using on whoever's turn it is case BATTLE_STATES.DECIDE_ATTACK: // skip this turn if our player has no health if (currentPlayerTurn.isPlayerCharacter && currentPlayerTurn.GetComponent <GameBoyUnit> ().currentHealth <= 0) { waitingForTurn = true; currentState = BATTLE_STATES.LOSE; Toolbox.Instance.isLocked = false; } // if the current player is an enemy and is dead, victory! (for now - later on we'll just skip this turn // and add in a "CHECK" phase else if (!currentPlayerTurn.isPlayerCharacter && currentPlayerTurn.GetComponent <GameBoyUnit> ().currentHealth <= 0) { waitingForTurn = true; currentState = BATTLE_STATES.WIN; Toolbox.Instance.isLocked = false; } // get our battle manager if we are a good guy. // Otherwise, perform an attack if we are a bad guy if (!waitingForTurn) { waitingForTurn = true; turnFinished = false; if (currentPlayerTurn.isPlayerCharacter) { // get their battle mode and start gaming //currentPlayerTurn.gameObject.GetComponent<BattleMenu> ().isMyTurn = true; StartCoroutine(currentPlayerTurn.Attack()); } // otherwise, if it is not my turn, enemy attack! else { StartCoroutine(currentPlayerTurn.Attack()); } } // if the turn is finished, perform our commands if (turnFinished) { currentState = BATTLE_STATES.PERFORM_COMMANDS; Toolbox.Instance.isLocked = false; } break; // perform commands of the attack case BATTLE_STATES.PERFORM_COMMANDS: // let's do a little enum in here StartCoroutine(displayAttack()); break; // check the conditions of the battle - has someone won? is any unit // to be destroyed? case BATTLE_STATES.CHECK_CONDITIONS: bool playerStillAlive = true; bool enemyStillAlive = true; // if our player is dead, we have lost if (!playerStillAlive) { currentState = BATTLE_STATES.LOSE; Toolbox.Instance.isLocked = false; break; } // if our enemy is dead, we have won if (!enemyStillAlive) { currentState = BATTLE_STATES.WIN; Toolbox.Instance.isLocked = false; break; } // first check if the player characters are all dead // then check if the enemy characters are all dead Debug.Log("we are here in check condition"); // for each of the enemies in play - are we all dead? // for each of the players in play, are we all dead? currentState = BATTLE_STATES.DECIDE_TURN; Toolbox.Instance.isLocked = false; break; // if the player side has won, hooray! victory conditions and experience case BATTLE_STATES.WIN: // let's add that experience to our tally // enemy defeated GameObject enemyDefeated = GameObject.FindGameObjectWithTag("Enemy"); gainedExperience += enemyDefeated.GetComponent <GameBoyUnit> ().experience; // if we have received a choice - we can choose to play again if (playAgainChoiceMade) { // check if we are gambling or continuing on. if (gambling) { currentState = BATTLE_STATES.START; Toolbox.Instance.isLocked = false; } // we have decided we are done gambling on experience else if (!gambling) { currentState = BATTLE_STATES.END; Toolbox.Instance.isLocked = false; } } // display character selection panel else { displayCharacterSelectionPanel(); } break; // if the good side has lost, sad day. Penalties and teleport case BATTLE_STATES.LOSE: currentState = BATTLE_STATES.END; Toolbox.Instance.isLocked = false; break; case BATTLE_STATES.CHARACTER_SELECTION: break; case BATTLE_STATES.END: // load previous scene toolboxInstance.positionInLastScene = toolboxInstance.battlePosition; toolboxInstance.sceneAlreadyLoaded = false; GameObject.FindGameObjectWithTag("PlayerCharacter").GetComponent <PlayerUnit> ().playerExperience += gainedExperience; // spawn at least location? // what if the grue is still there? // we'll get this in a moment. SceneManager.LoadScene("OpeningScene"); break; // if we hit a non-existent case default: break; } }