Ejemplo n.º 1
0
        /// <summary>
        /// Used for determining if a keyType was just released.
        /// </summary>
        /// <param name="key">Key to check if released.</param>
        /// <returns>Returns true if keyType is up and last frame is down.</returns>
        public static bool KeyJustReleased(Keys key)
        {
            if (_active && OldKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        public override void Update(GameTime gameTime)
        {
            NewKeyboardState = Keyboard.GetState();
            // update stuff here


            if (OldKeyboardState.IsKeyUp(Keys.Escape) && NewKeyboardState.IsKeyDown(Keys.Escape))
            {
                Screens.Pop();
                Screens.Peek().OldKeyboardState = this.NewKeyboardState;
            }
            OldKeyboardState = NewKeyboardState;
        }
Ejemplo n.º 3
0
 public override void Update(GameTime gameTime)
 {
     NewKeyboardState = Keyboard.GetState();
     if (OldKeyboardState.IsKeyUp(Keys.Enter) && NewKeyboardState.IsKeyDown(Keys.Enter))
     {
         // pop everything until main menu
         while (Screens.Count > 1)
         {
             Screens.Pop();
         }
     }
     OldKeyboardState = NewKeyboardState;
     Screens.Peek().OldKeyboardState = NewKeyboardState;
 }
Ejemplo n.º 4
0
        public override void Update(GameTime gameTime)
        {
            NewKeyboardState = Keyboard.GetState();
            MouseState mouseState = Mouse.GetState();


            if (startButton.ClickedWithinBounds(mouseState))
            {
                OldKeyboardState = NewKeyboardState;
                InGameState gs = new InGameState(graphicsDevice, Content, ref Screens);
                Screens.Push(gs);
            }
            else if (howToPlayButton.ClickedWithinBounds(mouseState))
            {
                OldKeyboardState = NewKeyboardState;
                HowToPlayState hs = new HowToPlayState(graphicsDevice, Content, ref Screens);
                Screens.Push(hs);
            }
            else if (optionsButton.ClickedWithinBounds(mouseState))
            {
                // switch to options screen
            }
            else if (quitButton.ClickedWithinBounds(mouseState))
            {
                Screens.Pop();
            }

            if (OldKeyboardState.IsKeyUp(Keys.Escape) && NewKeyboardState.IsKeyDown(Keys.Escape))
            {
                Screens.Pop();
            }

            if (OldKeyboardState.IsKeyUp(Keys.Enter) && NewKeyboardState.IsKeyDown(Keys.Enter))
            {
                OldKeyboardState = NewKeyboardState;
                InGameState gs = new InGameState(graphicsDevice, Content, ref Screens);
                Screens.Push(gs);
            }
            OldKeyboardState = NewKeyboardState;
        }
Ejemplo n.º 5
0
        public void Update(GameTime gameTime)
        {
            KeyboardState ks = Keyboard.GetState();

            if (ks.IsKeyDown(Keys.Up) && !OldKeyboardState.Equals(ks))
            {
                Selection--;
                if (Selection < 0)
                {
                    Selection = 0;
                }
            }
            if (ks.IsKeyDown(Keys.Down) && !OldKeyboardState.Equals(ks))
            {
                Selection++;
                if (Selection > MenuItems.Count - 1)
                {
                    Selection = MenuItems.Count - 1;
                }
            }

            if (ks.IsKeyDown(Keys.Enter) && !OldKeyboardState.Equals(ks))
            {
                switch (Selection)
                {
                case 0:
                    IsActive = false;
                    break;

                case 1:
                    break;     // show controls in draw section...

                case 2:
                    Game1.landscape.Exit();
                    break;
                }
            }
            OldKeyboardState = ks;
        }
Ejemplo n.º 6
0
 public static bool KeyDown(Keys key)
 {
     return(NewKeyboardState.IsKeyDown(key) &&
            !OldKeyboardState.IsKeyDown(key));
 }
Ejemplo n.º 7
0
 public static bool WasJustPressed(Keys key)
 {
     return(OldKeyboardState.IsKeyUp(key) && CurrentKeyboardState.IsKeyDown(key));
 }
Ejemplo n.º 8
0
        public override void Update()
        {
            StateKey         = Keyboard.GetState();
            OldKeyboardState = Keyboard.GetState();

            if (StateKey.IsKeyDown(Keys.Up))
            {
                Up = true;
                Console.WriteLine("Naar bove");
            }
            if (StateKey.IsKeyUp(Keys.Up))
            {
                Up = false;
            }
            if (StateKey.IsKeyDown(Keys.Down))
            {
                Console.WriteLine("Naar benede");
                Down = true;
            }
            if (StateKey.IsKeyUp(Keys.Down))
            {
                Down = false;
            }
            if (OldKeyboardState.IsKeyDown(Keys.Up))
            {
                Up = true;
                Console.WriteLine("Naar bove");
            }
            if (OldKeyboardState.IsKeyUp(Keys.Up))
            {
                Up = false;
            }
            if (OldKeyboardState.IsKeyDown(Keys.Down))
            {
                Console.WriteLine("Naar benede");
                Down = true;
            }
            if (OldKeyboardState.IsKeyUp(Keys.Down))
            {
                Down = false;
            }

            if (StateKey.IsKeyDown(Keys.Left))
            {
                Left = true;
            }
            if (StateKey.IsKeyUp(Keys.Left))
            {
                Left = false;
            }

            if (StateKey.IsKeyDown(Keys.Right))
            {
                Right = true;
            }
            if (StateKey.IsKeyUp(Keys.Right))
            {
                Right = false;
            }

            if (StateKey.IsKeyDown(Keys.Enter))
            {
                Enter = true;
            }
            if (StateKey.IsKeyUp(Keys.Enter))
            {
                Enter = false;
            }

            if (StateKey.IsKeyDown(Keys.Space))
            {
                Space = true;
            }
            if (StateKey.IsKeyUp(Keys.Space))
            {
                Space = false;
            }
        }
Ejemplo n.º 9
0
 public static bool IsKeyPressed(Keys k) => CurrentKeyboardState.IsKeyDown(k) && !OldKeyboardState.IsKeyDown(k);
Ejemplo n.º 10
0
        void ProcessKeyboardInput(GameTime gameTime, EnvironmentBlock[] walls)
        {
            // select standing animation based off last walk animation
            if (currentAnimation == walkLeft)
            {
                currentAnimation = standLeft;
            }
            else if (currentAnimation == walkRight)
            {
                currentAnimation = standRight;
            }
            else if (currentAnimation == walkUp)
            {
                currentAnimation = standUp;
            }
            else if (currentAnimation == walkDown)
            {
                currentAnimation = standDown;
            }

            // change character position and animation based on key press
            if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                currentAnimation = walkDown;
                currentAnimation.Update(gameTime);

                desiredDestinationPosition.Y += charSpeed * ticksSinceLastUpdate;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                currentAnimation = walkUp;
                currentAnimation.Update(gameTime);

                desiredDestinationPosition.Y -= charSpeed * ticksSinceLastUpdate;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                currentAnimation = walkLeft;
                currentAnimation.Update(gameTime);

                desiredDestinationPosition.X -= charSpeed * ticksSinceLastUpdate;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                currentAnimation = walkRight;
                currentAnimation.Update(gameTime);

                desiredDestinationPosition.X += charSpeed * ticksSinceLastUpdate;
            }

            //check collisions & if the player isn't going to collide with the environment, allow them to move in that direction.  Process the X & Y co-ordinate independantly.

            if (IsEnvironmentCollision(walls, new Vector2(desiredDestinationPosition.X, Y)) == false)
            {
                X = desiredDestinationPosition.X;
            }

            if (IsEnvironmentCollision(walls, new Vector2(X, desiredDestinationPosition.Y)) == false)
            {
                Y = desiredDestinationPosition.Y;
            }



#if _DEBUG // Code used for a 'teleport' function when the space bar is pressed.
            if (Keyboard.GetState().IsKeyDown(Keys.Space) && Game1.respawn > 0 && !OldKeyboardState.IsKeyDown(Keys.Space))
            {
                Game1.respawn--;

                do
                {
                    Random randomNumber = new Random();

                    int gridAlignedX = randomNumber.Next(0, GameConstants.windowWidth);
                    int gridAlignedY = randomNumber.Next(0, GameConstants.windowHeight);

                    gridAlignedX = gridAlignedX - (gridAlignedX % 16);
                    gridAlignedY = gridAlignedY - (gridAlignedY % 16);

                    X = gridAlignedX;
                    Y = gridAlignedY;
                } while (IsEnvironmentCollision(walls));
            }

            OldKeyboardState = Keyboard.GetState();
#endif
        }
Ejemplo n.º 11
0
 public static bool OneReleased(Keys key)
 {
     return(CurrentKeyboardState.IsKeyUp(key) && OldKeyboardState.IsKeyDown(key));
 }
Ejemplo n.º 12
0
 public static bool WasKeyKlicked(Keys key)
 {
     return(NewKeyboardState.IsKeyUp(key) && OldKeyboardState.IsKeyDown(key));
 }
Ejemplo n.º 13
0
        void Update()
        {
            if (Queue == null)
            {
                return;
            }

            TimeStamp += (long)(GameSpeed.TickDuration);

            OldKeyboardState = _KeyboardState;
            OldMouseState    = _MouseState;
            OldScrollValue   = _ScrollValue;

            _KeyboardState = Keyboard.GetState();
            _MouseState    = Mouse.GetState();
            _ScrollValue   = _MouseState.ScrollWheelValue;

            var ScreenCoordinates = new Vector2(_MouseState.X, _MouseState.Y);
            var WorldCoordinates  = DisplaySettings.TransformPoint(_MouseState.X, _MouseState.Y);

            _MouseState = _MouseState.UpdatePosition((int)WorldCoordinates.X, (int)WorldCoordinates.Y);

            // mouse move
            if (IsInsideWindow((int)ScreenCoordinates.X, (int)ScreenCoordinates.Y))
            {
                if (OldScrollValue != _ScrollValue)
                {
                    Queue.Enqueue(InputEvent.MouseScroll(TimeStamp, _ScrollValue - OldScrollValue));
                }

                if (OldMouseState.X != _MouseState.X || OldMouseState.Y != _MouseState.Y)
                {
                    Queue.Enqueue(InputEvent.MouseMove(TimeStamp, _MouseState.X, _MouseState.Y));
                }

                // mouse click left
                if (_MouseState.LeftButton == ButtonState.Pressed && OldMouseState.LeftButton == ButtonState.Released)
                {
                    Queue.Enqueue(InputEvent.MouseClick(ButtonState.Pressed, TimeStamp, MouseButton.Left));
                }

                if (_MouseState.LeftButton == ButtonState.Released && OldMouseState.LeftButton == ButtonState.Pressed)
                {
                    Queue.Enqueue(InputEvent.MouseClick(ButtonState.Released, TimeStamp, MouseButton.Left));
                }

                // mouse click right
                if (_MouseState.RightButton == ButtonState.Pressed && OldMouseState.RightButton == ButtonState.Released)
                {
                    Queue.Enqueue(InputEvent.MouseClick(ButtonState.Pressed, TimeStamp, MouseButton.Right));
                }

                if (_MouseState.RightButton == ButtonState.Released && OldMouseState.RightButton == ButtonState.Pressed)
                {
                    Queue.Enqueue(InputEvent.MouseClick(ButtonState.Released, TimeStamp, MouseButton.Right));
                }
            }

            // key down
            foreach (var Key in _KeyboardState.GetPressedKeys())
            {
                if (!OldKeyboardState.IsKeyDown(Key))
                {
                    Queue.Enqueue(InputEvent.KeyPress(KeyState.Down, TimeStamp, Key));
                }
            }

            // key up
            foreach (var Key in OldKeyboardState.GetPressedKeys())
            {
                if (!_KeyboardState.IsKeyDown(Key))
                {
                    Queue.Enqueue(InputEvent.KeyPress(KeyState.Up, TimeStamp, Key));
                }
            }
        }
Ejemplo n.º 14
0
        public override void Update(GameTime gameTime)
        {
            if (MainContent == null)
            {
                Screens.Pop();
                return;
            }
            NewKeyboardState = Keyboard.GetState();

            int direction = 0;

            /*
             * Right: 1
             * Up: 2
             * Left: 4
             * Down: 8*/


            // MOVE PLAYER
            // We can use the Direction class that I made to avoid confusion
            if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                direction += 1;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                direction += 2;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                direction += 4;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                direction += 8;
            }
            if (OldKeyboardState.IsKeyUp(Keys.B) && Keyboard.GetState().IsKeyDown(Keys.B))
            {
                if (MainContent.PlayerShip.getBombs() > 0)
                {
                    MainContent.PlayerShip.useBomb();
                    RemoveAllBullets();
                }
            }

            if (direction != 0)
            {
                MainContent.PlayerShip.Move(Direction.ConvertKeyDirection(direction));
            }

            // TOGGLE SPEED
            // we have to check the key is down, and not just being spammed
            if (OldKeyboardState.IsKeyUp(Keys.LeftShift) && NewKeyboardState.IsKeyDown(Keys.LeftShift))
            {
                MainContent.PlayerShip.ToggleRate(2);
            }

            // fire a bullet
            if (OldKeyboardState.IsKeyUp(Keys.Space) && NewKeyboardState.IsKeyDown(Keys.Space))
            {
                MainContent.FiringController.From(MainContent.PlayerShip).Between(MainContent.Events.TimeElapsed(),
                                                                                  MainContent.Events.TimeElapsed() + .1).Pattern(new SingleBulletFiringPattern());
                Stats.BulletFired();
            }
            if (OldKeyboardState.IsKeyUp(Keys.Escape) && NewKeyboardState.IsKeyDown(Keys.Escape))
            {
                Screens.Pop();
                Screens.Peek().OldKeyboardState = this.NewKeyboardState;
            }

            if (OldKeyboardState.IsKeyUp(Keys.Q) && NewKeyboardState.IsKeyDown(Keys.Q))
            {
                MainContent.ManualInvincibility();
            }

            foreach (BulletModel gb in MainContent.GoodBulletList)
            {
                gb.Move(Direction.Stay, Direction.Up);
            }

            // update the keyboard state
            OldKeyboardState = NewKeyboardState;

            MainContent.Events.ExecuteScheduledEvents();
        }
 public static bool IsKey(Func <bool, bool, bool> checkState, Keys key)
 {
     return(checkState
                (NewKeyboardState.IsKeyDown(key)
                , OldKeyboardState.IsKeyDown(key)));
 }