コード例 #1
0
ファイル: FoxClass.cs プロジェクト: semurr/ChickenRanch
        //, ChickenClass cl, RoosterClass rl)
        public void update(GameTime gameTime, ref ChickenClass[] chickenlst, ref RoosterClass[] roosterlst,
            ref int numRooster, ref int numChic,
            Vector3 avoid, int rosQueue, int chicqueue, EconomicsClass player)
        {
            //first time
            if (start == true)
            {
                if (position.Z < 6000)
                {
                    home = false;
                    start = false;
                }
            }

            //check bounding area's
            if(barn.inside(position))
            {
                //if fox go inside barn push out
                position = barn.pushOut(position,riseRun.X, riseRun.Z, speed);

            }
            else if (!fence.inside(position) && home == false)
            {
                float disttemp = Vector3.Distance(position, foxPathValues[0]);
                foxNextNode = 0;
                //find closest node after chase
                for (int i = 1; i < foxPathValues.Count; i++)
                {
                    if (disttemp > Vector3.Distance(position, foxPathValues[i]))
                    {
                        disttemp = Vector3.Distance(position, foxPathValues[i]);
                        foxNextNode = i;
                    }
                }
                riseRun.X = foxPathValues[foxNextNode].X - position.X;
                riseRun.Z = foxPathValues[foxNextNode].Z - position.Z;
                riseRun.Normalize();
                riseRun.X = riseRun.X * speed;
                riseRun.Z = riseRun.Z * speed;
                wandering = true;

                Vector2 position1 = new Vector2(position.X, position.Z);
                Vector2 position2 = new Vector2(foxPathValues[foxNextNode].X, foxPathValues[foxNextNode].Z);

                rotation = (float)getRotation(position1, position2);

            }
            else
            {
                //checks if fox is close to character, if so run away from character
                if( Vector3.Distance(avoid, position) < avoidD || avoiding == true)
                {
                    home = true;
                    start = true;

                    if (temp1 == true)
                    {
                        avoidChar(foxPathValues[16]);
                    }
                    else
                    {
                        avoidChar(foxPathValues[15]);
                    }
                }
                else if (wait == true)  //wait certain amount of time then start chasing again
                {
                    timer += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (timer > waitTime)
                    {
                        GameUI.gameInterface.instance.foxWarning.visible = true;
                        if (GameUI.gameInterface.instance.foxWarningCounter == 5)
                        {
                            GameUI.gameInterface.instance.foxWarning.visible = false;
                            GameUI.gameInterface.instance.foxWarningCounter = 0;
                        }
                        timer2 += (float)gameTime.ElapsedGameTime.TotalSeconds;
                        position.Z -= speed;
                        rotation = MathHelper.Pi;

                        if (timer2 > waitTime2)
                        {
                            wait = false;
                            timer = 0;
                            timer2 = 0;
                            FoxNextNode();
                        }
                    }

                }
                else
                {
                    //find the closest object and chase

                    chickenList = chickenlst;
                    roosterList = roosterlst;
                    chaseTime += (float)gameTime.ElapsedGameTime.TotalSeconds;

                    if (chaseTime > 3)
                    {
                        chaseTime = 0;
                    }

                    if (chaseTime == 0)
                    {
                        chaseTime += (float)gameTime.ElapsedGameTime.TotalSeconds;

                        if (chickenDistance >= 0)
                        {
                            chickenDistance = 0;
                            chickenClose = -1;
                        }

                        if (roosterDistance >= 0)
                        {
                            roosterDistance = 0;
                            roosterClose = -1;
                        }

                        //find closest chicken
                        for (int i = 0; i < numChic - chicqueue; i++)
                        {
                            //check if they are on ground
                            if (chickenList[i].ground == 3)
                            {
                                if (chickenDistance > Vector3.Distance(chickenList[i].position, position) || chickenClose == -1)
                                {
                                    chickenDistance = (int)Vector3.Distance(chickenList[i].position, position);
                                    chickenClose = i;
                                }
                            }
                        }

                        //find the closet rooster
                        for (int i = 0; i < numRooster; i++)
                        {
                            //check if they are on ground
                            if (roosterList[i] != null)
                            {
                                if (roosterDistance > Vector3.Distance(roosterList[i].position, position) || roosterClose == -1)
                                {
                                    roosterDistance = (int)Vector3.Distance(roosterList[i].position, position);
                                    roosterClose = i;
                                }
                            }
                        }
                    }

                    //if nothing to chase find next node and wander
                    if(chickenDistance == 0 && roosterDistance == 0)
                    {
                        chasing = 0;
                        if (wandering == true)
                        {
                            wander();
                        }
                        else
                        {
                            float disttemp = Vector3.Distance(position, foxPathValues[0]);
                            foxNextNode = 0;
                            //find closest node after chase
                            for (int i = 1; i < foxPathValues.Count; i++)
                            {
                                if (disttemp > Vector3.Distance(position, foxPathValues[i]))
                                {
                                    disttemp = Vector3.Distance(position, foxPathValues[i]);
                                    foxNextNode = i;
                                }
                            }
                            riseRun.X = foxPathValues[foxNextNode].X - position.X;
                            riseRun.Z = foxPathValues[foxNextNode].Z - position.Z;
                            riseRun.Normalize();
                            riseRun.X = riseRun.X * speed;
                            riseRun.Z = riseRun.Z * speed;
                            wandering = true;

                            Vector2 position1 = new Vector2(position.X, position.Z);
                            Vector2 position2 = new Vector2(foxPathValues[foxNextNode].X, foxPathValues[foxNextNode].Z);

                            rotation = (float)getRotation(position1, position2);
                        }
                    }

                    //if no rooster and chicken on the ground chase chicken
                    if (roosterDistance == 0)
                    {
                        if(chickenDistance != 0)
                        {
                            //chase chicken
                            chasing = 1;
                            chase(chickenList[chickenClose].position, ref numRooster, ref roosterlst, ref numChic,
                                ref chickenList, player);
                            wandering = false;
                        }
                    }

                    //if no chicken and a rooster on the ground
                    if (chickenDistance == 0)
                    {
                        if (roosterDistance != 0)
                        {
                            //chase rooster
                            chasing = 2;
                            chase(roosterList[roosterClose].position, ref numRooster, ref roosterlst, ref numChic,
                                ref chickenList, player);
                            wandering = false;
                        }
                    }

                    //if rooster and chicken on ground chase closest one
                    if (chickenDistance != 0 && roosterDistance != 0)
                    {
                        if (roosterDistance > chickenDistance)
                        {
                            chasing = 1;
                            wandering = false;
                            chase(chickenList[chickenClose].position, ref numRooster, ref roosterlst, ref numChic,
                                ref chickenList, player);
                        }
                        else
                        {
                            chasing = 2;
                            wandering = false;
                            chase(roosterList[roosterClose].position, ref numRooster, ref roosterlst, ref numChic,
                                ref chickenList, player);
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: FoxClass.cs プロジェクト: semurr/ChickenRanch
        //chase rooster or chicken
        public void chase(Vector3 chase, ref int nRooster, ref RoosterClass[] roosterList, ref int nChicken,
            ref ChickenClass[] chickenList, EconomicsClass player)
        {
            //turn alarm on if alarm has not already been
            if (GameUI.gameInterface.instance.wasWarned != true)
            {
                GameUI.gameInterface.instance.foxWarning.visible = true;
            }
            //turn alarm off after 10 seconds
            if (GameUI.gameInterface.instance.foxWarningCounter == 20)
            {
                GameUI.gameInterface.instance.foxWarning.visible = false;
                GameUI.gameInterface.instance.foxWarningCounter = 0;
                GameUI.gameInterface.instance.wasWarned = true;
            }

            //find the vector object needs to moe to collide
            riseRun2.X = chase.X - position.X;
            riseRun2.Z = chase.Z - position.Z;
            riseRun2.Normalize();
            riseRun2.X = riseRun2.X * speed;
            riseRun2.Z = riseRun2.Z * speed;

            Vector2 position1 = new Vector2(position.X, position.Z);
            Vector2 position2 = new Vector2(chase.X, chase.Z);

            rotation = (float)getRotation(position1, position2);

            //attack if object gets to close
            if (Math.Abs(position.X - chase.X) < attackLength && Math.Abs(position.Z - chase.Z) < attackLength)
            {
                if (chasing == 1)
                {
                    //attack chicken
                    if (Chicken.AudioManager.instance.sFXOn == true && GameUI.gameWorld.instance.isPaused != true)
                    {
                        Chicken.AudioManager.instance.foxAttackSound.Play();
                    }
                    chickenList[chickenClose] = null;
                    decrementChicken(ref chickenList, chickenClose, nChicken);
                    chickenDistance = 0;
                    nChicken--;
                    player.chickenEaten++;

                }
                else
                {
                    //attack rooster
                    if (Chicken.AudioManager.instance.sFXOn == true && GameUI.gameWorld.instance.isPaused != true)
                    {
                        Chicken.AudioManager.instance.foxAttackSound.Play();
                    }
                    roosterList[roosterClose] = null;
                    decrementRooster(ref roosterList, roosterClose, nRooster);
                    roosterDistance = 0;
                    nRooster--;
                    player.roosterEaten++;
                }
            }

            //chase toward entity position updates
            if (Math.Abs(position.X - chase.X) < Math.Abs(riseRun2.X) + 1)
            {
            }
            else if (riseRun2.X > 0)
            {
                positionOld.X = position.X;
                position.X = riseRun2.X + position.X;
            }
            else
            {
                positionOld.X = position.X;
                position.X += riseRun2.X;
            }

            if (Math.Abs(position.Z - chase.Z) < Math.Abs(riseRun2.Z) + 1)
            {
            }
            else if (riseRun2.Z > 0)
            {
                positionOld.Z = position.Z;
                position.Z += riseRun2.Z;
            }
            else
            {
                positionOld.Z = position.Z;
                position.Z += riseRun2.Z;
            }
        }
コード例 #3
0
ファイル: Game1.cs プロジェクト: semurr/ChickenRanch
        private static void Save(StorageDevice storageDevice,int numChics, int chicQueue, CharacterClass player,
            int numRooster, int roosterQueue, ChickenClass[] chickens, RoosterClass[] roosters, EconomicsClass eco, 
            int eggCount, int numEgg, EggClass[] egg, int days, float dayTime, bool endOfDay, int numBoots,
            RubberBootClass[] boots,
            float bootTime, bool bootPresent, bool bootEquipped, FoxClass fox)
        {
            // Pass the information into the data objects
            DataToSave dataToSave = new DataToSave();

            //save character
            dataToSave.cPosition = player.position;
            dataToSave.cRotation = player.rotation;
            dataToSave.hitpoints = player.hitPoints;

            //save Chickens
            dataToSave.numChickens = numChics;
            dataToSave.ChicQueue = chicQueue;
            //save chicken1
            if (chickens[0].time != null)
            {
                dataToSave.chic1time = chickens[0].time;
                dataToSave.chic1state = chickens[0].state;
                dataToSave.chic1ground = chickens[0].ground;
                dataToSave.chic1InitNode = chickens[0].ChickenInitNode;
                dataToSave.chic1PreviousNode = chickens[0].ChickenPreviousNode;
                dataToSave.chic1CurrentNode = chickens[0].ChickenCurrentNode;
                dataToSave.chic1NextNode = (int)chickens[0].chickenNextNode;
                dataToSave.chic1Position = chickens[0].position;
                dataToSave.chic1Rotation = chickens[0].rotation;
                dataToSave.chic1RiseRun = chickens[0].riseRun;
                dataToSave.chic1EggLaid = chickens[0].eggLaid;
            }
            else
            {
                dataToSave.chic1time = -1;
            }
            //save chicken2
            if (chickens[1] != null)
            {
                dataToSave.chic2time = chickens[1].time;
                dataToSave.chic2state = chickens[1].state;
                dataToSave.chic2ground = chickens[1].ground;
                dataToSave.chic2InitNode = chickens[1].ChickenInitNode;
                dataToSave.chic2PreviousNode = chickens[1].ChickenPreviousNode;
                dataToSave.chic2CurrentNode = chickens[1].ChickenCurrentNode;
                dataToSave.chic2NextNode = (int)chickens[1].chickenNextNode;
                dataToSave.chic2Position = chickens[1].position;
                dataToSave.chic2Rotation = chickens[1].rotation;
                dataToSave.chic2RiseRun = chickens[1].riseRun;
                dataToSave.chic2EggLaid = chickens[1].eggLaid;
            }
            else
            {
                dataToSave.chic2time = -1;
            }
            //save chicken3
            if (chickens[2] != null)
            {
                dataToSave.chic3time = chickens[2].time;
                dataToSave.chic3state = chickens[2].state;
                dataToSave.chic3ground = chickens[2].ground;
                dataToSave.chic3InitNode = chickens[2].ChickenInitNode;
                dataToSave.chic3PreviousNode = chickens[2].ChickenPreviousNode;
                dataToSave.chic3CurrentNode = chickens[2].ChickenCurrentNode;
                dataToSave.chic3NextNode = (int)chickens[2].chickenNextNode;
                dataToSave.chic3Position = chickens[2].position;
                dataToSave.chic3Rotation = chickens[2].rotation;
                dataToSave.chic3RiseRun = chickens[2].riseRun;
                dataToSave.chic3EggLaid = chickens[2].eggLaid;
            }
            else
            {
                dataToSave.chic3time = -1;
            }
            //save chicken4
            if (chickens[3] != null)
            {
                dataToSave.chic4time = chickens[3].time;
                dataToSave.chic4state = chickens[3].state;
                dataToSave.chic4ground = chickens[3].ground;
                dataToSave.chic4InitNode = chickens[3].ChickenInitNode;
                dataToSave.chic4PreviousNode = chickens[3].ChickenPreviousNode;
                dataToSave.chic4CurrentNode = chickens[3].ChickenCurrentNode;
                dataToSave.chic4NextNode = (int)chickens[3].chickenNextNode;
                dataToSave.chic4Position = chickens[3].position;
                dataToSave.chic4Rotation = chickens[3].rotation;
                dataToSave.chic4RiseRun = chickens[3].riseRun;
                dataToSave.chic4EggLaid = chickens[3].eggLaid;
            }
            else
            {
                dataToSave.chic4time = -1;
            }
            //save chicken5
            if (chickens[4] != null)
            {
                dataToSave.chic5time = chickens[4].time;
                dataToSave.chic5state = chickens[4].state;
                dataToSave.chic5ground = chickens[4].ground;
                dataToSave.chic5InitNode = chickens[4].ChickenInitNode;
                dataToSave.chic5PreviousNode = chickens[4].ChickenPreviousNode;
                dataToSave.chic5CurrentNode = chickens[4].ChickenCurrentNode;
                dataToSave.chic5NextNode = (int)chickens[4].chickenNextNode;
                dataToSave.chic5Position = chickens[4].position;
                dataToSave.chic5Rotation = chickens[4].rotation;
                dataToSave.chic5RiseRun = chickens[4].riseRun;
                dataToSave.chic5EggLaid = chickens[4].eggLaid;
            }
            else
            {
                dataToSave.chic5time = -1;
            }
            //save chicken6
            if (chickens[5] != null)
            {
                dataToSave.chic6time = chickens[5].time;
                dataToSave.chic6state = chickens[5].state;
                dataToSave.chic6ground = chickens[5].ground;
                dataToSave.chic6InitNode = chickens[5].ChickenInitNode;
                dataToSave.chic6PreviousNode = chickens[5].ChickenPreviousNode;
                dataToSave.chic6CurrentNode = chickens[5].ChickenCurrentNode;
                dataToSave.chic6NextNode = (int)chickens[5].chickenNextNode;
                dataToSave.chic6Position = chickens[5].position;
                dataToSave.chic6Rotation = chickens[5].rotation;
                dataToSave.chic6RiseRun = chickens[5].riseRun;
                dataToSave.chic6EggLaid = chickens[5].eggLaid;
            }
            else
            {
                dataToSave.chic6time = -1;
            }
            //save chicken7
            if (chickens[6] != null)
            {
                dataToSave.chic7time = chickens[6].time;
                dataToSave.chic7state = chickens[6].state;
                dataToSave.chic7ground = chickens[6].ground;
                dataToSave.chic7InitNode = chickens[6].ChickenInitNode;
                dataToSave.chic7PreviousNode = chickens[6].ChickenPreviousNode;
                dataToSave.chic7CurrentNode = chickens[6].ChickenCurrentNode;
                dataToSave.chic7NextNode = (int)chickens[6].chickenNextNode;
                dataToSave.chic7Position = chickens[6].position;
                dataToSave.chic7Rotation = chickens[6].rotation;
                dataToSave.chic7RiseRun = chickens[6].riseRun;
                dataToSave.chic7EggLaid = chickens[6].eggLaid;
            }
            else
            {
                dataToSave.chic7time = -1;
            }
            //save chicken8
            if (chickens[7] != null)
            {
                dataToSave.chic8time = chickens[7].time;
                dataToSave.chic8state = chickens[7].state;
                dataToSave.chic8ground = chickens[7].ground;
                dataToSave.chic8InitNode = chickens[7].ChickenInitNode;
                dataToSave.chic8PreviousNode = chickens[7].ChickenPreviousNode;
                dataToSave.chic8CurrentNode = chickens[7].ChickenCurrentNode;
                dataToSave.chic8NextNode = (int)chickens[7].chickenNextNode;
                dataToSave.chic8Position = chickens[7].position;
                dataToSave.chic8Rotation = chickens[7].rotation;
                dataToSave.chic8RiseRun = chickens[7].riseRun;
                dataToSave.chic8EggLaid = chickens[7].eggLaid;
            }
            else
            {
                dataToSave.chic8time = -1;
            }
            //save chicken9
            if (chickens[8] != null)
            {
                dataToSave.chic9time = chickens[8].time;
                dataToSave.chic9state = chickens[8].state;
                dataToSave.chic9ground = chickens[8].ground;
                dataToSave.chic9InitNode = chickens[8].ChickenInitNode;
                dataToSave.chic9PreviousNode = chickens[8].ChickenPreviousNode;
                dataToSave.chic9CurrentNode = chickens[8].ChickenCurrentNode;
                dataToSave.chic9NextNode = (int)chickens[8].chickenNextNode;
                dataToSave.chic9Position = chickens[8].position;
                dataToSave.chic9Rotation = chickens[8].rotation;
                dataToSave.chic9RiseRun = chickens[8].riseRun;
                dataToSave.chic9EggLaid = chickens[8].eggLaid;
            }
            else
            {
                dataToSave.chic9time = -1;
            }
            //save chicken10
            if (chickens[9] != null)
            {
                dataToSave.chic10time = chickens[9].time;
                dataToSave.chic10state = chickens[9].state;
                dataToSave.chic10ground = chickens[9].ground;
                dataToSave.chic10InitNode = chickens[9].ChickenInitNode;
                dataToSave.chic10PreviousNode = chickens[9].ChickenPreviousNode;
                dataToSave.chic10CurrentNode = chickens[9].ChickenCurrentNode;
                dataToSave.chic10NextNode = (int)chickens[9].chickenNextNode;
                dataToSave.chic10Position = chickens[9].position;
                dataToSave.chic10Rotation = chickens[9].rotation;
                dataToSave.chic10RiseRun = chickens[9].riseRun;
                dataToSave.chic10EggLaid = chickens[9].eggLaid;
            }
            else
            {
                dataToSave.chic10time = -1;
            }

            //economics save
            dataToSave.money = eco.money;
            dataToSave.startEggs = eco.startEggs;
            dataToSave.startChickens = eco.startChickens;
            dataToSave.startRoosters = eco.startRoosters;
            dataToSave.startmoney = eco.startmoney;
            dataToSave.eggsCollected = eco.eggsCollected;
            dataToSave.chickenBought = eco.chickenBought;
            dataToSave.roosterBought = eco.roosterBought;
            dataToSave.eggsEaten = eco.eggsEaten;
            dataToSave.eggSold = eco.eggSold;
            dataToSave.chickenSold = eco.chickenSold;
            dataToSave.roosterSold = eco.roosterSold;
            dataToSave.chickenEaten = eco.chickenEaten;
            dataToSave.roosterEaten = eco.roosterEaten;
            dataToSave.moneyAquired = eco.moneyAquired;

            //rooster save
            dataToSave.numRooster = numRooster;
            dataToSave.roosterQueue = roosterQueue;

            //rooster1 save
            if (roosters[0] != null)
            {
                dataToSave.rooster1state = roosters[0].state;
                dataToSave.rooster1InitNode = roosters[0].roosterInitNode;
                dataToSave.rooster1PreviousNode = roosters[0].roosterPreviousNode;
                dataToSave.rooster1CurrentNode = roosters[0].roosterCurrentNode;
                dataToSave.rooster1NextNode = roosters[0].roosterNextNode;
                dataToSave.rooster1Position = roosters[0].position;
                dataToSave.rooster1Rotation = roosters[0].rotation;
                dataToSave.rooster1RiseRun = roosters[0].riseRun;
                dataToSave.rooster1RiseRun2 = roosters[0].riseRun2;
                dataToSave.rooster1Start = roosters[0].start;
            }
            else
            {
                dataToSave.rooster1state = -1;
            }

            //rooster2 save
            if (roosters[1] != null)
            {
                dataToSave.rooster2state = roosters[1].state;
                dataToSave.rooster2InitNode = roosters[1].roosterInitNode;
                dataToSave.rooster2PreviousNode = roosters[1].roosterPreviousNode;
                dataToSave.rooster2CurrentNode = roosters[1].roosterCurrentNode;
                dataToSave.rooster2NextNode = roosters[1].roosterNextNode;
                dataToSave.rooster2Position = roosters[1].position;
                dataToSave.rooster2Rotation = roosters[1].rotation;
                dataToSave.rooster2RiseRun = roosters[1].riseRun;
                dataToSave.rooster2RiseRun2 = roosters[1].riseRun2;
                dataToSave.rooster2Start = roosters[1].start;
            }
            else
            {
                dataToSave.rooster2state = -1;
            }

            //rooster3 save
            if (roosters[2] != null)
            {
                dataToSave.rooster3state = roosters[2].state;
                dataToSave.rooster3InitNode = roosters[2].roosterInitNode;
                dataToSave.rooster3PreviousNode = roosters[2].roosterPreviousNode;
                dataToSave.rooster3CurrentNode = roosters[2].roosterCurrentNode;
                dataToSave.rooster3NextNode = roosters[2].roosterNextNode;
                dataToSave.rooster3Position = roosters[2].position;
                dataToSave.rooster3Rotation = roosters[2].rotation;
                dataToSave.rooster3RiseRun = roosters[2].riseRun;
                dataToSave.rooster3RiseRun2 = roosters[2].riseRun2;
                dataToSave.rooster3Start = roosters[2].start;
            }
            else
            {
                dataToSave.rooster3state = -1;
            }

            //rooster4 save
            if (roosters[3] != null)
            {
                dataToSave.rooster4state = roosters[3].state;
                dataToSave.rooster4InitNode = roosters[3].roosterInitNode;
                dataToSave.rooster4PreviousNode = roosters[3].roosterPreviousNode;
                dataToSave.rooster4CurrentNode = roosters[3].roosterCurrentNode;
                dataToSave.rooster4NextNode = roosters[3].roosterNextNode;
                dataToSave.rooster4Position = roosters[3].position;
                dataToSave.rooster4Rotation = roosters[3].rotation;
                dataToSave.rooster4RiseRun = roosters[3].riseRun;
                dataToSave.rooster4RiseRun2 = roosters[3].riseRun2;
                dataToSave.rooster4Start = roosters[3].start;
            }
            else
            {
                dataToSave.rooster4state = -1;
            }

            //rooster5 save
            if (roosters[4] != null)
            {
                dataToSave.rooster5state = roosters[4].state;
                dataToSave.rooster5InitNode = roosters[4].roosterInitNode;
                dataToSave.rooster5PreviousNode = roosters[4].roosterPreviousNode;
                dataToSave.rooster5CurrentNode = roosters[4].roosterCurrentNode;
                dataToSave.rooster5NextNode = roosters[4].roosterNextNode;
                dataToSave.rooster5Position = roosters[4].position;
                dataToSave.rooster5Rotation = roosters[4].rotation;
                dataToSave.rooster5RiseRun = roosters[4].riseRun;
                dataToSave.rooster5RiseRun2 = roosters[4].riseRun2;
                dataToSave.rooster5Start = roosters[4].start;
            }
            else
            {
                dataToSave.rooster5state = -1;
            }

            //eggclass
            dataToSave.eggCount = eggCount;
            dataToSave.numEgg = numEgg;
            if (numEgg > 0)
            {
                dataToSave.egg1 = egg[0].position;
            }
            if (numEgg > 1)
            {
                dataToSave.egg2 = egg[1].position;
            }
            if (numEgg > 2)
            {
                dataToSave.egg3 = egg[2].position;
            }
            if (numEgg > 3)
            {
                dataToSave.egg4 = egg[3].position;
            }
            if (numEgg > 4)
            {
                dataToSave.egg5 = egg[4].position;
            }
            if (numEgg > 5)
            {
                dataToSave.egg6 = egg[5].position;
            }
            if (numEgg > 6)
            {
                dataToSave.egg7 = egg[6].position;
            }
            if (numEgg > 7)
            {
                dataToSave.egg8 = egg[7].position;
            }
            if (numEgg > 8)
            {
                dataToSave.egg9 = egg[8].position;
            }
            if (numEgg > 9)
            {
                dataToSave.egg10 = egg[9].position;
            }
            if (numEgg > 10)
            {
                dataToSave.egg11 = egg[10].position;
            }
            if (numEgg > 11)
            {
                dataToSave.egg12 = egg[11].position;
            }
            if (numEgg > 12)
            {
                dataToSave.egg13 = egg[12].position;
            }
            if (numEgg > 13)
            {
                dataToSave.egg14 = egg[13].position;
            }
            if (numEgg > 14)
            {
                dataToSave.egg15 = egg[14].position;
            }
            if (numEgg > 15)
            {
                dataToSave.egg16 = egg[15].position;
            }
            if (numEgg > 16)
            {
                dataToSave.egg17 = egg[16].position;
            }
            if (numEgg > 17)
            {
                dataToSave.egg18 = egg[17].position;
            }
            if (numEgg > 18)
            {
                dataToSave.egg19 = egg[18].position;
            }
            if (numEgg > 19)
            {
                dataToSave.egg20 = egg[19].position;
            }

            dataToSave.days = days;           //tracks number of total days
            dataToSave.dayTime = dayTime; //tracks number of seconds since day began
            dataToSave.endOfDay = endOfDay;

            //boots
            dataToSave.numBoots = numBoots;
            if (numBoots > 0)
            {
                dataToSave.boot1 = boots[0].position;
            }
            if (numBoots > 1)
            {
                dataToSave.boot2 = boots[1].position;
            }
            dataToSave.bootTime = bootTime;
            dataToSave.bootPresent = bootPresent;
            dataToSave.bootEquipped = bootEquipped;

            //fox
            dataToSave.foxWandering = fox.wandering;
            dataToSave.foxInitNode = fox.foxInitNode;
            dataToSave.foxPreviousNode = fox.foxPreviousNode;
            dataToSave.foxCurrentNode = fox.foxCurrentNode;
            dataToSave.foxNextNode = fox.foxNextNode;
            dataToSave.foxPosition = fox.position;
            dataToSave.foxPositionOld = fox.positionOld;
            dataToSave.foxRotation = fox.rotation;
            dataToSave.foxRiseRun = fox.riseRun;
            dataToSave.foxRiseRun2 = fox.riseRun2;
            dataToSave.foxChasing = fox.chasing;
            dataToSave.foxAvoiding = fox.avoiding;
            dataToSave.foxTimer = fox.timer;
            dataToSave.foxChaseTime = fox.chaseTime;
            dataToSave.foxTimer2 = fox.timer2;
            dataToSave.foxHome = fox.home;
            dataToSave.foxStart = fox.start;
            dataToSave.foxTemp1 = fox.temp1;

            StorageContainer myContainer = storageDevice.OpenContainer("Chicken_Game");
            // Here is the path to where you want to save your data
            string nameOfFile = Path.Combine(myContainer.Path, "ChickenGameSave.sav");
            // If the file doesn't exist, it will be created, if it does, it will be replaced
            FileStream fileStream = File.Open(nameOfFile, FileMode.Create);
            XmlSerializer serializer = new XmlSerializer(typeof(DataToSave));
            serializer.Serialize(fileStream, dataToSave);
            //close this file
            fileStream.Close();
            myContainer.Dispose();
        }
コード例 #4
0
ファイル: Game1.cs プロジェクト: semurr/ChickenRanch
        private void LoadData(StorageDevice storageDevice,ref int numChic, ref int chicQueue, ref int numRooster, 
            ref int roosterQueue, ref CharacterClass player, ref ChickenClass[] chickens, ref RoosterClass[] roosters,
            ref EconomicsClass eco, ref int eggCount, ref int numEgg, ref EggClass[] egg, ref int days, ref float dayTime,
            ref bool endOfDay, ref int numBoots, ref RubberBootClass[] boots, ref float bootTime, ref bool bootPresent,
            ref bool bootEquipped, ref FoxClass fox)
        {
            StorageContainer myContainer = storageDevice.OpenContainer("Chicken_Game");
            string filename = Path.Combine(myContainer.Path, "ChickenGameSave.sav");
            if (!File.Exists(filename))
                return;
            FileStream fileStream = File.Open(filename, FileMode.OpenOrCreate, FileAccess.Read);
            XmlSerializer serializer = new XmlSerializer(typeof(DataToSave));
            DataToSave dataToSave = (DataToSave)serializer.Deserialize(fileStream);
            fileStream.Close();
            myContainer.Dispose();

            //load character
            player.position = dataToSave.cPosition;
            player.rotation = dataToSave.cRotation;
            player.hitPoints = dataToSave.hitpoints;

            //load chickens
            numChic = dataToSave.numChickens;
            chicQueue = dataToSave.ChicQueue;

            //load chicken1
            if (dataToSave.chic1time != -1)
            {
                chickens[0] = new ChickenClass(Content, graphics);
                chickens[0].InitializeChicken(0);
                chickens[0].time = dataToSave.chic1time;
                chickens[0].state = dataToSave.chic1state;
                chickens[0].ground = dataToSave.chic1ground;
                chickens[0].ChickenInitNode = dataToSave.chic1InitNode;
                chickens[0].ChickenPreviousNode = dataToSave.chic1PreviousNode;
                chickens[0].ChickenCurrentNode = dataToSave.chic1CurrentNode;
                chickens[0].chickenNextNode = dataToSave.chic1NextNode;
                chickens[0].position = dataToSave.chic1Position;
                chickens[0].rotation = dataToSave.chic1Rotation;
                chickens[0].riseRun = dataToSave.chic1RiseRun;
                chickens[0].eggLaid = dataToSave.chic1EggLaid;
            }
            //load chicken2
            if (dataToSave.chic2time != -1)
            {
                chickens[1] = new ChickenClass(Content, graphics);
                chickens[1].InitializeChicken(0);
                chickens[1].time = dataToSave.chic2time;
                chickens[1].state = dataToSave.chic2state;
                chickens[1].ground = dataToSave.chic2ground;
                chickens[1].ChickenInitNode = dataToSave.chic2InitNode;
                chickens[1].ChickenPreviousNode = dataToSave.chic2PreviousNode;
                chickens[1].ChickenCurrentNode = dataToSave.chic2CurrentNode;
                chickens[1].chickenNextNode = dataToSave.chic2NextNode;
                chickens[1].position = dataToSave.chic2Position;
                chickens[1].rotation = dataToSave.chic2Rotation;
                chickens[1].riseRun = dataToSave.chic2RiseRun;
                chickens[1].eggLaid = dataToSave.chic2EggLaid;
            }
            //load chicken3
            if (dataToSave.chic3time != -1)
            {
                chickens[2] = new ChickenClass(Content, graphics);
                chickens[2].InitializeChicken(0);
                chickens[2].time = dataToSave.chic3time;
                chickens[2].state = dataToSave.chic3state;
                chickens[2].ground = dataToSave.chic3ground;
                chickens[2].ChickenInitNode = dataToSave.chic3InitNode;
                chickens[2].ChickenPreviousNode = dataToSave.chic3PreviousNode;
                chickens[2].ChickenCurrentNode = dataToSave.chic3CurrentNode;
                chickens[2].chickenNextNode = dataToSave.chic3NextNode;
                chickens[2].position = dataToSave.chic3Position;
                chickens[2].rotation = dataToSave.chic3Rotation;
                chickens[2].riseRun = dataToSave.chic3RiseRun;
                chickens[2].eggLaid = dataToSave.chic3EggLaid;
            }
            //load chicken4
            if (dataToSave.chic4time != -1)
            {
                chickens[3] = new ChickenClass(Content, graphics);
                chickens[3].InitializeChicken(0);
                chickens[3].time = dataToSave.chic4time;
                chickens[3].state = dataToSave.chic4state;
                chickens[3].ground = dataToSave.chic4ground;
                chickens[3].ChickenInitNode = dataToSave.chic4InitNode;
                chickens[3].ChickenPreviousNode = dataToSave.chic4PreviousNode;
                chickens[3].ChickenCurrentNode = dataToSave.chic4CurrentNode;
                chickens[3].chickenNextNode = dataToSave.chic4NextNode;
                chickens[3].position = dataToSave.chic4Position;
                chickens[3].rotation = dataToSave.chic4Rotation;
                chickens[3].riseRun = dataToSave.chic4RiseRun;
                chickens[3].eggLaid = dataToSave.chic4EggLaid;
            }
            //load chicken5
            if (dataToSave.chic5time != -1)
            {
                chickens[4] = new ChickenClass(Content, graphics);
                chickens[4].InitializeChicken(0);
                chickens[4].time = dataToSave.chic5time;
                chickens[4].state = dataToSave.chic5state;
                chickens[4].ground = dataToSave.chic5ground;
                chickens[4].ChickenInitNode = dataToSave.chic5InitNode;
                chickens[4].ChickenPreviousNode = dataToSave.chic5PreviousNode;
                chickens[4].ChickenCurrentNode = dataToSave.chic5CurrentNode;
                chickens[4].chickenNextNode = dataToSave.chic5NextNode;
                chickens[4].position = dataToSave.chic5Position;
                chickens[4].rotation = dataToSave.chic5Rotation;
                chickens[4].riseRun = dataToSave.chic5RiseRun;
                chickens[4].eggLaid = dataToSave.chic5EggLaid;
            }
            //load chicken6
            if (dataToSave.chic6time != -1)
            {
                chickens[5] = new ChickenClass(Content, graphics);
                chickens[5].InitializeChicken(0);
                chickens[5].time = dataToSave.chic6time;
                chickens[5].state = dataToSave.chic6state;
                chickens[5].ground = dataToSave.chic6ground;
                chickens[5].ChickenInitNode = dataToSave.chic6InitNode;
                chickens[5].ChickenPreviousNode = dataToSave.chic6PreviousNode;
                chickens[5].ChickenCurrentNode = dataToSave.chic6CurrentNode;
                chickens[5].chickenNextNode = dataToSave.chic6NextNode;
                chickens[5].position = dataToSave.chic6Position;
                chickens[5].rotation = dataToSave.chic6Rotation;
                chickens[5].riseRun = dataToSave.chic6RiseRun;
                chickens[5].eggLaid = dataToSave.chic6EggLaid;
            }
            //load chicken7
            if (dataToSave.chic7time != -1)
            {
                chickens[6] = new ChickenClass(Content, graphics);
                chickens[6].InitializeChicken(0);
                chickens[6].time = dataToSave.chic7time;
                chickens[6].state = dataToSave.chic7state;
                chickens[6].ground = dataToSave.chic7ground;
                chickens[6].ChickenInitNode = dataToSave.chic7InitNode;
                chickens[6].ChickenPreviousNode = dataToSave.chic7PreviousNode;
                chickens[6].ChickenCurrentNode = dataToSave.chic7CurrentNode;
                chickens[6].chickenNextNode = dataToSave.chic7NextNode;
                chickens[6].position = dataToSave.chic7Position;
                chickens[6].rotation = dataToSave.chic7Rotation;
                chickens[6].riseRun = dataToSave.chic7RiseRun;
                chickens[6].eggLaid = dataToSave.chic7EggLaid;
            }
            //load chicken8
            if (dataToSave.chic8time != -1)
            {
                chickens[7] = new ChickenClass(Content, graphics);
                chickens[7].InitializeChicken(0);
                chickens[7].time = dataToSave.chic8time;
                chickens[7].state = dataToSave.chic8state;
                chickens[7].ground = dataToSave.chic8ground;
                chickens[7].ChickenInitNode = dataToSave.chic8InitNode;
                chickens[7].ChickenPreviousNode = dataToSave.chic8PreviousNode;
                chickens[7].ChickenCurrentNode = dataToSave.chic8CurrentNode;
                chickens[7].chickenNextNode = dataToSave.chic8NextNode;
                chickens[7].position = dataToSave.chic8Position;
                chickens[7].rotation = dataToSave.chic8Rotation;
                chickens[7].riseRun = dataToSave.chic8RiseRun;
                chickens[7].eggLaid = dataToSave.chic8EggLaid;
            }
            //load chicken9
            if (dataToSave.chic9time != -1)
            {
                chickens[8] = new ChickenClass(Content, graphics);
                chickens[8].InitializeChicken(0);
                chickens[8].time = dataToSave.chic9time;
                chickens[8].state = dataToSave.chic9state;
                chickens[8].ground = dataToSave.chic9ground;
                chickens[8].ChickenInitNode = dataToSave.chic9InitNode;
                chickens[8].ChickenPreviousNode = dataToSave.chic9PreviousNode;
                chickens[8].ChickenCurrentNode = dataToSave.chic9CurrentNode;
                chickens[8].chickenNextNode = dataToSave.chic9NextNode;
                chickens[8].position = dataToSave.chic9Position;
                chickens[8].rotation = dataToSave.chic9Rotation;
                chickens[8].riseRun = dataToSave.chic9RiseRun;
                chickens[8].eggLaid = dataToSave.chic9EggLaid;
            }
            //load chicken1
            if (dataToSave.chic10time != -1)
            {
                chickens[9] = new ChickenClass(Content, graphics);
                chickens[9].InitializeChicken(0);
                chickens[9].time = dataToSave.chic10time;
                chickens[9].state = dataToSave.chic10state;
                chickens[9].ground = dataToSave.chic10ground;
                chickens[9].ChickenInitNode = dataToSave.chic10InitNode;
                chickens[9].ChickenPreviousNode = dataToSave.chic10PreviousNode;
                chickens[9].ChickenCurrentNode = dataToSave.chic10CurrentNode;
                chickens[9].chickenNextNode = dataToSave.chic10NextNode;
                chickens[9].position = dataToSave.chic10Position;
                chickens[9].rotation = dataToSave.chic10Rotation;
                chickens[9].riseRun = dataToSave.chic10RiseRun;
                chickens[9].eggLaid = dataToSave.chic10EggLaid;
            }

            //economics save
            eco.money = dataToSave.money;
            eco.startEggs = dataToSave.startEggs;
            eco.startChickens = dataToSave.startChickens;
            eco.startRoosters = dataToSave.startRoosters;
            eco.startmoney = dataToSave.startmoney;
            eco.eggsCollected = dataToSave.eggsCollected;
            eco.chickenBought = dataToSave.chickenBought;
            eco.roosterBought = dataToSave.roosterBought;
            eco.eggsEaten = dataToSave.eggsEaten;
            eco.eggSold = dataToSave.eggSold;
            eco.chickenSold = dataToSave.chickenSold;
            eco.roosterSold = dataToSave.roosterSold;
            eco.chickenEaten = dataToSave.chickenEaten;
            eco.roosterEaten = dataToSave.roosterEaten;
            eco.moneyAquired = dataToSave.moneyAquired;

            //load roosters
            numRooster = dataToSave.numRooster;
            roosterQueue = dataToSave.roosterQueue;

            //rooster1 load
            if (dataToSave.rooster1state != -1)
            {
                roosters[0] = new RoosterClass(Content, graphics);
                roosters[0].InitializeRooster(13);
                roosters[0].state = dataToSave.rooster1state;
                roosters[0].roosterInitNode = dataToSave.rooster1InitNode;
                roosters[0].roosterPreviousNode = dataToSave.rooster1PreviousNode;
                roosters[0].roosterCurrentNode = dataToSave.rooster1CurrentNode;
                roosters[0].roosterNextNode = dataToSave.rooster1NextNode;
                roosters[0].position = dataToSave.rooster1Position;
                roosters[0].rotation = dataToSave.rooster1Rotation;
                roosters[0].riseRun = dataToSave.rooster1RiseRun;
                roosters[0].riseRun2 = dataToSave.rooster1RiseRun2;
                roosters[0].start = dataToSave.rooster1Start;
            }

            //rooster2 load
            if (dataToSave.rooster2state != -1)
            {
                roosters[1] = new RoosterClass(Content, graphics);
                roosters[1].InitializeRooster(13);
                roosters[1].state = dataToSave.rooster2state;
                roosters[1].roosterInitNode = dataToSave.rooster2InitNode;
                roosters[1].roosterPreviousNode = dataToSave.rooster2PreviousNode;

                roosters[1].roosterCurrentNode = dataToSave.rooster2CurrentNode;
                roosters[1].roosterNextNode = dataToSave.rooster2NextNode;
                roosters[1].position = dataToSave.rooster2Position;
                roosters[1].rotation = dataToSave.rooster2Rotation;
                roosters[1].riseRun = dataToSave.rooster2RiseRun;
                roosters[1].riseRun2 = dataToSave.rooster2RiseRun2;
                roosters[1].start = dataToSave.rooster2Start;
            }

            //rooster3 load
            if (dataToSave.rooster3state != -1)
            {
                roosters[2] = new RoosterClass(Content, graphics);
                roosters[2].InitializeRooster(13);
                roosters[2].state = dataToSave.rooster3state;
                roosters[2].roosterInitNode = dataToSave.rooster3InitNode;
                roosters[2].roosterPreviousNode = dataToSave.rooster3PreviousNode;
                roosters[2].roosterCurrentNode = dataToSave.rooster3CurrentNode;
                roosters[2].roosterNextNode = dataToSave.rooster3NextNode;
                roosters[2].position = dataToSave.rooster3Position;
                roosters[2].rotation = dataToSave.rooster3Rotation;
                roosters[2].riseRun = dataToSave.rooster3RiseRun;
                roosters[2].riseRun2 = dataToSave.rooster3RiseRun2;
                roosters[2].start = dataToSave.rooster3Start;
            }

            //rooster4 load
            if (dataToSave.rooster4state != -1)
            {
                roosters[3] = new RoosterClass(Content, graphics);
                roosters[3].InitializeRooster(13);
                roosters[3].state = dataToSave.rooster4state;
                roosters[3].roosterInitNode = dataToSave.rooster4InitNode;
                roosters[3].roosterPreviousNode = dataToSave.rooster4PreviousNode;
                roosters[3].roosterCurrentNode = dataToSave.rooster4CurrentNode;
                roosters[3].roosterNextNode = dataToSave.rooster4NextNode;
                roosters[3].position = dataToSave.rooster4Position;
                roosters[3].rotation = dataToSave.rooster4Rotation;
                roosters[3].riseRun = dataToSave.rooster4RiseRun;
                roosters[3].riseRun2 = dataToSave.rooster4RiseRun2;
                roosters[3].start = dataToSave.rooster4Start;
            }

            //rooster5 load
            if (dataToSave.rooster5state != -1)
            {
                roosters[4] = new RoosterClass(Content, graphics);
                roosters[4].InitializeRooster(13);
                roosters[4].state = dataToSave.rooster5state;
                roosters[4].roosterInitNode = dataToSave.rooster5InitNode;
                roosters[4].roosterPreviousNode = dataToSave.rooster5PreviousNode;
                roosters[4].roosterCurrentNode = dataToSave.rooster5CurrentNode;
                roosters[4].roosterNextNode = dataToSave.rooster5NextNode;
                roosters[4].position = dataToSave.rooster5Position;
                roosters[4].rotation = dataToSave.rooster5Rotation;
                roosters[4].riseRun = dataToSave.rooster5RiseRun;
                roosters[4].riseRun2 = dataToSave.rooster5RiseRun2;
                roosters[4].start = dataToSave.rooster5Start;
            }

            //eggclass
            eggCount = dataToSave.eggCount;
            numEgg = dataToSave.numEgg;
            if (numEgg > 0)
            {
                egg[0].position = new Vector3();
                egg[0].position = new Vector3(dataToSave.egg1.X, dataToSave.egg1.Y, dataToSave.egg1.Z);
            }
            if (numEgg > 1)
            {
                egg[1].position = new Vector3();
                egg[1].position = new Vector3(dataToSave.egg2.X, dataToSave.egg2.Y, dataToSave.egg2.Z);
            }
            if (numEgg > 2)
            {
                egg[2].position = new Vector3();
                egg[2].position = new Vector3(dataToSave.egg3.X,dataToSave.egg3.Y,dataToSave.egg3.Z);
            }
            if (numEgg > 3)
            {
                egg[3].position = new Vector3();
                egg[3].position = new Vector3(dataToSave.egg4.X,dataToSave.egg4.Y, dataToSave.egg4.Z);
            }
            if (numEgg > 4)
            {
                egg[4].position = new Vector3();
                egg[4].position = new Vector3(dataToSave.egg5.X, dataToSave.egg5.Y, dataToSave.egg5.Z);
            }
            if (numEgg > 5)
            {
                egg[5].position = new Vector3();
                egg[5].position = new Vector3(dataToSave.egg6.X, dataToSave.egg6.Y, dataToSave.egg6.Z);
            }
            if (numEgg > 6)
            {
                egg[6].position = new Vector3();
                egg[6].position = new Vector3(dataToSave.egg7.X, dataToSave.egg7.Y, dataToSave.egg7.Z);
            }
            if (numEgg > 7)
            {
                egg[7].position = new Vector3();
                egg[7].position = new Vector3(dataToSave.egg8.X, dataToSave.egg8.Y, dataToSave.egg8.Z);
            }
            if (numEgg > 8)
            {
                egg[8].position = new Vector3();
                egg[8].position = new Vector3(dataToSave.egg9.X, dataToSave.egg9.Y, dataToSave.egg9.Z);
            }
            if (numEgg > 9)
            {
                egg[9].position = new Vector3();
                egg[9].position = new Vector3(dataToSave.egg10.X, dataToSave.egg10.Y, dataToSave.egg10.Z);
            }
            if (numEgg > 10)
            {
                egg[10].position = new Vector3();
                egg[10].position = new Vector3(dataToSave.egg11.X, dataToSave.egg11.Y, dataToSave.egg11.Z);
            }
            if (numEgg > 11)
            {
                egg[11].position = new Vector3();
                egg[11].position = new Vector3(dataToSave.egg12.X, dataToSave.egg12.Y, dataToSave.egg12.Z);
            }
            if (numEgg > 12)
            {
                egg[12].position = new Vector3();
                egg[12].position = new Vector3(dataToSave.egg13.X, dataToSave.egg13.Y, dataToSave.egg13.Z);
            }
            if (numEgg > 13)
            {
                egg[13].position = new Vector3();
                egg[13].position = new Vector3(dataToSave.egg14.X, dataToSave.egg14.Y, dataToSave.egg14.Z);
            }
            if (numEgg > 14)
            {
                egg[14].position = new Vector3();
                egg[14].position = new Vector3(dataToSave.egg15.X, dataToSave.egg15.Y, dataToSave.egg15.Z);
            }
            if (numEgg > 15)
            {
                egg[15].position = new Vector3();
                egg[15].position = new Vector3(dataToSave.egg16.X, dataToSave.egg16.Y, dataToSave.egg16.Z);
            }
            if (numEgg > 16)
            {
                egg[16].position = new Vector3();
                egg[16].position = new Vector3(dataToSave.egg17.X, dataToSave.egg17.Y, dataToSave.egg17.Z);
            }
            if (numEgg > 17)
            {
                egg[17].position = new Vector3();
                egg[17].position = new Vector3(dataToSave.egg18.X, dataToSave.egg18.Y, dataToSave.egg18.Z);
            }
            if (numEgg > 18)
            {
                egg[18].position = new Vector3();
                egg[18].position = new Vector3(dataToSave.egg19.X, dataToSave.egg19.Y, dataToSave.egg19.Z);
            }
            if (numEgg > 19)
            {
                egg[19].position = new Vector3();
                egg[19].position = new Vector3(dataToSave.egg20.X, dataToSave.egg20.Y, dataToSave.egg20.Z);
            }

            days = dataToSave.days;
            dayTime = dataToSave.dayTime;
            endOfDay = dataToSave.endOfDay;

            //boots
            numBoots = dataToSave.numBoots;
            if (numBoots > 0)
            {
                boots[0] = new RubberBootClass(Content, graphics);
                boots[0].position = dataToSave.boot1;
            }
            if (numBoots > 1)
            {
                boots[1] = new RubberBootClass(Content, graphics);
                boots[1].position = dataToSave.boot2;
            }
            bootTime = dataToSave.bootTime;
            bootPresent = dataToSave.bootPresent;
            bootEquipped = dataToSave.bootEquipped;

            //fox
            fox.wandering = dataToSave.foxWandering;
            fox.foxInitNode = dataToSave.foxInitNode;
            fox.foxPreviousNode = dataToSave.foxPreviousNode;
            fox.foxCurrentNode = dataToSave.foxCurrentNode;
            fox.foxNextNode = dataToSave.foxNextNode;
            fox.position = dataToSave.foxPosition;
            fox.positionOld = dataToSave.foxPositionOld;
            fox.rotation = dataToSave.foxRotation;
            fox.riseRun = dataToSave.foxRiseRun;
            fox.riseRun2 = dataToSave.foxRiseRun2;
            fox.chasing = dataToSave.foxChasing;
            fox.avoiding = dataToSave.foxAvoiding;
            fox.timer = dataToSave.foxTimer;
            fox.chaseTime = dataToSave.foxChaseTime;
            fox.timer2 = dataToSave.foxTimer2;
            fox.home = dataToSave.foxHome;
            fox.start = dataToSave.foxStart;
            fox.temp1 = dataToSave.foxTemp1;
        }
コード例 #5
0
ファイル: CharacterClass.cs プロジェクト: semurr/ChickenRanch
        public void update(GameTime gameTime, BrokenEggClass[] brokenEggLst,
                            int numBrokeEgg, bool bootEquipped, ref Vector3 cameraPosition,
                            ref Vector3 cameraLookAt, ref Matrix cameraViewMatrix, EconomicsClass player, 
                            ref int totalEggs)
        {
            elapsed += (float)gameTime.ElapsedGameTime.TotalSeconds;
            moveNormal(cameraPosition, ref cameraViewMatrix);

            //if there are broken eggs on ground
            for (int i = 0; i < numBrokeEgg; i++)
            {
                //test to see if character is walking on broken eggs
                //if on eggs, slide until off
                if (Vector3.Distance(position, brokenEggLst[i].position) <= 250 && bootEquipped == false)
                {
                    //slide code
                    Chicken.AudioManager.instance.setSlipEffectInstance(Chicken.AudioManager.instance.eggSlipSound);
                    if (Chicken.AudioManager.instance.sFXOn == true && Chicken.AudioManager.instance.
                        sFXeggSlipInstance.State != SoundState.Playing && GameUI.gameWorld.instance.isPaused != true)
                    {

                        Chicken.AudioManager.instance.sFXeggSlipInstance.Volume = 0.1f;
                        Chicken.AudioManager.instance.sFXeggSlipInstance.Play();
                    }
                    displacement = ((speed * speed) / 2) / force;
                    if (moveBack == true)
                    {
                        position.X -= displacement * (float)Math.Sin(rotation);
                        position.Z -= displacement * (float)Math.Cos(rotation);
                    }
                    else
                    {
                        position.X += displacement * (float)Math.Sin(rotation);
                        position.Z += displacement * (float)Math.Cos(rotation);
                    }
                }
            }

            //hotkey for eat egg
            GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);
            KeyboardState keyBoardState = Keyboard.GetState();

            //eat egg gamepad hotkey
            if (gamePadState.IsButtonDown(Buttons.Y) && buttonDown == false)
            {
                //eat egg
                player.eatEgg(ref hitPoints, maxHP, ref totalEggs);
                buttonDown = true;
            }
            if (gamePadState.IsButtonUp(Buttons.Y) && buttonDown == true)
            {
                buttonDown = false;
            }

            //eat egg keyboard hotkey
            if (keyBoardState.IsKeyDown(Keys.E) && buttonDown2 == false)
            {
                //eat egg
                player.eatEgg(ref hitPoints, maxHP, ref totalEggs);
                buttonDown2 = true;
            }

            if (keyBoardState.IsKeyUp(Keys.E) && buttonDown2 == true)
            {
                buttonDown2 = false;
            }
        }