Пример #1
0
        public void LoadContent(GraphicsDeviceManager deviceManager, ContentManager contentManager, int windowWidth, int windowHeight)
        {
            mScreenWidth  = windowWidth;
            mScreenHeight = windowHeight;

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

            Device       = deviceManager.GraphicsDevice;
            mSpriteBatch = new SpriteBatch(deviceManager.GraphicsDevice);

            mOptionsScreen = new OptionsMenu(true);

            // Unlock the framerate. Later we want to remove this piece of code
            mGraphicsDevice = deviceManager.GraphicsDevice;
            mSpriteBatch    = new SpriteBatch(deviceManager.GraphicsDevice);

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

            IsVisible = true;

            // Load background image
            mBackgroundImageOptions = contentManager.Load <Texture2D>("forest");

            mMenuList = new List <UIv2.Menu>();

            var menu = new UIv2.Menu(mGraphicsDevice, 5, 5, 90, 90);

            menu.WithBackground(UIv2.Menu.CreateTexture2D(deviceManager.GraphicsDevice, 50, 30, pixel => new Color(0.0f, 0.0f, 0.0f, 0.2f)), 5, 5, 90, 90);
            mMenuList.Add(menu);

            Texture2D texture2D            = UIv2.Menu.CreateTexture2D(mGraphicsDevice, 200, 30, pixel => Color.Black);
            Texture2D texture2DSliderPoint = UIv2.Menu.CreateTexture2D(mGraphicsDevice, 200, 30, pixel => Color.White);

            var heading = new UIv2.Components.Label(mGraphicsDevice, 35, 5, 30, 15, "Pause", subHeaderFont, Color.White);

            heading.FontType = FontManager.FontType.Subheading;
            heading.AddTo(menu);

            // Create new Resume Button

            var resumeButton = new UIv2.Components.Button(mGraphicsDevice, 40, 20, 20, 7, texture2D, "Resume", font, Color.White);

            resumeButton.AddTo(menu);
            resumeButton.AddListener(MouseButtons.Left, InputState.Pressed, () =>
            {
                SoundManager.AddSound(mClickSound);
                mHudScreen.IsVisible = true;
                ScreenManager.Remove(this);
                IsVisible = false;
            });

            // Create new Save Button
            var saveButton = new UIv2.Components.Button(mGraphicsDevice, 40, 30, 20, 7, texture2D, "Save Game", font, Color.White);

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

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

                Console.WriteLine("########################################################");
                Console.WriteLine("Saving Camera to " + GetSavedGamesPath() + "\\Camera.xml");
                Console.WriteLine("########################################################");


                using (Stream stream = new FileStream(GetSavedGamesPath() + "\\Camera.xml", FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    serializer.Serialize(stream, mHudScreen.mGameScreen.mCamera);
                    stream.Close();
                }

                serializer = new XmlSerializer(typeof(Level));

                Console.WriteLine("########################################################");
                Console.WriteLine("Saving Level to " + GetSavedGamesPath() + "\\Level.xml");
                Console.WriteLine("########################################################");



                using (Stream stream = new FileStream(GetSavedGamesPath() + "\\Level.xml", FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    serializer.Serialize(stream, mHudScreen.mGameScreen.mLevel);
                    stream.Close();
                }

                serializer = new XmlSerializer(typeof(HudScreen));

                Console.WriteLine("########################################################");
                Console.WriteLine("Saving Level to " + GetSavedGamesPath() + "\\HudScreen.xml");
                Console.WriteLine("########################################################");



                using (Stream stream = new FileStream(GetSavedGamesPath() + "\\HudScreen.xml", FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    serializer.Serialize(stream, mHudScreen);
                    stream.Close();
                }

                serializer = new XmlSerializer(typeof(Silverback));

                Console.WriteLine("########################################################");
                Console.WriteLine("Saving Level to " + GetSavedGamesPath() + "\\Silverback.xml");
                Console.WriteLine("########################################################");

                using (Stream stream = new FileStream(GetSavedGamesPath() + "\\Silverback.xml", FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    serializer.Serialize(stream, mHudScreen.mGameScreen.mLevel.mSilverback);
                    stream.Close();
                }


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

                Console.WriteLine("########################################################");
                Console.WriteLine("Saving Level to " + GetSavedGamesPath() + "\\CapuchinPositions.xml");
                Console.WriteLine("########################################################");

                using (Stream stream = new FileStream(GetSavedGamesPath() + "\\CapuchinPositions.xml", FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    var toSerialize = new List <Matrix>();
                    mHudScreen.mGameScreen.mLevel.mCapuchinBatch.mActors.ForEach(actor => toSerialize.Add(actor.mModelMatrix));
                    serializer.Serialize(stream, toSerialize);
                    stream.Close();
                }

                Console.WriteLine("########################################################");
                Console.WriteLine("Saving Level to " + GetSavedGamesPath() + "\\GibbonPositions.xml");
                Console.WriteLine("########################################################");

                using (Stream stream = new FileStream(GetSavedGamesPath() + "\\GibbonPositions.xml", FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    var toSerialize = new List <Matrix>();
                    mHudScreen.mGameScreen.mLevel.mGibbonBatch.mActors.ForEach(actor => toSerialize.Add(actor.mModelMatrix));
                    serializer.Serialize(stream, toSerialize);
                    stream.Close();
                }

                Console.WriteLine("########################################################");
                Console.WriteLine("Saving Level to " + GetSavedGamesPath() + "\\OrangPositions.xml");
                Console.WriteLine("########################################################");

                using (Stream stream = new FileStream(GetSavedGamesPath() + "\\OrangPositions.xml", FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    var toSerialize = new List <Matrix>();
                    mHudScreen.mGameScreen.mLevel.mOrangutanBatch.mActors.ForEach(actor => toSerialize.Add(actor.mModelMatrix));
                    serializer.Serialize(stream, toSerialize);
                    stream.Close();
                }

                Console.WriteLine("########################################################");
                Console.WriteLine("Saving Level to " + GetSavedGamesPath() + "\\ChimpPositions.xml");
                Console.WriteLine("########################################################");

                using (Stream stream = new FileStream(GetSavedGamesPath() + "\\ChimpPositions.xml", FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    var toSerialize = new List <Matrix>();
                    mHudScreen.mGameScreen.mLevel.mChimpanezzeBatch.mActors.ForEach(actor => toSerialize.Add(actor.mModelMatrix));
                    serializer.Serialize(stream, toSerialize);
                    stream.Close();
                }

                Console.WriteLine("########################################################");
                Console.WriteLine("Saving Level to " + GetSavedGamesPath() + "\\Huts.xml");
                Console.WriteLine("########################################################");

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

                using (Stream stream = new FileStream(GetSavedGamesPath() + "\\Huts.xml", FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    var toSerialize   = new List <Hut>();
                    var hutActorBatch = mHudScreen.mGameScreen.mLevel.mActorBatches.Find(ele =>
                                                                                         ele.mMesh == mHudScreen.mGameScreen.mLevel.mHutMesh);
                    mHudScreen.mGameScreen.mLevel.mHuts.ForEach(hut => toSerialize.Add(hut));
                    serializer.Serialize(stream, toSerialize);
                    stream.Close();
                }
            });

            // Error label | Savegame
            var errLabel = new UIv2.Components.Label(mGraphicsDevice, 10, 90, 80, 4, "Could not load the savegame", font, Color.White);

            errLabel.FontType = FontManager.FontType.Default;
            errLabel.SetVisibility(false);
            errLabel.AddTo(menu);

            // Create new Load Game Button
            var loadButton = new UIv2.Components.Button(mGraphicsDevice, 40, 40, 20, 7, texture2D, "Load Checkpoint", font, Color.White);

            loadButton.AddTo(menu);
            loadButton.AddListener(MouseButtons.Left, InputState.Pressed, () =>
            {
                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"))
                {
                    errLabel.SetVisibility(true);
                    return;
                }
                errLabel.SetVisibility(false);
                ScreenManager.Remove(this);
                ScreenManager.Remove(mHudScreen.mGameScreen);
                ScreenManager.Remove(mHudScreen);

                var loadingScreen = new LoadingScreen(mHudScreen.mLevelPath);
                loadingScreen.LoadSaveGame();
                ScreenManager.Add(loadingScreen);
            });

            // Create new Options Button
            var optionsButton = new UIv2.Components.Button(mGraphicsDevice, 40, 50, 20, 7, texture2D, "Options", font, Color.White);

            optionsButton.AddTo(menu);
            optionsButton.AddListener(MouseButtons.Left, InputState.Pressed, () =>
            {
                SoundManager.AddSound(mClickSound);
                ScreenManager.Add(mOptionsScreen);
                IsVisible = false;
            });

            // Create new Back Button
            var backButton = new UIv2.Components.Button(mGraphicsDevice, 40, 60, 20, 7, texture2D, "Main Menu", font, Color.White);

            backButton.AddTo(menu);
            backButton.AddListener(MouseButtons.Left, InputState.Pressed, () =>
            {
                SoundManager.AddSound(mClickSound);
                ScreenManager.Remove(mHudScreen);
                ScreenManager.Remove(this);
                IsVisible = false;
            });
        }
Пример #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");
            mMainMenuMusic = contentManager.Load <SoundEffect>("Audio/slowmo");

            SoundManager.AddMusic(mMainMenuMusic);

            // We should remove this for a more stable framerate later
            deviceManager.SynchronizeWithVerticalRetrace = false;
            deviceManager.ApplyChanges();

            mMenuList = new List <UIv2.Menu>();

            IsVisible = true;

            mGraphicsDevice = deviceManager.GraphicsDevice;

            mSpriteBatch = new SpriteBatch(deviceManager.GraphicsDevice);

            // Load font
            var font          = contentManager.Load <SpriteFont>("Font");
            var headerFont    = contentManager.Load <SpriteFont>("Heading");
            var buttonTexture = contentManager.Load <Texture2D>("button");

            IsVisible = true;

            // Load background image
            mBackgroundImage = contentManager.Load <Texture2D>("Forest");

            IsVisible = true;

            mOptionsScreen      = new OptionsMenu(false);
            mStatisticsScreen   = new StatisticsScreen();
            mCreditsScreen      = new CreditsScreen();
            mEditorHudScreen    = new EditorHudScreen();
            mAchievementsScreen = new AchievementsScreen();
            mScreamScreen       = new ScreamScreen();

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

            mMenuList.Add(menu);

            var texture2D = UIv2.Menu.CreateTexture2D(mGraphicsDevice, 200, 30, pixel => Color.Black);

            var heading = new UIv2.Components.Label(mGraphicsDevice, 10, 0, 80, 30, "Silverback", headerFont, Color.DarkSlateGray);

            heading.FontType = FontManager.FontType.Heading;
            heading.AddTo(menu);

            var newGameButton = new UIv2.Components.Button(mGraphicsDevice, 35, 24, 30, 7, texture2D, "New Game", font, Color.White);

            newGameButton.AddTo(menu);
            newGameButton.AddListener(MouseButtons.Left, InputState.Pressed, () =>
            {
                SoundManager.AddSound(mClickSound);
                Statistic.CurrentSaveTime = 0;
                var loadingScreen         = new LoadingScreen("..\\..\\..\\..\\Content\\tutorial.lvl");
                ScreenManager.Add(loadingScreen);
                IsVisible = false;
            });

            var loadGameButton = new UIv2.Components.Button(mGraphicsDevice, 35, 32, 30, 7, texture2D, "Load Game", font, Color.White);

            loadGameButton.AddTo(menu);
            // Add an event listener to the button
            loadGameButton.AddListener(MouseButtons.Left, InputState.Pressed, () =>
            {
                SoundManager.AddSound(mClickSound);

                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;
                }

                // Get the level file

                using (var fs = File.OpenRead(PauseScreen.GetSavedGamesPath() + "\\HudScreen.xml"))
                {
                    var serializer      = new XmlSerializer(typeof(HudScreen));
                    HudScreen hudScreen = null;
                    try
                    {
                        hudScreen = (HudScreen)serializer.Deserialize(fs);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.GetBaseException());
                    }

                    if (hudScreen != null)
                    {
                        var loadingScreen = new LoadingScreen(hudScreen.mLevelPath);
                        loadingScreen.LoadSaveGame();
                        ScreenManager.Add(loadingScreen);
                    }

                    IsVisible = false;
                }
            });

            // Create Statistic button
            var statisticsButton = new UIv2.Components.Button(mGraphicsDevice, 35, 40, 30, 7, texture2D, "Statistics", font, Color.White);

            statisticsButton.AddTo(menu);
            // Add an event listener to the button
            statisticsButton.AddListener(MouseButtons.Left, InputState.Pressed, () =>
            {
                SoundManager.AddSound(mClickSound);
                ScreenManager.Add(mStatisticsScreen);
                IsVisible = false;
            });

            // Create Achievements button
            var achievementsButton = new UIv2.Components.Button(mGraphicsDevice, 35, 48, 30, 7, texture2D, "Achievements", font, Color.White);

            achievementsButton.AddTo(menu);
            // Add an event listener to the button
            achievementsButton.AddListener(MouseButtons.Left, InputState.Pressed, () =>
            {
                SoundManager.AddSound(mClickSound);
                ScreenManager.Add(mAchievementsScreen);
                IsVisible = false;
            });

            // Create Credits button
            var creditsButton = new UIv2.Components.Button(mGraphicsDevice, 35, 56, 30, 7, texture2D, "Credits", font, Color.White);

            creditsButton.AddTo(menu);
            // Add an event listener to the button
            creditsButton.AddListener(MouseButtons.Left, InputState.Pressed, () =>
            {
                SoundManager.AddSound(mClickSound);
                // ScreenManager.Add(mScreamScreen);
                ScreenManager.Add(mCreditsScreen);
                IsVisible = false;
            });

            // Create Option button
            var optionsButton = new UIv2.Components.Button(mGraphicsDevice, 35, 64, 30, 7, texture2D, "Options", font, Color.White);

            optionsButton.AddTo(menu);
            // Add an event listener to the button
            optionsButton.AddListener(MouseButtons.Left, InputState.Pressed, () =>
            {
                SoundManager.AddSound(mClickSound);
                ScreenManager.Add(mOptionsScreen);
                IsVisible = false;
            });

            var editorButton = new UIv2.Components.Button(mGraphicsDevice, 35, 72, 30, 7, texture2D, "Editor", font, Color.White);

            editorButton.AddTo(menu);
            editorButton.AddListener(MouseButtons.Left, InputState.Pressed, () =>
            {
                SoundManager.AddSound(mClickSound);
                ScreenManager.Add(mEditorHudScreen);
                IsVisible = false;
            });

            var exitButton = new UIv2.Components.Button(mGraphicsDevice, 35, 80, 30, 7, texture2D, "Exit", font, Color.White);

            exitButton.AddTo(menu);
            exitButton.AddListener(MouseButtons.Left, InputState.Pressed, () =>
            {
                SoundManager.AddSound(mClickSound);
                ScreenManager.Remove(this);
            });
        }
Пример #3
0
        public void LoadContent(GraphicsDeviceManager deviceManager, ContentManager contentManager, int windowWidth, int windowHeight)
        {
            mScreenWidth  = windowWidth;
            mScreenHeight = windowHeight;

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

            Device       = deviceManager.GraphicsDevice;
            mSpriteBatch = new SpriteBatch(deviceManager.GraphicsDevice);

            // Unlock the framerate. Later we want to remove this piece of code
            mGraphicsDevice = deviceManager.GraphicsDevice;
            mSpriteBatch    = new SpriteBatch(deviceManager.GraphicsDevice);

            // Load font
            var font       = contentManager.Load <SpriteFont>("Font");
            var headerFont = contentManager.Load <SpriteFont>("Heading");

            IsVisible = true;

            // Load background image
            mBackgroundImage = contentManager.Load <Texture2D>("Forest");

            mMenuList = new List <UIv2.Menu>();
            var menu = new UIv2.Menu(mGraphicsDevice, 5, 5, 90, 90);

            menu.WithBackground(UIv2.Menu.CreateTexture2D(deviceManager.GraphicsDevice, 50, 30, pixel => new Color(0.0f, 0.0f, 0.0f, 0.2f)), 5, 5, 90, 90);
            mMenuList.Add(menu);

            Texture2D texture2D            = UIv2.Menu.CreateTexture2D(mGraphicsDevice, 200, 30, pixel => Color.Black);
            Texture2D texture2DSliderPoint = UIv2.Menu.CreateTexture2D(mGraphicsDevice, 200, 30, pixel => Color.White);

            // Congratulations!
            var congratz = new UIv2.Components.Label(mGraphicsDevice, 10, 0, 80, 30, "Congratulations!", headerFont, Color.DarkSlateGray);

            congratz.FontType = FontManager.FontType.Heading;
            congratz.AddTo(menu);

            // You've won
            var win = new UIv2.Components.Label(mGraphicsDevice, 10, 30, 80, 30, "You've won", headerFont, Color.DarkSlateGray);

            win.FontType = FontManager.FontType.Heading;
            win.AddTo(menu);

            var winString = "Nice work dude!";
            var winLabel  = new UIv2.Components.Label(mGraphicsDevice, 20, 60, 60, 10, winString, font, Color.White);

            winLabel.AddTo(menu);

            if (mHudScreen.mGameScreen.mLevel.mNextLevelFilename != "null")
            {
                var nextLevelButton = new UIv2.Components.Button(mGraphicsDevice, 40, 70, 20, 7, texture2D, "Next level", font, Color.White);
                nextLevelButton.AddTo(menu);
                nextLevelButton.AddListener(MouseButtons.Left, InputState.Pressed, () =>
                {
                    var nextLevelFilename = mHudScreen.mGameScreen.mLevel.mNextLevelFilename;
                    // Check if path is relative
                    if (!Path.IsPathRooted(nextLevelFilename))
                    {
                        var levelFilename = mHudScreen.mGameScreen.mLevel.mLevelFilename;
                        var directoryPath = Path.GetDirectoryName(levelFilename);
                        nextLevelFilename = directoryPath + "/" + nextLevelFilename;
                    }
                    SoundManager.AddSound(mClickSound);
                    ScreenManager.Remove(this);
                    IsVisible         = false;
                    var loadingScreen = new LoadingScreen(nextLevelFilename);
                    ScreenManager.Add(loadingScreen);
                });
            }
            else
            {
                winLabel.Text += " You've finished the game.";
                if (Statistic.CurrentSaveTime < Statistic.MinimalTime || Statistic.MinimalTime == 0)
                {
                    Statistic.MinimalTime   = Statistic.CurrentSaveTime;
                    Achievements.Gamemaster = true;
                    if (Statistic.MinimalTime < 3600000)
                    {
                        Achievements.Speedrunner = true;
                    }
                }
            }

            // Create Main Menu Button (Back Button)
            var backButton = new UIv2.Components.Button(mGraphicsDevice, 40, 80, 20, 7, texture2D, "Main menu", font, Color.White);

            backButton.AddTo(menu);
            backButton.AddListener(MouseButtons.Left, InputState.Pressed, () =>
            {
                SoundManager.AddSound(mClickSound);
                ScreenManager.Remove(this);
                IsVisible = false;
            });
        }