Ejemplo n.º 1
0
 // Use this for initialization
 void Start()
 {
     player              = GameObject.Find("luna");
     anim                = GetComponent <Animator>();
     turn                = GameObject.Find("GameControl").GetComponent <TurnSwitch>();
     takedamage          = GameObject.Find("GameControl").GetComponent <TakeDamage>();
     characterController = player.GetComponent <CharacterController>();
     playerModel         = PlayerModel.GetInstance();
     monsterInfo         = gameObject.GetComponent <MonsterInfo>();
     itemModel           = ItemModel.GetInstance();
     bag             = GameObject.Find("Bag").GetComponent <Bag>();
     ico             = GameObject.Find("GetItem").transform.FindChild("ItemInfo").FindChild("frame").FindChild("ico").GetComponent <Image>();
     name            = GameObject.Find("GetItem").transform.FindChild("ItemInfo").FindChild("nameInfo").FindChild("name").GetComponent <Text>();
     explain         = GameObject.Find("GetItem").transform.FindChild("ItemInfo").FindChild("explain").FindChild("explainText").GetComponent <Text>();
     bgmBattle       = GameObject.Find("BGM_battleNormal").GetComponent <AudioSource>();
     BGM_cench       = GameObject.Find("BGM_cench").GetComponent <AudioSource>();
     getSound        = GameObject.Find("GetSound").GetComponent <AudioSource>();
     lightPunchAudio = GameObject.Find("LightPunchAudio").GetComponent <AudioSource>();
 }
Ejemplo n.º 2
0
 // Use this for initialization
 void Start()
 {
     playerPos   = PlayerPos.GetInstance();
     playerModel = PlayerModel.GetInstance();
     if (playerPos.index == 2)                                     //根据角色位置id来设置角色的位置
     {
         transform.position             = playerPos1.position;     //设置角色位置
         transform.forward              = -playerPos1.right;       //设置角色的面向
         Camera.main.transform.position = maincameraPos1.position; //设置主相机的位置
         mapCamera.transform.position   = mapcameraPos1.position;  //设置小地图相机的位置
         playerPos.index = 0;                                      //重置角色位置id
     }
     if (playerPos.index == 3)
     {
         transform.position             = playerPos2.position;
         transform.forward              = -playerPos2.forward;
         Camera.main.transform.position = maincameraPos2.position;
         mapCamera.transform.position   = mapcameraPos2.position;
         playerPos.index = 0;
     }
     r               = GetComponent <Rigidbody>();
     anim            = GetComponent <Animator>();
     mySequence      = DOTween.Sequence();
     turn            = GameObject.Find("GameControl").GetComponent <TurnSwitch>();
     id              = playerModel.Playerinfo[0].id;
     name            = playerModel.Playerinfo[0].name;
     hp              = playerModel.Playerinfo[0].hp;
     maxHp           = playerModel.Playerinfo[0].maxHp;
     sp              = playerModel.Playerinfo[0].sp;
     maxSp           = playerModel.Playerinfo[0].maxSp;
     str             = playerModel.Playerinfo[0].str;
     magic           = playerModel.Playerinfo[0].magic;
     def             = playerModel.Playerinfo[0].def;
     agile           = playerModel.Playerinfo[0].agile;
     takedamage      = GameObject.Find("GameControl").GetComponent <TakeDamage>();
     stepAudio       = GameObject.Find("FootStepAudio").GetComponent <AudioSource>();
     lightPunchAudio = GameObject.Find("LightPunchAudio").GetComponent <AudioSource>();
     BGM_cench       = GameObject.Find("BGM_cench").GetComponent <AudioSource>();
     bgmBattle       = GameObject.Find("BGM_battleNormal").GetComponent <AudioSource>();
 }
Ejemplo n.º 3
0
        /* The Update() function handles different scenarios when different flags are true. */
        public override void Update(GameTime gameTime)
        {
            /* First, the labels on the screen are updated. This means changes to health or level are visible to the user. */
            UpdateLabels();

            /* If the user has just chosen the Pokemon they would like to switch in, the flag is set to false.
             * A new TurnSwitch is then added to the turn list, using the current player and Pokemon that was selected.
             * Now that the player turn has been created, DoRound() is called to do everything else necessary for the round to start. */
            if (switchCompleted)
            {
                switchCompleted = false;
                battle.Turns.Add(new TurnSwitch(battle.CurrentPlayer, battle.PlayerTeam[GameRef.SwitchScreen.SelectedIndex], battle, (byte)GameRef.SwitchScreen.SelectedIndex));
                DoRound();
            }

            /* If a player Pokemon has just fainted, and the user has just chosen a new Pokemon to send in, the flag is set to false.
             * Next, all the turns where the fainted Pokemon is the user are removed from the turn list.
             * This means that a fainted Pokemon should not be able to execute a turn.
             * The turn list is iterated through backwards, as changes are being made to the list while iterating through it.
             * A new TurnSwitch is created using the current player and the newly selected Pokemon.
             * The new switch turn is immediately executed, as it doesn't count as a part of the round. */
            if (faintCompleted)
            {
                faintCompleted = false;
                for (int i = battle.Turns.Count - 1; i >= 0; i--)
                {
                    if (battle.Turns[i].User == battle.CurrentPlayer)
                    {
                        battle.Turns.Remove(battle.Turns[i]);
                    }
                }
                TurnSwitch faintSwitch = new TurnSwitch(battle.CurrentPlayer, battle.PlayerTeam[GameRef.SwitchScreen.SelectedIndex], battle, (byte)GameRef.SwitchScreen.SelectedIndex);
                faintSwitch.Execute();
            }

            /* If the battle's OpenSwitchMenu flag is true, then the SwitchScreen is reset so it has the updated values for the Pokemon on its list.
             * The SwitchScreen is pushed onto the top of the GameStateManager stack, so that it is displayed on the next frame.
             * This will allow the player to choose the next Pokemon they want to send out.
             * The faintCompleted flag is set to true so that once the SwitchScreen pops, the BattleScreen will send the chosen Pokemon out into battle.
             * Finally, the battle's OpenSwitchMenu flag is set to false as it's done its job. */
            if (battle.OpenSwitchMenu && log.FinishedEmptying)
            {
                GameRef.SwitchScreen.Reset();
                Change(ChangeType.Push, GameRef.SwitchScreen);
                faintCompleted        = true;
                battle.OpenSwitchMenu = false;
            }

            /* If the battle's EmptyLog flag is true, then the BattleLog control's Empty() function is called,
             * which starts the process of displaying the text buffered in the log onto the screen.
             * The flag is then set to false so that this block doesn't execute again next frame. */
            if (battle.EmptyLog)
            {
                log.Empty(battle.LogList);
                battle.EmptyLog = false;
            }

            /* If the battle's BattleFinished flag is true, then the player's PokemonInBattle from this screen need to be transferred back to the WorldScreen.
             * This is necessary so that changes to health and level will carry over after the battle, instead of being reset to how they were before.
             * The waitingToPop flag is set to true, so that the BattleScreen pops on the next game loop iteration.
             * The WorldScreen's Player's Team is then reset and filled with the BattleScreen's Player's Team, using InitTeam() and AddToTeam(). */
            if (battle.BattleFinished)
            {
                waitingToPop = true;
                WorldScreen.Player.InitTeam(battle.PlayerTeam[0]);
                for (int i = 1; i < battle.PlayerTeam.Count; i++)
                {
                    WorldScreen.Player.AddToTeam(battle.PlayerTeam[i]);
                }
            }

            /* This is where the flag system gets a bit complicated.
             * If the executing and nextMove flags are true, then a turn has just finished.
             * The engine checks if there are any more turns left to execute, by checking the list's Count.
             * If there are moves left, the ExecuteNextTurn() function kickstarts the next turn in the list.
             * The turn that has just been executed is then removed from the list since it isn't needed any more.
             * In this way, the list will gradually empty as the turns are executed.
             * If there are no turns left in the list, the executing flag is set to false, since there is nothing to execute.
             * In both cases, the nextMove flag is set to false, as the next move no longer needs to be checked. */
            if (executing && nextMove)
            {
                if (battle.Turns.Count > 0)
                {
                    battle.ExecuteNextTurn();
                    battle.Turns.Remove(battle.Turns[0]);
                }
                else
                {
                    executing = false;
                }
                nextMove = false;
            }

            /* If the BattleLog's FinishedEmptying flag is true, it's time to check if another move can be executed.
             * This means that the nextMove flag will be set to true if the round is still executing.
             * Either way, ResetBattleScreen() is called to update the sprite images in case a switch has happened,
             * and to reset the menu so that it is ready to be used to get the user's next turn.
             * The log's FinishedEmptying flag is set back to false. The log's list is also cleared.
             * Finally, if the waitingToPop flag is true, it is set back to false and the BattleScreen is popped off the stack. */
            if (log.FinishedEmptying)
            {
                if (executing)
                {
                    nextMove = true;
                }
                ResetBattleScreen();
                log.FinishedEmptying = false;
                battle.LogList.Clear();
                if (waitingToPop)
                {
                    waitingToPop = false;
                    Change(ChangeType.Pop, null);
                }
            }

            /* The ControlManager and battle are also updated during the BattleScreen updating. */
            ControlManager.Update(gameTime, PlayerIndex.One);
            battle.Update(gameTime);

            /* If the user presses the backspace key, and the BattleLog isn't in the middle of displaying anything, the menu will be reset.
             * This essentially means the user can cancel their choice if necessary.
             * Finally, the parent function is called. */
            if (InputHandler.KeyReleased(Keys.Back) && !log.Emptying)
            {
                ResetBattleScreen();
            }
            base.Update(gameTime);
        }