Ejemplo n.º 1
0
        public static string ReinitialseSavegame(ref HudScreen hudScreen)
        {
            if (!File.Exists(PauseScreen.GetSavedGamesPath() + "\\Camera.xml") ||
                !File.Exists(PauseScreen.GetSavedGamesPath() + "\\CapuchinPositions.xml") ||
                !File.Exists(PauseScreen.GetSavedGamesPath() + "\\ChimpPositions.xml") ||
                !File.Exists(PauseScreen.GetSavedGamesPath() + "\\GibbonPositions.xml") ||
                !File.Exists(PauseScreen.GetSavedGamesPath() + "\\HudScreen.xml") ||
                !File.Exists(PauseScreen.GetSavedGamesPath() + "\\Huts.xml") ||
                !File.Exists(PauseScreen.GetSavedGamesPath() + "\\Level.xml") ||
                !File.Exists(PauseScreen.GetSavedGamesPath() + "\\OrangPositions.xml") ||
                !File.Exists(PauseScreen.GetSavedGamesPath() + "\\Silverback.xml"))
            {
                return("There are missing files");
            }

            var serializer = new XmlSerializer(typeof(Camera));

            using (var fs = File.OpenRead(GetSavedGamesPath() + "\\Camera.xml"))
            {
                Camera camera = null;
                try
                {
                    camera = (Camera)serializer.Deserialize(fs);
                }
                catch (Exception ex)
                {
                    return(ex.ToString());
                }

                hudScreen.mGameScreen.mCamera = camera;
                hudScreen.mGameScreen.mCameraHandler.mCamera = camera;
                fs.Close();
            }

            serializer = new XmlSerializer(typeof(Level), new XmlRootAttribute("Level"));

            using (var fs = File.OpenRead(GetSavedGamesPath() + "\\Level.xml"))
            {
                Level level = null;
                try
                {
                    level = (Level)serializer.Deserialize(fs);
                }
                catch (Exception ex)
                {
                    return(ex.ToString());
                }
                hudScreen.mGameScreen.mLevel.Dispose();
                hudScreen.mGameScreen.mLevel = level;
                hudScreen.mGameScreen.mLevel?.Load(level?.mLevelFilename);
                fs.Close();
            }

            if (hudScreen.mGameScreen.mLevel != null)
            {
                var oldSilverback = hudScreen.mGameScreen.mLevel.mSilverback;
            }

            serializer = new XmlSerializer(typeof(Silverback));

            using (var fs = File.OpenRead(PauseScreen.GetSavedGamesPath() + "\\Silverback.xml"))
            {
                Silverback silverback = null;
                try
                {
                    silverback = (Silverback)serializer.Deserialize(fs);
                }
                catch (Exception ex)
                {
                    return(ex.ToString());
                }

                if (hudScreen.mGameScreen.mLevel != null)
                {
                    if (silverback != null)
                    {
                        hudScreen.mGameScreen.mLevel.mSilverback.HP = silverback.HP;
                    }
                }
                fs.Close();
            }

            serializer = new XmlSerializer(typeof(List <Matrix>));

            using (var fs = File.OpenRead(PauseScreen.GetSavedGamesPath() + "\\CapuchinPositions.xml"))
            {
                var positions = new List <Matrix>();
                try
                {
                    positions = (List <Matrix>)serializer.Deserialize(fs);


                    var rand = new Random();

                    foreach (var matrix in positions)
                    {
                        if (hudScreen.mGameScreen.mLevel != null)
                        {
                            var mcapuchin = new Capuchin(hudScreen.mGameScreen.mLevel.mCapuchinMesh,
                                                         hudScreen.mGameScreen.mLevel.mTerrain,
                                                         hudScreen.mGameScreen.mLevel.mSilverback,
                                                         hudScreen.mGameScreen.mLevel,
                                                         ref rand);
                            mcapuchin.Actor.ModelMatrix = matrix;
                            hudScreen.mGameScreen.mLevel.Add(mcapuchin);
                        }

                        LumberChoice.AddApe(3);
                    }
                }
                catch (Exception)
                {
                    // ignored
                }

                fs.Close();
            }

            using (var fs = File.OpenRead(PauseScreen.GetSavedGamesPath() + "\\GibbonPositions.xml"))
            {
                var positions = new List <Matrix>();
                try
                {
                    positions = (List <Matrix>)serializer.Deserialize(fs);


                    var rand = new Random();

                    foreach (var matrix in positions)
                    {
                        if (hudScreen.mGameScreen.mLevel != null)
                        {
                            var gibbon = new Gibbon(hudScreen.mGameScreen.mLevel.mGibbonMesh,
                                                    hudScreen.mGameScreen.mLevel.mTerrain,
                                                    hudScreen.mGameScreen.mLevel.mSilverback,
                                                    hudScreen.mGameScreen.mLevel,
                                                    ref rand);
                            gibbon.Actor.ModelMatrix = matrix;
                            hudScreen.mGameScreen.mLevel.Add(gibbon);
                        }

                        LumberChoice.AddApe(4);
                    }
                }
                catch (Exception)
                {
                    // ignored
                }

                fs.Close();
            }

            using (var fs = File.OpenRead(PauseScreen.GetSavedGamesPath() + "\\ChimpPositions.xml"))
            {
                var positions = new List <Matrix>();
                try
                {
                    positions = (List <Matrix>)serializer.Deserialize(fs);


                    var rand = new Random();

                    foreach (var matrix in positions)
                    {
                        if (hudScreen.mGameScreen.mLevel != null)
                        {
                            var chimp = new Chimpanezee(hudScreen.mGameScreen.mLevel.mChimpanezzeMesh,
                                                        hudScreen.mGameScreen.mLevel.mTerrain,
                                                        hudScreen.mGameScreen.mLevel.mSilverback,
                                                        hudScreen.mGameScreen.mLevel,
                                                        ref rand);
                            chimp.Actor.ModelMatrix = matrix;
                            hudScreen.mGameScreen.mLevel.Add(chimp);
                        }
                        LumberChoice.AddApe(1);
                    }
                }
                catch (Exception)
                {
                    // ignored
                }

                fs.Close();
            }

            using (var fs = File.OpenRead(PauseScreen.GetSavedGamesPath() + "\\OrangPositions.xml"))
            {
                var positions = new List <Matrix>();
                try
                {
                    positions = (List <Matrix>)serializer.Deserialize(fs);


                    var rand = new Random();

                    foreach (var matrix in positions)
                    {
                        if (hudScreen.mGameScreen.mLevel != null)
                        {
                            var orang = new OrangUtan(hudScreen.mGameScreen.mLevel.mOrangUtanMesh,
                                                      hudScreen.mGameScreen.mLevel.mTerrain,
                                                      hudScreen.mGameScreen.mLevel.mSilverback,
                                                      hudScreen.mGameScreen.mLevel,
                                                      ref rand);
                            orang.Actor.ModelMatrix = matrix;
                            hudScreen.mGameScreen.mLevel.Add(orang);
                        }

                        LumberChoice.AddApe(2);
                    }
                }
                catch (Exception)
                {
                    // ignored
                }

                fs.Close();
            }


            serializer = new XmlSerializer(typeof(List <Hut>));

            using (var fs = File.OpenRead(PauseScreen.GetSavedGamesPath() + "\\Huts.xml"))
            {
                try
                {
                    Hut.mAmount = 0;
                    var huts = (List <Hut>)serializer.Deserialize(fs) ?? new List <Hut>();
                    if (hudScreen.mGameScreen.mLevel != null)
                    {
                        // hudScreen.mGameScreen.mLevel.mHuts = hudScreen.mGameScreen.mLevel.mHuts.Except(huts).ToList();
                        if (hudScreen.mGameScreen.mLevel != null)
                        {
                            // Remove dead huts from ...mLevel.mHuts

                            var tmpHuts = new List <Hut>();

                            // Yeah this is bad
                            foreach (var h in huts)
                            {
                                foreach (var hut in hudScreen.mGameScreen.mLevel.mHuts)
                                {
                                    if (h.mId == hut.mId)
                                    {
                                        tmpHuts.Add(hut);
                                    }
                                }
                            }

                            hudScreen.mGameScreen.mLevel.mHuts.Clear();
                            hudScreen.mGameScreen.mLevel.mHuts.AddRange(tmpHuts);

                            var screen        = hudScreen;
                            var hutActorBatch = hudScreen.mGameScreen.mLevel.mActorBatches.Find(ele =>
                                                                                                ele.mMesh == screen.mGameScreen.mLevel.mHutMesh);

                            var tmpActors = new List <Actor>();

                            foreach (var actor in hutActorBatch.mActors)
                            {
                                foreach (var hut in hudScreen.mGameScreen.mLevel.mHuts)
                                {
                                    if (hut.Actor == actor)
                                    {
                                        tmpActors.Add(actor);
                                    }
                                }
                            }

                            hutActorBatch.mActors.Clear();
                            hutActorBatch.mActors.AddRange(tmpActors);


                            var i = 0;
                            foreach (var hut in hudScreen.mGameScreen.mLevel.mHuts)
                            {
                                // var contains = false;
                                // foreach (var h in huts)
                                // {
                                //     if (h.mId == hut.mId)
                                //     {
                                //         contains = true;
                                //     }
                                // }
                                //
                                // if (!contains)
                                // {
                                //     hudScreen.mGameScreen.mLevel.mHuts.Remove(hut);
                                //     continue;
                                // }

                                hut.mSilverback          = hudScreen.mGameScreen.mLevel.mSilverback;
                                hut.mAxeMesh             = hudScreen.mGameScreen.mLevel.mAxeMesh;
                                hut.mDoubleAxeKillerMesh = hudScreen.mGameScreen.mLevel.mDoubleAxeKillerMesh;
                                hut.mScene          = hudScreen.mGameScreen.mLevel;
                                hut.mLumberjackMesh = hudScreen.mGameScreen.mLevel.mLumberjackMesh;
                                hut.HP = huts[i++].HP;
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    // ignored
                }

                fs.Close();
            }
            Hut.mAmount = 0;

            return("");
        }
Ejemplo n.º 2
0
        public void LoadContent(GraphicsDeviceManager deviceManager,
                                ContentManager contentManager,
                                int windowWidth,
                                int windowHeight)
        {
            mScreenWidth  = windowWidth;
            mScreenHeight = windowHeight;

            //Load SoundEffects
            mClickSound = contentManager.Load <SoundEffect>("Audio/click2");

            mGraphicsDevice = deviceManager.GraphicsDevice;

            mPauseScreen = new PauseScreen(this);

            mWinScreen  = new WinScreen(this);
            mLoseScreen = new LoseScreen(this);

            mGameScreen = new GameScreen(mLevelPath);
            ScreenManager.Add(mGameScreen);
            mTotalCunter = mGameScreen.mLevel.mSpawnablePrimatesCount;

            mSpriteBatch = new SpriteBatch(mGraphicsDevice);

            // Load font
            var font          = contentManager.Load <SpriteFont>("Font");
            var subHeaderFont = contentManager.Load <SpriteFont>("SubHeaderFont");

            IsVisible = true;

            // Instantiate a new menu
            mMenuList = new List <UIv2.Menu>();

            mButtonTexture = UIv2.Menu.CreateTexture2D(mGraphicsDevice, 200, 30, pixel => Color.Black);
            var textureTransparent = UIv2.Menu.CreateTexture2D(mGraphicsDevice, 10, 10, pixel => Color.Transparent);

            //Highlighted Button
            mHighlightedButtonTexture = UIv2.Menu.CreateTexture2D(mGraphicsDevice, 200, 30, pixel => Color.Orange);

            var menu = new UIv2.Menu(mGraphicsDevice, 0, 95, 100, 5);

            menu.WithBackground(UIv2.Menu.CreateTexture2D(deviceManager.GraphicsDevice,
                                                          windowWidth,
                                                          200,
                                                          pixel => new Color(0.0f, 0.0f, 0.0f, 0.15f)),
                                0,
                                0,
                                100,
                                100);
            mMenuList.Add(menu);

            mCounterMenu = new UIv2.Menu(mGraphicsDevice, 40, 15, 20, 4);
            mCounterMenu.WithBackground(UIv2.Menu.CreateTexture2D(deviceManager.GraphicsDevice,
                                                                  windowWidth,
                                                                  200,
                                                                  pixel => new Color(0.0f, 0.0f, 0.0f, 0.15f)),
                                        0,
                                        0,
                                        100,
                                        100);
            mCounterMenu.NonSolid();
            mMenuList.Add(mCounterMenu);

            var counterLabel = new UIv2.Components.Label(mGraphicsDevice, 0, 0, 100, 100, "Available apes to spawn: " + mGameScreen.mLevel.mSpawnablePrimatesCount, font, Color.White);

            counterLabel.AddTo(mCounterMenu);

            var pauseButton =
                new UIv2.Components.Button(mGraphicsDevice, 90, 0, 7, 100, mButtonTexture, "Pause", font, Color.White);

            pauseButton.AddTo(menu);
            pauseButton.AddListener(MouseButtons.Left,
                                    InputState.Pressed,
                                    () =>
            {
                SoundManager.AddSound(mClickSound);
                ScreenManager.Add(mPauseScreen);
                mGameScreen.mCameraHandler.Lock();
                IsVisible             = false;
                mWasVisible           = false;
                mGameScreen.IsVisible = false;
            });

            mHPLabel = new UIv2.Components.Label(mGraphicsDevice,
                                                 0,
                                                 0,
                                                 45,
                                                 100,
                                                 "HP: ",
                                                 font,
                                                 Color.White);
            mHPLabel.AddTo(menu);

            mTimeLabel = new UIv2.Components.Label(mGraphicsDevice,
                                                   0,
                                                   0,
                                                   10,
                                                   100,
                                                   "",
                                                   font,
                                                   Color.White);
            mTimeLabel.AddTo(menu);

            var levelLabel = new UIv2.Components.Label(mGraphicsDevice,
                                                       10,
                                                       0,
                                                       7,
                                                       100,
                                                       "Level: Tutorial",
                                                       font,
                                                       Color.White);

            levelLabel.AddTo(menu);
            for (var i = 0; i < 0; i++)
            {
                var morang = new OrangUtan(mGameScreen.mLevel.mOrangUtanMesh,
                                           mGameScreen.mLevel.mTerrain,
                                           mGameScreen.mLevel.mSilverback,
                                           mGameScreen.mLevel,
                                           ref mRandom);
                //morang.mScene = mGameScreen.mLevel;
                mGameScreen.mLevel.Add(morang);
            }

            // Create selection button for Baboon
            mApe1Button =
                new UIv2.Components.Button(mGraphicsDevice, 30, 0, 7, 100, mButtonTexture, "Orang", font, Color.White);
            mApe1Button.AddTo(menu);
            mApe1Button.AddListener(MouseButtons.Left,
                                    InputState.Pressed,
                                    () =>
            {
                SoundManager.AddSound(mClickSound);

                if (mGameScreen.mLevel.mSpawnablePrimatesCount == 0)
                {
                    if (mGameScreen.mLevel.mOrangutanBatch.mActors.Count > 0)
                    {
                        UnHiglightSelectedActorBatch();
                        mActorBatch      = mGameScreen.mLevel.mOrangutanBatch;
                        mHighlitedButton = mApe1Button;
                        HighlightSelectedActorBatch();
                    }
                }
                else if (mGameScreen.mLevel.mSpawnablePrimatesCount > 0)
                {
                    mGameScreen.mLevel.mSpawnablePrimatesCount--;
                    mOrangCounter++;
                    counterLabel.Text = "Available apes to spawn: " + mGameScreen.mLevel.mSpawnablePrimatesCount;

                    var morang = new OrangUtan(mGameScreen.mLevel.mOrangUtanMesh,
                                               mGameScreen.mLevel.mTerrain,
                                               mGameScreen.mLevel.mSilverback,
                                               mGameScreen.mLevel,
                                               ref mRandom);
                    //morang.mScene = mGameScreen.mLevel;
                    mGameScreen.mLevel.Add(morang);
                    LumberChoice.AddApe(2);
                }

                if (mGameScreen.mLevel.mSpawnablePrimatesCount == 0)
                {
                    mCounterMenu.mIsVisible = false;
                    DisableUnusedApeSelectorButtons();
                }
            });

            // Create selection button for Capuchin
            mApe2Button = new UIv2.Components.Button(mGraphicsDevice,
                                                     41,
                                                     0,
                                                     7,
                                                     100,
                                                     mButtonTexture,
                                                     "Capuchin",
                                                     font,
                                                     Color.White);
            mApe2Button.AddTo(menu);
            mApe2Button.AddListener(MouseButtons.Left,
                                    InputState.Pressed,
                                    () =>
            {
                SoundManager.AddSound(mClickSound);

                if (mGameScreen.mLevel.mSpawnablePrimatesCount == 0)
                {
                    if (mGameScreen.mLevel.mCapuchinBatch.mActors.Count > 0)
                    {
                        UnHiglightSelectedActorBatch();
                        mActorBatch      = mGameScreen.mLevel.mCapuchinBatch;
                        mHighlitedButton = mApe2Button;
                        HighlightSelectedActorBatch();
                    }
                }
                else if (mGameScreen.mLevel.mSpawnablePrimatesCount > 0)
                {
                    mCapuchinCounter++;
                    counterLabel.Text = "Available apes to spawn: " + mGameScreen.mLevel.mSpawnablePrimatesCount;
                    mGameScreen.mLevel.mSpawnablePrimatesCount--;
                    var mcapuchin = new Capuchin(mGameScreen.mLevel.mCapuchinMesh,
                                                 mGameScreen.mLevel.mTerrain,
                                                 mGameScreen.mLevel.mSilverback,
                                                 mGameScreen.mLevel,
                                                 ref mRandom);
                    mGameScreen.mLevel.Add(mcapuchin);
                    LumberChoice.AddApe(3);
                }

                if (mGameScreen.mLevel.mSpawnablePrimatesCount == 0)
                {
                    mCounterMenu.mIsVisible = false;
                    DisableUnusedApeSelectorButtons();
                }
            });

            // Create selection button for Chimpaneeze
            mApe3Button =
                new UIv2.Components.Button(mGraphicsDevice, 52, 0, 7, 100, mButtonTexture, "Chimp", font, Color.White);
            mApe3Button.AddTo(menu);

            mApe3Button.AddListener(MouseButtons.Left,
                                    InputState.Pressed,
                                    () =>
            {
                SoundManager.AddSound(mClickSound);

                if (mGameScreen.mLevel.mSpawnablePrimatesCount == 0)
                {
                    if (mGameScreen.mLevel.mChimpanezzeBatch.mActors.Count > 0)
                    {
                        UnHiglightSelectedActorBatch();
                        mActorBatch      = mGameScreen.mLevel.mChimpanezzeBatch;
                        mHighlitedButton = mApe3Button;
                        HighlightSelectedActorBatch();
                    }
                }
                else if (mGameScreen.mLevel.mSpawnablePrimatesCount > 0)
                {
                    mChimpCounter++;
                    mGameScreen.mLevel.mSpawnablePrimatesCount--;
                    counterLabel.Text = "Available apes to spawn: " + mGameScreen.mLevel.mSpawnablePrimatesCount;
                    var mchimpanezee  = new Chimpanezee(mGameScreen.mLevel.mChimpanezzeMesh,
                                                        mGameScreen.mLevel.mTerrain,
                                                        mGameScreen.mLevel.mSilverback,
                                                        mGameScreen.mLevel,
                                                        ref mRandom);
                    mGameScreen.mLevel.Add(mchimpanezee);
                    LumberChoice.AddApe(1);
                }

                if (mGameScreen.mLevel.mSpawnablePrimatesCount == 0)
                {
                    mCounterMenu.mIsVisible = false;
                    DisableUnusedApeSelectorButtons();
                }
            }
                                    );

            // Create selection button for Gibbon
            mApe4Button =
                new UIv2.Components.Button(mGraphicsDevice, 63, 0, 7, 100, mButtonTexture, "Gibbon", font, Color.White);
            mApe4Button.AddTo(menu);
            mApe4Button.AddListener(MouseButtons.Left,
                                    InputState.Pressed,
                                    () =>
            {
                SoundManager.AddSound(mClickSound);

                if (mGameScreen.mLevel.mSpawnablePrimatesCount == 0)
                {
                    if (mGameScreen.mLevel.mGibbonBatch.mActors.Count > 0)
                    {
                        UnHiglightSelectedActorBatch();
                        mActorBatch      = mGameScreen.mLevel.mGibbonBatch;
                        mHighlitedButton = mApe4Button;
                        HighlightSelectedActorBatch();
                    }
                }
                else if (mGameScreen.mLevel.mSpawnablePrimatesCount > 0)
                {
                    mGibbonCounter++;
                    mGameScreen.mLevel.mSpawnablePrimatesCount--;
                    counterLabel.Text = "Available apes to spawn: " + mGameScreen.mLevel.mSpawnablePrimatesCount;

                    var mgibbon = new Gibbon(mGameScreen.mLevel.mGibbonMesh,
                                             mGameScreen.mLevel.mTerrain,
                                             mGameScreen.mLevel.mSilverback,
                                             mGameScreen.mLevel,
                                             ref mRandom);
                    mGameScreen.mLevel.Add(mgibbon);
                    LumberChoice.AddApe(4);
                }

                if (mGameScreen.mLevel.mSpawnablePrimatesCount == 0)
                {
                    mCounterMenu.mIsVisible = false;
                    DisableUnusedApeSelectorButtons();
                }
            });

            // Display the level text before the level starts
            if (mGameScreen.mLevel.mLevelStory != null)
            {
                mGameScreen.mCameraHandler.Lock();
                var textMenu = new UIv2.Menu(mGraphicsDevice, 5, 5, 90, 90);
                textMenu.WithBackground(UIv2.Menu.CreateTexture2D(deviceManager.GraphicsDevice, 50, 30, pixel => new Color(0.0f, 0.0f, 0.0f, 0.15f)), 5, 5, 90, 90);
                var heading = new UIv2.Components.Label(mGraphicsDevice, 5, 5, 90, 15, mGameScreen.mLevel.mLevelTitle, subHeaderFont, Color.DarkSlateGray);
                heading.FontType = FontManager.FontType.Subheading;
                heading.AddTo(textMenu);
                var textLabel = new UIv2.Components.Label(mGraphicsDevice, 25, 28, 50, 35, mGameScreen.mLevel.mLevelStory, font, Color.White);
                textLabel.DisableAutobreak();
                textLabel.AddTo(textMenu);
                mContinueLabel = new UIv2.Components.Label(mGraphicsDevice, 25, 80, 50, 10, "Press the left mouse button to continue", font, Color.White);
                mContinueLabel.AddTo(textMenu);
                var textButton = new UIv2.Components.Button(mGraphicsDevice, 0, 0, 100, 100, textureTransparent, "", font, Color.White);
                textButton.AddTo(textMenu);
                textButton.AddListener(MouseButtons.Left,
                                       InputState.Pressed,
                                       () =>
                {
                    menu.mIsVisible         = true;
                    mCounterMenu.mIsVisible = true;
                    textMenu.mIsVisible     = false;
                    mGameScreen.mCameraHandler.Unlock();
                });
                mMenuList.Add(textMenu);
                menu.mIsVisible         = false;
                mCounterMenu.mIsVisible = false;
            }

            mMenuList.Add(menu);
        }