Ejemplo n.º 1
0
        // Allows the game to perform any initialization it needs to before starting to run.
        // This is where it can query for any required services and load any non-graphic
        // related content.  Calling base.Initialize will enumerate through any components
        // and initialize them as well.
        protected override void Initialize()
        {
            Console.WriteLine("Begin Initialize");

            Console.WriteLine("Initializing Input");
            Keyboard.Initialize();
            Mouse.Initialize();
            GamePad.Initialize();

            game = new GameManager(launchParameters);

            base.Initialize();

            if (!isContentLoaded)
            {
                // BAD STUFF.
                Exit();
                return;
            }

            // Create and initialize the game.
            game.Initialize(this);

            Window.ClientSizeChanged += OnClientSizeChanged;

            Console.WriteLine("End Initialize");
        }
Ejemplo n.º 2
0
        //-----------------------------------------------------------------------------
        // Updating
        //-----------------------------------------------------------------------------

        // Called every step to update the game.
        public void Update(float timeDelta)
        {
            //prop.Update(1.0 / 60.0, new Point2I(ScreenSize.X - Property<int>.Width, ScreenSize.Y / 2));

            //if (Keyboard.IsKeyPressed(Keys.F4))
            //	GameBase.IsFullScreen = !GameBase.IsFullScreen;

            // Update the menu
            Controls.Update();

            // Toggle debug mode
            if (Keyboard.IsKeyPressed(Keys.F2) || (GamePad.IsButtonDown(Buttons.Back) && GamePad.IsButtonPressed(Buttons.RightStickButton)))
            {
                debugMode = !debugMode;
            }

            // Update the game-state stack.
            if (!isGamePaused)
            {
                gameStateStack.Update();
            }

            elapsedTicks++;

            // DEBUG: Update debug keys.
            GameDebug.GameControl = gameControl;
            GameDebug.UpdateRoomDebugKeys();
        }
Ejemplo n.º 3
0
        //=========== UPDATING ===========
        #region Updating

        /** <summary> Updates the debug menu while it's open. </summary> */
        public void Update()
        {
            if (Mouse.IsMouseMoved())
            {
                if (Mouse.GetDistance().Length > 2.0 && mouseHoverItem != null)
                {
                    controlMode = MenuControlMode.Mouse;
                }
            }

            if (Keyboard.IsKeyPressed(Keys.Left) ||
                Keyboard.IsKeyPressed(Keys.Right) ||
                Keyboard.IsKeyPressed(Keys.Up) ||
                Keyboard.IsKeyPressed(Keys.Down) ||
                Keyboard.IsKeyPressed(Keys.X) ||
                Keyboard.IsKeyPressed(Keys.Z) ||
                Keyboard.IsKeyPressed(Keys.Space) ||
                Keyboard.IsKeyPressed(Keys.Enter) ||
                Keyboard.IsKeyPressed(Keys.Escape))
            {
                controlMode = MenuControlMode.Keyboard;
            }
            else if (GamePad.IsButtonPressed(Buttons.DPadLeft) ||
                     GamePad.IsButtonPressed(Buttons.DPadRight) ||
                     GamePad.IsButtonPressed(Buttons.DPadUp) ||
                     GamePad.IsButtonPressed(Buttons.DPadDown) ||
                     GamePad.IsButtonPressed(Buttons.LeftStickLeft) ||
                     GamePad.IsButtonPressed(Buttons.LeftStickRight) ||
                     GamePad.IsButtonPressed(Buttons.LeftStickUp) ||
                     GamePad.IsButtonPressed(Buttons.LeftStickDown) ||
                     GamePad.IsButtonPressed(Buttons.A) ||
                     GamePad.IsButtonPressed(Buttons.B) ||
                     GamePad.IsButtonPressed(Buttons.Start) ||
                     GamePad.IsButtonPressed(Buttons.Back) ||
                     GamePad.IsButtonPressed(Buttons.Y))
            {
                controlMode = MenuControlMode.GamePad;
            }

            if (controlMode == MenuControlMode.Mouse)
            {
                UpdateMouseControls();
            }
            else if (controlMode == MenuControlMode.Keyboard)
            {
                UpdateKeyboardControls();
            }
            else
            {
                UpdateGamePadControls();
            }
        }
Ejemplo n.º 4
0
 public override bool Up()
 {
     return(GamePad.IsButtonUp(ButtonCode, Player));
 }
Ejemplo n.º 5
0
 public override bool Down()
 {
     return(GamePad.IsButtonDown(ButtonCode, Player));
 }
Ejemplo n.º 6
0
 public override bool Released()
 {
     return(GamePad.IsButtonReleased(ButtonCode, Player));
 }
Ejemplo n.º 7
0
 public override bool Pressed()
 {
     return(GamePad.IsButtonPressed(ButtonCode, Player));
 }
Ejemplo n.º 8
0
        //-----------------------------------------------------------------------------
        // Updating
        //-----------------------------------------------------------------------------

        // Allows the game to run logic such as updating the world,
        // checking for collisions, gathering input, and playing audio.
        protected override void Update(GameTime gameTime)
        {
            if (!isContentLoaded)
            {
                Exit();
                return;
            }

            // Update the fullscreen mode.
            UpdateFullScreen();

            if (windowSizeChanged)
            {
                game.ScreenResized();
                windowSizeChanged = false;
            }

            // Update the frame rate.
            UpdateFrameRate(gameTime);

            // Update the listeners.
            if (Form.Focused)
            {
                Keyboard.Enable();
                GamePad.Enable();
                Mouse.Enable();
                Keyboard.Update(gameTime);
                GamePad.Update(gameTime);
                Mouse.Update(gameTime, (IsFullScreen ? -new Vector2F(Window.ClientBounds.Location) : Vector2F.Zero));
            }
            else
            {
                Keyboard.Disable(false);
                GamePad.Disable(false);
                Mouse.Disable(false);
            }
            AudioSystem.Update(gameTime);

            // Update the game logic.
            //game.Update((float) gameTime.ElapsedGameTime.TotalSeconds);

            // DEBUG: Hold 1 to speed up the game.
            if (Keyboard.IsKeyDown(Keys.D1))
            {
                for (int i = 0; i < 16; i++)
                {
                    game.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
                }
            }
            // DEBUG: Hold 2 to slow down the game.
            else if (Keyboard.IsKeyDown(Keys.D2))
            {
                slowTimer++;
                if (slowTimer >= 10)
                {
                    slowTimer = 0;
                    game.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
                }
            }
            else
            {
                // Update the game logic.
                game.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
            }

            base.Update(gameTime);

            // Update screenshot requests.
            UpdateScreenShot();

            //windowSizeChanged = false;
        }
Ejemplo n.º 9
0
        /** <summary> Updates the debug menu with gamepad controls. </summary> */
        private void UpdateGamePadControls()
        {
            /*Keys keyNextItem = Keys.Down;
            *  Keys keyPrevItem = Keys.Up;
            *  Keys keyStepInto = Keys.Right;
            *  Keys keyStepOut  = Keys.Left;*/

            Buttons buttonNextItem  = Buttons.DPadDown;
            Buttons buttonNextItem2 = Buttons.LeftStickDown;
            Buttons buttonPrevItem  = Buttons.DPadUp;
            Buttons buttonPrevItem2 = Buttons.LeftStickUp;
            Buttons buttonStepInto  = Buttons.DPadRight;
            Buttons buttonStepInto2 = Buttons.LeftStickRight;
            Buttons buttonStepOut   = Buttons.DPadLeft;
            Buttons buttonStepOut2  = Buttons.LeftStickLeft;

            if (currentItem.Root.Root == null)
            {
                /*keyNextItem = Keys.Right;
                 * keyPrevItem = Keys.Left;
                 * keyStepInto = Keys.Down;
                 * keyStepOut  = Keys.Up;*/
                buttonNextItem  = Buttons.DPadRight;
                buttonNextItem2 = Buttons.LeftStickRight;
                buttonPrevItem  = Buttons.DPadLeft;
                buttonPrevItem2 = Buttons.LeftStickLeft;
                buttonStepInto  = Buttons.DPadDown;
                buttonStepInto2 = Buttons.LeftStickDown;
                buttonStepOut   = Buttons.DPadUp;
                buttonStepOut2  = Buttons.LeftStickUp;
            }

            // Select next root menu item.
            if ((GamePad.IsButtonPressed(Buttons.DPadRight) || GamePad.IsButtonPressed(Buttons.LeftStickRight)) && currentItem.Items.Count == 0 && CurrentMenu != menu)
            {
                int index = currentPath[0];
                currentItem = menu.Items[index];
                currentPath.Clear();
                currentPath.Add(index);
                SelectNextItem();
                StepIntoSubMenu();
            }

            // Step into a sub-menu.
            else if (GamePad.IsButtonPressed(buttonStepInto) || GamePad.IsButtonPressed(buttonStepInto2))
            {
                StepIntoSubMenu();
            }

            // Select previous root menu item.
            if ((GamePad.IsButtonPressed(Buttons.DPadLeft) || GamePad.IsButtonPressed(Buttons.LeftStickLeft)) && CurrentMenu.Root == menu)
            {
                currentItem = CurrentMenu;
                currentPath.RemoveAt(currentPath.Count - 1);
                SelectPreviousItem();
                StepIntoSubMenu();
            }
            // Step out of a sub-menu.
            else if (GamePad.IsButtonPressed(buttonStepOut) || GamePad.IsButtonPressed(buttonStepOut2))
            {
                StepOutOfSubMenu();
            }

            // Select next item.
            if (GamePad.IsButtonPressed(buttonNextItem) || GamePad.IsButtonPressed(buttonNextItem2))
            {
                SelectNextItem();
            }

            // Select previous item.
            if (GamePad.IsButtonPressed(buttonPrevItem) || GamePad.IsButtonPressed(buttonPrevItem2))
            {
                SelectPreviousItem();
            }

            // Step out of a sub-menu.
            if (GamePad.IsButtonPressed(Buttons.B) || GamePad.IsButtonPressed(Buttons.Back))
            {
                StepOutOfSubMenu();
            }

            // Press item.
            if (GamePad.IsButtonPressed(Buttons.A) || GamePad.IsButtonPressed(Buttons.Start) || GamePad.IsButtonPressed(Buttons.Y))
            {
                if (currentItem.Items.Count == 0)
                {
                    currentItem.Press();
                    if (!GamePad.IsButtonPressed(Buttons.Y))
                    {
                        Close();
                    }
                }
                else
                {
                    StepIntoSubMenu();
                }
            }
        }