Ejemplo n.º 1
0
 public bool IsNewKeyRelease(Keys key)
 {
     return(PreviousKeyboardState.IsKeyDown(key) && KeyboardState.IsKeyUp(key));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Checks if any of the keys specified were down last frame
 /// </summary>
 public bool WasAnyKeysDown(params Keys[] keys)
 {
     return(keys.Any(k => PreviousKeyboardState.IsKeyDown(k)));
 }
Ejemplo n.º 3
0
 public void Update(GameTime gameTime)
 {
     guiSystem.Update();
     CurrentKeyboardState = Keyboard.GetState();
     if ((CurrentKeyboardState.IsKeyUp(Keys.Enter) && PreviousKeyboardState.IsKeyDown(Keys.Enter)) || (CurrentKeyboardState.IsKeyUp(Keys.E) && PreviousKeyboardState.IsKeyDown(Keys.E)))
     {
         if (btnControlUp.IsSelected)
         {
             if (btnReturn.IsSelected)
             {
                 Game1.gameState = Game1.GameState.StartMenu;
             }
         }
     }
     PreviousKeyboardState = Keyboard.GetState();
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Checks if a given key has been toggled (Was pressed last state, but now isn't)
 /// </summary>
 public bool WasKeyPressed(Keys key)
 {
     return(CurrentKeyboardState.IsKeyUp(key) && PreviousKeyboardState.IsKeyDown(key));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Checks if any of the keys specified are pressed/toggled
 /// </summary>
 public bool AnyKeysPressed(params Keys[] keys)
 {
     return(keys.Any(k => CurrentKeyboardState.IsKeyUp(k) && PreviousKeyboardState.IsKeyDown(k)));
 }
Ejemplo n.º 6
0
        // Manage the GUI here, all the buttons and player input.
        public void Update(GameTime gameTime)
        {
            backgroundManager.Update();

            CurrentKeyboardState = Keyboard.GetState();
            // Button actions go here
            if ((CurrentKeyboardState.IsKeyUp(Keys.Enter) && PreviousKeyboardState.IsKeyDown(Keys.Enter)) || (CurrentKeyboardState.IsKeyUp(Keys.E) && PreviousKeyboardState.IsKeyDown(Keys.E)))
            {
                if (btnNewGame.IsSelected)
                {
                    Game1.gameState = Game1.GameState.Playing;
                }

                //if (btnOptions.IsSelected)
                //Game1.gameState = Game1.GameState.OptionsMenu;

                if (btnExit.IsSelected)
                {
                    Game1.gameState = Game1.GameState.Exiting;
                }
            }
            PreviousKeyboardState = Keyboard.GetState();
            guiSystem.Update();
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Checks if a given key is was down last frame
 /// </summary>
 public bool WasKeyDown(Keys key)
 {
     return(PreviousKeyboardState.IsKeyDown(key));
 }
Ejemplo n.º 8
0
        protected override void Update(GameTime gameTime)
        {
            FPSCounter.Update(gameTime);

            CurrentMouseState    = Mouse.GetState();
            CurrentKeyboardState = Keyboard.GetState();

            if (CurrentKeyboardState.IsKeyUp(Keys.A) && PreviousKeyboardState.IsKeyDown(Keys.A))
            {
                XDensity -= 1;
            }

            if (CurrentKeyboardState.IsKeyUp(Keys.S) && PreviousKeyboardState.IsKeyDown(Keys.S))
            {
                XDensity += 1;
            }

            if (CurrentKeyboardState.IsKeyUp(Keys.Z) && PreviousKeyboardState.IsKeyDown(Keys.Z))
            {
                YDensity -= 1;
            }

            if (CurrentKeyboardState.IsKeyUp(Keys.X) && PreviousKeyboardState.IsKeyDown(Keys.X))
            {
                YDensity += 1;
            }

            if (CurrentKeyboardState.IsKeyUp(Keys.F5) && PreviousKeyboardState.IsKeyDown(Keys.F5))
            {
                ResetGrass(XDensity, YDensity);
            }

            foreach (GrassBlade blade in GrassList)
            {
                if (CurrentMouseState.X > PreviousMouseState.X)
                {
                    if (Vector2.Distance(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), blade.OriginalState.basePosition) < 100)
                    {
                        float PercentDist = 1 - ((100 / 100) * Vector2.Distance(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), blade.OriginalState.basePosition)) / 100;
                        if (blade.CurrentState.tipPosition.X > Mouse.GetState().X)
                        {
                            //blade.CurrentState.controlPoint = Vector2.Lerp(blade.OriginalState.controlPoint, blade.OriginalState.controlPoint + (Vector2.One * (20 * PercentDist)), 0.8f * PercentDist);
                            blade.CurrentState.tipPosition.X = MathHelper.Lerp(blade.OriginalState.tipPosition.X, blade.OriginalState.tipPosition.X + (50 * PercentDist), 0.8f * PercentDist);
                        }
                    }
                    blade.Update(gameTime);
                }
                else
                {
                    //blade.CurrentState.controlPoint = Vector2.Lerp(blade.CurrentState.controlPoint, blade.OriginalState.controlPoint, (float)(0.05f * Random.NextDouble() * 2));
                    blade.CurrentState.tipPosition.X = MathHelper.Lerp(blade.CurrentState.tipPosition.X, blade.OriginalState.tipPosition.X, (float)(0.05f * Random.NextDouble() * 2));
                    blade.Update(gameTime);
                }

                if (CurrentMouseState.X < PreviousMouseState.X)
                {
                    if (Vector2.Distance(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), blade.OriginalState.basePosition) < 100)
                    {
                        float PercentDist = 1 - ((100 / 100) * Vector2.Distance(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), blade.OriginalState.basePosition)) / 100;
                        if (blade.CurrentState.tipPosition.X < Mouse.GetState().X)
                        {
                            //blade.CurrentState.controlPoint = Vector2.Lerp(blade.OriginalState.controlPoint, blade.OriginalState.controlPoint - (Vector2.One * (20 * PercentDist)), 0.8f * PercentDist);
                            blade.CurrentState.tipPosition.X = MathHelper.Lerp(blade.OriginalState.tipPosition.X, blade.OriginalState.tipPosition.X - (50 * PercentDist), 0.8f * PercentDist);
                        }
                    }
                    blade.Update(gameTime);
                }
                else
                {
                    //blade.CurrentState.controlPoint = Vector2.Lerp(blade.CurrentState.controlPoint, blade.OriginalState.controlPoint, (float)(0.05f * Random.NextDouble() * 2));
                    blade.CurrentState.tipPosition.X = MathHelper.Lerp(blade.CurrentState.tipPosition.X, blade.OriginalState.tipPosition.X, (float)(0.05f * Random.NextDouble() * 2));
                    blade.Update(gameTime);
                }
            }

            PreviousKeyboardState = CurrentKeyboardState;
            PreviousMouseState    = CurrentMouseState;
            base.Update(gameTime);
        }
Ejemplo n.º 9
0
 public static bool IsHeldKey(Keys k)
 {
     return(CurrentKeyboardState.IsKeyDown(k) && PreviousKeyboardState.IsKeyDown(k));
 }
Ejemplo n.º 10
0
        public void Update(GameTime gameTime, GraphicsDevice graphicsDevice)
        {
            backgroundManager.Update();
            CurrentKeyboardState = Keyboard.GetState();
            // Button actions go here
            if ((CurrentKeyboardState.IsKeyUp(Keys.Enter) && PreviousKeyboardState.IsKeyDown(Keys.Enter)) || (CurrentKeyboardState.IsKeyUp(Keys.E) &&
                                                                                                              PreviousKeyboardState.IsKeyDown(Keys.E)))
            {
                if (btnBack.IsSelected)
                {
                    Game1.gameState = GameState.StartMenu;
                }
            }
            PreviousKeyboardState = Keyboard.GetState();

            guiSystem.Update();
        }
Ejemplo n.º 11
0
        // Any update code which is generic for all Objects of a type.
        public void Update()
        {
            // Button Management
            CurrentKeyboardState = Keyboard.GetState();
            if ((CurrentKeyboardState.IsKeyUp(Keys.Down) && PreviousKeyboardState.IsKeyDown(Keys.Down)) || (CurrentKeyboardState.IsKeyUp(Keys.S) && PreviousKeyboardState.IsKeyDown(Keys.S)))
            {
                if (ButtonIndex < GuiButtonCount - 1)
                {
                    ButtonIndex++;
                }

                ButtonIndexUpdate(ButtonIndex);
            }

            if ((CurrentKeyboardState.IsKeyUp(Keys.Up) && PreviousKeyboardState.IsKeyDown(Keys.Up)) || (CurrentKeyboardState.IsKeyUp(Keys.W) && PreviousKeyboardState.IsKeyDown(Keys.W)))
            {
                if (ButtonIndex > 0)
                {
                    ButtonIndex--;
                }

                ButtonIndexUpdate(ButtonIndex);
            }
            PreviousKeyboardState = CurrentKeyboardState;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Check for releases by comparing the previous state to the current state.
 /// In the event of a key release it will have been down, and currently its up
 /// </summary>
 /// <param name="key">This is the key to check for release</param>
 /// <returns></returns>
 public bool KeyReleased(Keys key)
 {
     return(KeyboardState.IsKeyUp(key) && PreviousKeyboardState.IsKeyDown(key));
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Gets whether the given key was just released.
 /// </summary>
 /// <param name="key">The given key.</param>
 /// <returns>True if it was just released, false otherwise.</returns>
 public static bool GetKeyUp(Keys key)
 {
     return(PreviousKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key));
 }
Ejemplo n.º 14
0
 protected bool WasJustPressed(Keys key)
 {
     return(CurrentKeyboardState.IsKeyDown(key) && !PreviousKeyboardState.IsKeyDown(key));
 }
Ejemplo n.º 15
0
        public bool IsInputPressed(Keys key)
        {
            KeyboardState keyboardState = Keyboard.GetState();
            GamePadState  gamePadState  = GamePad.GetState(PlayerIndex.One);

            //Enter/Accept/Debug has the same logic for UI and in game.
            if (key == Keys.Enter && ((keyboardState.IsKeyDown(Keys.Space) && !PreviousKeyboardState.IsKeyDown(Keys.Space)) ||
                                      (keyboardState.IsKeyDown(Keys.Enter) && !PreviousKeyboardState.IsKeyDown(Keys.Enter)) ||
                                      (gamePadState.IsButtonDown(Buttons.A) && !PreviousGamePadState.IsButtonDown(Buttons.A)) ||
                                      (gamePadState.IsButtonDown(Buttons.Start) && !PreviousGamePadState.IsButtonDown(Buttons.Start))))
            {
                return(true);
            }
            else if (key == Keys.Home && ((keyboardState.IsKeyDown(Keys.Home) && !PreviousKeyboardState.IsKeyDown(Keys.Home) ||
                                           (gamePadState.IsButtonDown(Buttons.Back) && !PreviousGamePadState.IsButtonDown(Buttons.Back)))))
            {
                return(true);
            }
            else if (TheLastSliceGame.Instance.GameState == GameState.Menu)
            {
                //For menus we need to check the previous state of the input.
                if (key == Keys.Up && ((keyboardState.IsKeyDown(Keys.Up) && !PreviousKeyboardState.IsKeyDown(Keys.Up)) ||
                                       (keyboardState.IsKeyDown(Keys.W) && !PreviousKeyboardState.IsKeyDown(Keys.W)) ||
                                       (gamePadState.IsButtonDown(Buttons.DPadUp) && !PreviousGamePadState.IsButtonDown(Buttons.DPadUp)) ||
                                       (gamePadState.ThumbSticks.Left.Y > 0.2 && PreviousGamePadState.ThumbSticks.Left.Y < 0.2)))
                {
                    return(true);
                }
                else if (key == Keys.Down && ((keyboardState.IsKeyDown(Keys.Down) && !PreviousKeyboardState.IsKeyDown(Keys.Down)) ||
                                              (keyboardState.IsKeyDown(Keys.S) && !PreviousKeyboardState.IsKeyDown(Keys.S)) ||
                                              (gamePadState.IsButtonDown(Buttons.DPadDown) && !PreviousGamePadState.IsButtonDown(Buttons.DPadDown)) ||
                                              (gamePadState.ThumbSticks.Left.Y < -0.2 && PreviousGamePadState.ThumbSticks.Left.Y > -0.2)))
                {
                    return(true);
                }
                else if (keyboardState.IsKeyDown(key) && !PreviousKeyboardState.IsKeyDown(key))
                {
                    return(true);
                }
            }
            else
            {
                if (key == Keys.Up && (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W) ||
                                       gamePadState.IsButtonDown(Buttons.DPadUp) || gamePadState.ThumbSticks.Left.Y > 0.2))
                {
                    return(true);
                }
                else if (key == Keys.Down && (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S) ||
                                              gamePadState.IsButtonDown(Buttons.DPadDown) || gamePadState.ThumbSticks.Left.Y < -0.2))
                {
                    return(true);
                }
                else if (key == Keys.Left && (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A) ||
                                              gamePadState.IsButtonDown(Buttons.DPadLeft) || gamePadState.ThumbSticks.Left.X < -0.2))
                {
                    return(true);
                }
                else if (key == Keys.Right && (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D) ||
                                               gamePadState.IsButtonDown(Buttons.DPadRight) || gamePadState.ThumbSticks.Left.X > 0.2))
                {
                    return(true);
                }
                else if (keyboardState.IsKeyDown(key) && !PreviousKeyboardState.IsKeyDown(key))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 16
0
        private static void DetermineInput(Keys[] fighterKeys, Keys[] currentPressedKeys, FighterModel fighter, Dictionary <string, ViewObject> actions)
        {
            if (actions["Hit"].Drawn)
            {
                if (!BlockInput)
                {
                    foreach (Keys pressedKey in currentPressedKeys)
                    {
                        if (pressedKey == fighterKeys[0])
                        {
                            BattlegroundController.ResetViews(actions);

                            fighter.Move("left");

                            actions["Move"].ToBeDrawn = true;
                            actions["Move"].Drawn     = false;

                            for (int i = 0; i < currentPressedKeys.Length; i++)
                            {
                                if (currentPressedKeys[i] == fighterKeys[1] || currentPressedKeys[i] == fighterKeys[2] ||
                                    currentPressedKeys[i] == fighterKeys[2])
                                {
                                    currentPressedKeys[i] = Keys.None;
                                }
                            }
                        }
                        else if (pressedKey == fighterKeys[1])
                        {
                            BattlegroundController.ResetViews(actions);

                            fighter.Move("right");

                            actions["ReversedMove"].ToBeDrawn = true;
                            actions["ReversedMove"].Drawn     = false;

                            for (int i = 0; i < currentPressedKeys.Length; i++)
                            {
                                if (currentPressedKeys[i] == fighterKeys[0] || currentPressedKeys[i] == fighterKeys[2] ||
                                    currentPressedKeys[i] == fighterKeys[3])
                                {
                                    currentPressedKeys[i] = Keys.None;
                                }
                            }
                        }
                        else if (pressedKey == fighterKeys[2] && !PreviousKeyboardState.IsKeyDown(fighterKeys[2]))
                        {
                            fighter.Punch();

                            // TO REDUCE INPUT DELAY:
                            actions["Move"].Drawn         = true;
                            actions["ReversedMove"].Drawn = true;

                            actions["Punch"].ToBeDrawn = true;
                            actions["Punch"].Drawn     = false;

                            for (int i = 0; i < currentPressedKeys.Length; i++)
                            {
                                if (currentPressedKeys[i] == fighterKeys[0] || currentPressedKeys[i] == fighterKeys[1] ||
                                    currentPressedKeys[i] == fighterKeys[3])
                                {
                                    currentPressedKeys[i] = Keys.None;
                                }
                            }
                        }
                        else if (pressedKey == fighterKeys[3] && !PreviousKeyboardState.IsKeyDown(fighterKeys[3]))
                        {
                            fighter.Kick();

                            actions["Move"].Drawn         = true;
                            actions["ReversedMove"].Drawn = true;

                            actions["Kick"].ToBeDrawn = true;
                            actions["Kick"].Drawn     = false;

                            for (int i = 0; i < currentPressedKeys.Length; i++)
                            {
                                if (currentPressedKeys[i] == fighterKeys[0] || currentPressedKeys[i] == fighterKeys[1] ||
                                    currentPressedKeys[i] == fighterKeys[2])
                                {
                                    currentPressedKeys[i] = Keys.None;
                                }
                            }
                        }

                        // ADD BLOCKING FUNCTIONALITY HERE
                    }
                }
            }
        }
Ejemplo n.º 17
0
 // ************************ Lab 11 ****************************************
 public static bool IsKeyReleased(Keys key)
 {
     return(CurrentKeyboardState.IsKeyUp(key) && PreviousKeyboardState.IsKeyDown(key));
 }
Ejemplo n.º 18
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)
        {
#if (ANDROID)
            // Get touch input
            bool gesturing = false;
            while (TouchPanel.IsGestureAvailable)
            {
                gesture   = TouchPanel.ReadGesture();
                gesturing = true;
            }

            // Start the game
            if (gesture.GestureType == GestureType.Tap)
            {
                gameState = GameState.Playing;
            }
#endif
            CurrentKeyboardState = Keyboard.GetState();
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                gameState = GameState.StartMenu;
            }

            // TODO: Add your update logic here
            if (gameState == GameState.StartMenu)
            {
                if (LoadedGameState != GameState.StartMenu)
                {
                    Content.Unload();
                    startMenu = new StartMenuScreen(graphics);
                    startMenu.Initialize();
                    startMenu.LoadContent(Content, GraphicsDevice);
                    LoadedGameState = GameState.StartMenu;
                }
                startMenu.Update(gameTime);
            }

            if (gameState == GameState.OptionsMenu)
            {
                if (LoadedGameState != GameState.OptionsMenu)
                {
                    Content.Unload();
                    optionsMenuScreen = new OptionsMenuScreen();
                    optionsMenuScreen.Initialize();
                    optionsMenuScreen.LoadContent(Content, GraphicsDevice);
                    LoadedGameState = GameState.OptionsMenu;
                }
                optionsMenuScreen.Update(gameTime);
            }

            if (CurrentKeyboardState.IsKeyUp(Keys.P) && PreviousKeyboardState.IsKeyDown(Keys.P))
            {
                if (gameState == GameState.Paused)
                {
                    gameState = GameState.Playing;
                }
                else if (gameState == GameState.Playing)
                {
                    gameState = GameState.Paused;
                }
            }

            if (gameState == GameState.Playing)
            {
                if (LoadedGameState != GameState.Playing)
                {
                    Content.Unload();
                    gameScreen = new GameScreen(graphics);
                    gameScreen.Initialize(Content, GraphicsDevice);
                    gameScreen.LoadContent(Content, GraphicsDevice);
                    LoadedGameState = GameState.Playing;
                }
                gameScreen.Update(gameTime, GraphicsDevice);
            }

            // Gameover goes to Start Menu for now
            if (gameState == GameState.GameOver)
            {
                if (LoadedGameState != GameState.GameOver)
                {
                    Content.Unload();
                    gameOverScreen = new GameOverScreen();
                    gameOverScreen.Initialize();
                    gameOverScreen.LoadContent(Content, GraphicsDevice);
                    LoadedGameState = GameState.GameOver;
                }
                gameOverScreen.Update(gameTime, GraphicsDevice);
            }

#if (ANDROID)
            if (gesturing == false)
            {
                gesture = new GestureSample();
            }
#endif

            if (gameState == GameState.Exiting)
            {
                this.Exit();
            }
            PreviousKeyboardState = Keyboard.GetState();
            base.Update(gameTime);
        }