Exemplo n.º 1
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // Get ControlManager from services
            _controlManager = (ControlManager)Game.Services.GetService(typeof(ControlManager));

            // Add new control (title)
            Control title = new Control("Lost Gold", Control.TextSizeOptions.Large);
            title.offsetY = -150;
            _controlManager.Add(title);

            // Add new control (byline)
            Control byLine = new Control("by Lars Boldt", Control.TextSizeOptions.Small);
            byLine.offsetY = -120;
            _controlManager.Add(byLine);

            // Add new selectablecontrol (Start game)
            SelectableControl newGameLbl = new SelectableControl("Start new game", Control.TextSizeOptions.Medium);
            newGameLbl.OnSelect += new EventHandler(newGameLbl_onSelect);
            _controlManager.Add(newGameLbl);

            // Add new selectablecontrol (exit game)
            SelectableControl exitLbl = new SelectableControl("Exit", Control.TextSizeOptions.Medium);
            exitLbl.offsetY = 30;
            exitLbl.OnSelect += new EventHandler(exitLbl_onSelect);
            _controlManager.Add(exitLbl);

            base.Initialize();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Game over, you ran out of time
            if (engine.Enabled && engine.timeLeft <= 0)
            {
                Control loseText = new Control("You are out of time!", Control.TextSizeOptions.Large);
                loseText.Color = Color.Red;
                controlManager.Add(loseText);

                SelectableControl continueLbl = new SelectableControl("Press \"Enter\" or GamePad \"A\" to return to menu", Control.TextSizeOptions.Medium);
                continueLbl.offsetY = 50;
                continueLbl.OnSelect += new EventHandler(continueLbl_onSelect);
                controlManager.Add(continueLbl);

                engine.Enabled = false;
            }

            // Game won, you found the gold area
            if (engine.WinArea.Intersects(engine.Character.Rectangle()) && engine.Enabled)
            {
                Control winText = new Control("You found the gold!", Control.TextSizeOptions.Large);
                winText.Color = Color.Gold;
                controlManager.Add(winText);

                SelectableControl continueLbl = new SelectableControl("Press \"Enter\" or GamePad \"A\" to return to menu", Control.TextSizeOptions.Medium);
                continueLbl.offsetY = 50;
                continueLbl.OnSelect +=new EventHandler(continueLbl_onSelect);
                controlManager.Add(continueLbl);

                engine.Enabled = false;
            }

            // Game pause
            if (InputManager.KeyReleased(Keys.P) || InputManager.ButtonPressed(Buttons.Back, 0))
            {
                // If game is running, pause it
                if (engine.Enabled)
                {
                    engine.Enabled = false;
                    controlManager.Add(new Control("Game paused", Control.TextSizeOptions.Large));
                    Control helpTxt = new Control("Press \"P\" or GamePad \"Back\" to unpause", Control.TextSizeOptions.Small);
                    helpTxt.offsetY = 50;
                    controlManager.Add(helpTxt);
                }
                // Game is paused, start it
                else
                {
                    engine.Enabled = true;
                    controlManager.Clear();
                }
            }

            // Bring up Resume/exit menu during gameplay
            if ((InputManager.KeyReleased(Keys.Escape) || InputManager.ButtonPressed(Buttons.Start, 0)) && engine.Enabled)
            {
                engine.Enabled = false;

                Control menuTxt = new Control("Game menu", Control.TextSizeOptions.Large);
                menuTxt.offsetY = -40;
                controlManager.Add(menuTxt);

                SelectableControl resume = new SelectableControl("Resume", Control.TextSizeOptions.Medium);
                resume.OnSelect += new EventHandler(resume_OnSelect);
                controlManager.Add(resume);

                SelectableControl exit = new SelectableControl("Exit", Control.TextSizeOptions.Medium);
                exit.offsetY = 20;
                exit.OnSelect += new EventHandler(continueLbl_onSelect);
                controlManager.Add(exit);
            }

            base.Update(gameTime);
        }