Example #1
0
        public PauseMenu(MinerGame game, MenuScene previous)
            : base(game, previous)
        {
            int start = -400;
            int pos = start;
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 + pos, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), RESUME, (menu) =>
                    {
                        this.GoBack();
                    }));
            pos += MENU_ITEM_HEIGHT + GAP;
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 + pos, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), SAVE_GAME, (menu) =>
                    {
                        using (FileStream fs = new FileStream("save1.xml", FileMode.Create))
                        {
                            XmlSerializer xml = new XmlSerializer(typeof(GameState));
                            xml.Serialize(fs, this.Game.GameState);
                        }
                    }));
            pos += MENU_ITEM_HEIGHT + GAP;
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 + pos, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), LOAD_GAME, (menu) =>
                    {
                        System.Windows.Forms.OpenFileDialog openFile = new System.Windows.Forms.OpenFileDialog();

                        if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            try
                            {
                                this.Game.Content.Unload();

                                using (Stream stream = openFile.OpenFile())
                                {
                                    XmlSerializer xml = new XmlSerializer(typeof(GameState));
                                    this.Game.GameState = (GameState)xml.Deserialize(stream);
                                    this.Game.GameState.Miner.Suit = new Nanosuit();
                                    stream.Close();
                                }

                                this.Game.GameState.Miner.game = this.Game;

                                foreach (var item in this.Game.GameState.Enemies)
                                {
                                    item.game = this.Game;
                                }

                                foreach (var item in this.Game.GameState.Bullets)
                                {
                                    item.game = this.Game;
                                }

                                this.Game.Content.Load<SpriteFont>("general");
                                this.Game.Content.Load<Texture2D>(Kosmojopek.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Ufolowca.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(WladcaLaserowejDzidy.ASSET_NAME);
                                //this.Content.Load<Texture2D>(PoteznySultan.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Miner.ASSET_NAME);
                                //this.Content.Load<Texture2D>(CosmicMatter.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(DoubleJump.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Field.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Fuel.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Indestructibility.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Key.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(KeyLocalizer.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Laser.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(MoreEnemies.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(SolidRock.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(SpaceGate.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(TitanRock.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Bullet.ASSET_NAME);

                                this.Game.GameState.Miner.LoadContent();

                                foreach (var item in this.Game.GameState.Enemies)
                                {
                                    item.LoadContent();
                                }

                                foreach (var item in this.Game.GameState.Bullets)
                                {
                                    item.LoadContent();
                                }

                                foreach (var item in this.Game.GameState.Map.Fields)
                                {
                                    foreach (var field in item)
                                    {
                                        field.game = this.Game;
                                        field.LoadContent();
                                    }
                                }

                                GameScene newScene = new GameScene(this.Game)
                                {
                                    OldKeyState = this.CurrentKeyState
                                };
                                MenuManager.GetInstance().CurrentMenu = newScene;
                            }
                            catch (Exception exc)
                            {
                                System.Windows.Forms.MessageBox.Show(ERROR_READING_FILE + exc.Message);
                            }
                        }
                    }));
            pos += MENU_ITEM_HEIGHT + GAP;
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 + pos, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), INSTRUCTIONS, (menu) =>
                    {

                    }));
            pos += MENU_ITEM_HEIGHT + GAP;
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 + pos, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), SETTINGS, (menu) =>
                    {
                        SettingsMenu newMenu = new SettingsMenu(this.Game, this)
                        {
                            OldKeyState = this.CurrentKeyState
                        };
                        MenuManager.GetInstance().CurrentMenu = newMenu;
                    }));
            pos += MENU_ITEM_HEIGHT + GAP;
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 + pos, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), EXIT_MAIN_MENU, (menu) =>
                    {
                        MainMenu newMenu = new MainMenu(this.Game)
                        {
                            OldKeyState = this.CurrentKeyState
                        };
                        MenuManager.GetInstance().CurrentMenu = newMenu;
                    }));
            pos += MENU_ITEM_HEIGHT + GAP;
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 + pos, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), EXIT_GAME, (menu) =>
                    {
                        menu.Game.ExitGame();
                    }));
            MenuItems[currentlySelected].Selected = true;
        }
Example #2
0
        /// <summary>
        /// Metoda odpowiadająca za uaktualnienie stanu związanego z obiektem.
        /// </summary>
        /// <param name="gameTime">Czas, jaki upłynął od ostatniego wywołania tej metody.</param>
        public override void Update(GameTime gameTime)
        {
            KeyboardState keyState = Keyboard.GetState();
            if (keyState.GetPressedKeys().Length == 0)
            {
                OldKeyState = keyState;
                return;
            }
            Keys pressedKey = Keyboard.GetState().GetPressedKeys()[0];
            if (IsKeyAChar(pressedKey) && !OldKeyState.IsKeyDown(pressedKey))
            {
                PlayerName += pressedKey.ToString();
            }

            if (pressedKey == Keys.Enter)
            {
                this.Game.GameState.User = new User
                {
                    Name = PlayerName,
                    Score = 0
                };

                MainMenu newMenu = new MainMenu(this.Game)
                {
                    OldKeyState = keyState
                };
                MenuManager.GetInstance().CurrentMenu = newMenu;
            }

            OldKeyState = keyState;
        }