public override void Update(GameTime gameTime, GamePadState newGamePadState, GamePadState oldGamePadState, KeyboardState newKeyboardState, KeyboardState oldKeyboardState)
 {
     if ((newGamePadState.Buttons.A != oldGamePadState.Buttons.A && newGamePadState.Buttons.A == ButtonState.Pressed)
         || (newKeyboardState.IsKeyDown(Keys.Enter) && oldKeyboardState.IsKeyUp(Keys.Enter))) {
         Game.GameStartingScreen = GameStartingScreen.SetupScreen;
     }
 }
Example #2
0
        public static List<InputManager.ACTIONS> GetInput()
        {
            currentGamePadState = GamePad.GetState(PlayerIndex.One);
            List<InputManager.ACTIONS> actions = new List<InputManager.ACTIONS>();

            if (currentGamePadState.IsButtonUp(Buttons.A) && previousGamePadState.IsButtonDown(Buttons.A))
            {
                actions.Add(InputManager.ACTIONS.JUMP);
            }

            if (currentGamePadState.ThumbSticks.Left.X > 0 || currentGamePadState.DPad.Right == ButtonState.Pressed)
            {
                actions.Add(InputManager.ACTIONS.RIGHT);
            }
            else if (currentGamePadState.ThumbSticks.Left.X < 0 || currentGamePadState.DPad.Left == ButtonState.Pressed)
            {
                actions.Add(InputManager.ACTIONS.LEFT);
            }

            if (currentGamePadState.IsButtonUp(Buttons.Y) && previousGamePadState.IsButtonDown(Buttons.Y))
            {
                actions.Add(InputManager.ACTIONS.TOGGLE);
            }

            previousGamePadState = currentGamePadState;
            return actions;
        }
Example #3
0
        public override void Update(GameTime gameTime, EventManager events)
        {
            base.Update(gameTime, events);

              #region GamePad

              // GamePad
              P1LastGamePadState = P1GamePadState;
              P1GamePadState = GamePad.GetState(PlayerIndex.One);

              bool left = P1GamePadState.ThumbSticks.Left.X < 0.0f;
              bool right = P1GamePadState.ThumbSticks.Left.X > 0.0f;
              bool jump = (P1GamePadState.Buttons.A == ButtonState.Pressed
            && P1LastGamePadState.Buttons.A == ButtonState.Released);
              bool action = (P1GamePadState.Buttons.B == ButtonState.Released
            && P1LastGamePadState.Buttons.B == ButtonState.Pressed);

              #endregion

              #region Keyboard

              bool keyJump = (keyboard.IsKeyDown(Keys.Up)
            && lastKeyboard.IsKeyUp(Keys.Up));
              bool keyDownLeft = keyboard.IsKeyDown(Keys.Left);
              bool keyDownRight = keyboard.IsKeyDown(Keys.Right);
              bool keyAction = keyboard.IsKeyUp(Keys.Space)
            && lastKeyboard.IsKeyDown(Keys.Space);

              #endregion

              if (action || keyAction) events.Notify(Event.Action, null);
        }
        public void ProcessController()
        {
            keyState = Keyboard.GetState();
            padState = GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One);
            Actor hero = (Actor)game.Hero;

            /*
             * GamePad inputs
             */

            //Moving
            if (padState.IsButtonDown(Buttons.LeftThumbstickLeft) || keyState.IsKeyDown(Keys.Left))
            {
                hero.Pos.X -= 1.5f;
                hero.NextPosture(ActorDirection.Left);
            }
            if (padState.IsButtonDown(Buttons.LeftThumbstickRight) || keyState.IsKeyDown(Keys.Right))
            {
                hero.Pos.X += 1.5f;
                hero.NextPosture(ActorDirection.Right);
            }

            //Jump
            if (padState.IsButtonDown(Buttons.LeftThumbstickUp))
            {

            }

            if (padState.IsButtonDown(Buttons.LeftThumbstickDown))
            {

            }
        }
Example #5
0
        /// <summary>
        ///   Constructs a new input state.
        /// </summary>
        public InputHelper(ScreenManager manager)
        {
            _currentKeyboardState = new KeyboardState();
            _currentGamePadState = new GamePadState();
            _currentMouseState = new MouseState();
            _currentVirtualState = new GamePadState();

            _lastKeyboardState = new KeyboardState();
            _lastGamePadState = new GamePadState();
            _lastMouseState = new MouseState();
            _lastVirtualState = new GamePadState();

            _manager = manager;

            _cursorIsVisible = false;
            _cursorMoved = false;
#if WINDOWS_PHONE
            _cursorIsValid = false;
#else
            _cursorIsValid = true;
#endif
            _cursor = Vector2.Zero;

            _handleVirtualStick = true;
        }
Example #6
0
 /// <summary>
 /// Performs the logic to control the Player.
 /// </summary>
 /// <param name="pad">The state of the gamepad used to control this player.</param>
 public void Update(GamePadState pad)
 {
     if (pad.ThumbSticks.Left.X >= 0.5) pos.X += speed;
     if (pad.ThumbSticks.Left.X <= -0.5) pos.X -= speed;
     if (pad.ThumbSticks.Left.Y >= 0.5) pos.Y -= speed;
     if (pad.ThumbSticks.Left.Y <= -0.5) pos.Y += speed;
 }
Example #7
0
        public override void Update(float deltaTime)
        {
            if (id == World.gameId)
            {
                gamePad = GamePad.GetState(PlayerIndex.One);
                keyboard = Keyboard.GetState();

                if (gamePad.Buttons.Y == ButtonState.Pressed &&
                    oldGamePad.Buttons.Y == ButtonState.Released &&
                    World.inMenu == false ||
                    keyboard.IsKeyDown(Keys.Tab) &&
                    oldKeyboard.IsKeyUp(Keys.Tab) &&
                    World.inMenu == false)
                {
                    World.inMenu = true;
                    World.menuManager.SwitchMenu(World.menuManager.shop);
                }
                else if (keyboard.IsKeyDown(Keys.Tab) &&
                   oldKeyboard.IsKeyUp(Keys.Tab) &&
                   World.inMenu == true)
                {
                    World.menuManager.CurrentMenu.BackOut();
                }
            }
            oldGamePad = gamePad;
            oldKeyboard = keyboard;
            base.Update(deltaTime);
        }
Example #8
0
 public float getAxis(GamePadState gamePadState, bool left, bool x)
 {
     if (x)
     {
         if (left)
         {
             return gamePadState.ThumbSticks.Left.X;
         }
         else
         {
             return gamePadState.ThumbSticks.Right.X;
         }
     }
     else
     {
         if (left)
         {
             return gamePadState.ThumbSticks.Left.Y;
         }
         else
         {
             return gamePadState.ThumbSticks.Right.Y;
         }
     }
 }
Example #9
0
        /// <summary>
        /// Gets the current direction from a game pad and keyboard.
        /// </summary>
        public static Buttons FromInput(GamePadState gamePad, KeyboardState keyboard)
        {
            Buttons direction = None;

            // Get vertical direction.
            if (gamePad.IsButtonDown(Buttons.DPadUp) ||
                gamePad.IsButtonDown(Buttons.LeftThumbstickUp) ||
                keyboard.IsKeyDown(Keys.Up))
            {
                direction |= Up;
            }
            else if (gamePad.IsButtonDown(Buttons.DPadDown) ||
                gamePad.IsButtonDown(Buttons.LeftThumbstickDown) ||
                keyboard.IsKeyDown(Keys.Down))
            {
                direction |= Down;
            }

            // Comebine with horizontal direction.
            if (gamePad.IsButtonDown(Buttons.DPadLeft) ||
                gamePad.IsButtonDown(Buttons.LeftThumbstickLeft) ||
                keyboard.IsKeyDown(Keys.Left))
            {
                direction |= Left;
            }
            else if (gamePad.IsButtonDown(Buttons.DPadRight) ||
                gamePad.IsButtonDown(Buttons.LeftThumbstickRight) ||
                keyboard.IsKeyDown(Keys.Right))
            {
                direction |= Right;
            }

            return direction;
        }
Example #10
0
        public virtual void GamePadController(GamePadState state)
        {
            if (state.DPad.Down == ButtonState.Pressed && !(_previousGamePadState.DPad.Down == ButtonState.Pressed))
            {
                _selectedIndex++;

                if (_selectedIndex == _levels.Length)
                    _selectedIndex--;
            }
            else if (state.DPad.Up == ButtonState.Pressed && !(_previousGamePadState.DPad.Up == ButtonState.Pressed))
            {
                _selectedIndex--;

                if (_selectedIndex < 0)
                    _selectedIndex++;
            }
            else if (state.Buttons.A == ButtonState.Pressed &&!(_previousGamePadState.Buttons.A ==ButtonState.Pressed))
            {
                var sample = _levels[_selectedIndex].CreateLevelFunction();
                sample.OnLoad();
                CurrentLevel = sample;
            }

            _previousGamePadState = state;
        }
Example #11
0
        /// <summary>
        /// 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.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
            previousGamePadState = GamePad.GetState(PlayerIndex.One);
        }
Example #12
0
        //Methods
        //Update & Draw
        public void Update(MouseState mouse, KeyboardState keyboard, GamePadState gamePadState)
        {
            if (keyboard.IsKeyUp(Keys.Escape) && gamePadState.Buttons.Start == ButtonState.Released)
                pauseAllowed = true;

            if ((keyboard.IsKeyDown(Keys.Escape) || gamePadState.Buttons.Start == ButtonState.Pressed) && pauseAllowed)
            {

                pauseAllowed = false;
                Game1.gameState = GameState.Pause;
            }

            if (mouse.X > 800)
            {
                Map.Current.position.X++;
                player.position.X++;
            }

            if (mouse.X < 200)
            {
                Map.Current.position.X--;
                player.position.X--;
            }

            Map.Current.Update();
            player.Update(mouse, keyboard, gamePadState);
        }
Example #13
0
        private List<Command> handleController()
        {
            List<Command> commands = new List<Command>();
            padState = GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One);
            
            Vector2 move = new Vector2();
            move.X = 0;
            move.Y = 0;
            if (padState.ThumbSticks.Left.Length() > .7f)
            {
                move.X = padState.ThumbSticks.Left.X * .7f;
                move.Y = -padState.ThumbSticks.Left.Y * .7f;   
            }
            commands.Add(new MoveCommand(move));


            Vector2 gazeDir = new Vector2();
            gazeDir.X = padState.ThumbSticks.Right.X;
            gazeDir.Y = -padState.ThumbSticks.Right.Y;
            commands.Add(new GazeCommand(gazeDir));

            if (padState.IsButtonDown(Buttons.RightShoulder))
                commands.Add(new PunchCommand());
            return commands;
        }
Example #14
0
        public override void CaptureMouseState()
        {
            _gpState = XInput.GamePad.GetState( XFG.PlayerIndex.One );

            relativeMousePosition.X = _gpState.ThumbSticks.Left.X;
            relativeMousePosition.Y = _gpState.ThumbSticks.Left.Y;
        }
Example #15
0
 public GetInput(PlayerIndex index)
 {
     playerIndex = index;
     directionBoolArray = new bool[4] { upPressed, leftPressed, downPressed, rightPressed };
     oldKeyState = Keyboard.GetState();
     oldPadState = GamePad.GetState(playerIndex);
 }
Example #16
0
 //********************************************
 // Constructors
 //********************************************
 public InputManager(Main game)
 {
     z_game = game;
     z_prevKeyState = z_curKeyState = new KeyboardState();
     z_prevPadState = z_curPadState = new GamePadState();
     SetDefaultControls();
 }
Example #17
0
        //=========================================================================================
        /// <summary>
        /// Constructor. Creates the object.
        /// </summary>
        //=========================================================================================
        public Gui_Game_Paused()
        {
            // Save the current kb and gamepad state;

            m_last_gamepad_state    = GamePad.GetState(PlayerIndex.One);
            m_last_keyboard_state   = Keyboard.GetState();
        }
        /// <summary>
        /// Exit the screen after a tap or click
        /// </summary>
        /// <param name="input"></param>
        private void HandleInput(MouseState mouseState, GamePadState padState)
        {
            if (!isExit)
            {
#if WINDOWS_PHONE
                if (ScreenManager.input.Gestures.Count > 0 &&
                    ScreenManager.input.Gestures[0].GestureType == GestureType.Tap)
                {
                    isExit = true;
                }
#else

                PlayerIndex result;
                if (mouseState.LeftButton == ButtonState.Pressed)
                {
                    isExit = true;
                }
                else if (ScreenManager.input.IsNewButtonPress(Buttons.A, null, out result) ||
                    ScreenManager.input.IsNewButtonPress(Buttons.Start, null, out result))
                {
                    isExit = true;
                }
#endif

            }
        }
Example #19
0
        //
        // Horizontal Movement
        protected void CheckHorizontalMovementKeys(KeyboardState ksKeys,
                                           GamePadState gsPad)
        {
            bool bResetTimer = false;

            player.Thrusting = false;
            if ((ksKeys.IsKeyDown(Keys.Right)) || (gsPad.ThumbSticks.Left.X > 0))
            {
                if (player.ScrollRate < iMaxHorizontalSpeed)
                {
                    player.ScrollRate += player.AccelerationRate;
                    if (player.ScrollRate > iMaxHorizontalSpeed)
                        player.ScrollRate = iMaxHorizontalSpeed;
                    bResetTimer = true;
                }
                player.Thrusting = true;
                player.Facing = 0;
            }

            if ((ksKeys.IsKeyDown(Keys.Left)) || (gsPad.ThumbSticks.Left.X < 0))
            {
                if (player.ScrollRate > -iMaxHorizontalSpeed)
                {
                    player.ScrollRate -= player.AccelerationRate;
                    if (player.ScrollRate < -iMaxHorizontalSpeed)
                        player.ScrollRate = -iMaxHorizontalSpeed;
                    bResetTimer = true;
                }
                player.Thrusting = true;
                player.Facing = 1;
            }

            if (bResetTimer)
                player.SpeedChangeCount = 0.0f;
        }
Example #20
0
        public void Update(GameTime gameTime)
        {
            oldGs = gamePadState;

            gamePadState = GamePad.GetState(playerIndex, GamePadDeadZone.None);
            gamePadChanged = gamePadState != oldGs;
        }
Example #21
0
 public void update(GamePadState gamePad, GameTime time)
 {
     if (! Menu.isActive())
     {
         if (time.TotalGameTime.Milliseconds % 50 == 0)
         {
             if (gamePad.ThumbSticks.Left.X > 0 && position.X < maxPosition.X)
                 position.X += cursorWidth;
             else if (gamePad.ThumbSticks.Left.X < 0 && position.X > 0)
                 position.X -= cursorWidth;
             if (gamePad.ThumbSticks.Left.Y < 0 && position.Y < maxPosition.Y)
                 position.Y += cursorHeight;
             else if (gamePad.ThumbSticks.Left.Y > 0 && position.Y > 0)
                 position.Y -= cursorHeight;
         }
         if (time.TotalGameTime.Milliseconds % 200 == 0)
         {
             if (gamePad.DPad.Right == ButtonState.Pressed && position.X < maxPosition.X)
                 position.X += cursorWidth;
             else if (gamePad.DPad.Left == ButtonState.Pressed && position.X > 0)
                 position.X -= cursorWidth;
             if (gamePad.DPad.Down == ButtonState.Pressed && position.Y < maxPosition.Y)
                 position.Y += cursorHeight;
             else if (gamePad.DPad.Up == ButtonState.Pressed && position.Y > 0)
                 position.Y -= cursorHeight;
         }
     }
 }
Example #22
0
        /// <summary>
        /// Updates key and pad states and also action values
        /// </summary>
        public void update()
        {
            keyState = Keyboard.GetState();
            padState = GamePad.GetState(index);

            foreach (Action action in actionList)
            {
                if (keyState.IsKeyDown(action.key) ||
                            padState.IsButtonDown(action.button))
                {
                    action.isPressed = true;
                    action.pressTime += 1;
                }
                else if ((keyState.IsKeyUp(action.key) &&
                                prevKeyState.IsKeyDown(action.key))
                        || (padState.IsButtonUp(action.button) &&
                                prevPadState.IsButtonDown(action.button)))
                {
                    action.isPressed = false;
                    action.pressTime = 0;
                };
            }
            //Last run - store the current states
            //as the previous state
            prevKeyState = keyState;
            prevPadState = padState;
        }
Example #23
0
        protected void AmbientToggle(KeyboardState currentKeyboardState, GamePadState currentGamePadState)
        {
            // toggle Ambient - Night/Day effect
            if (previousKeyboardState.IsKeyDown(Keys.E) &&
                currentKeyboardState.IsKeyUp(Keys.E) ||
                previousGamePadState.IsButtonDown(Buttons.RightShoulder) &&
                currentGamePadState.IsButtonUp(Buttons.RightShoulder))
            {
                ambient = !ambient;

                currentMusic.Stop();
                currentMusic.Dispose();

                // Ambient true sets to day time effect, false sets to night time effect
                if(ambient)
                {
                    skyColor = Color.DeepSkyBlue;
                    effect.Parameters["material"].StructureMembers["ambient"].SetValue(new Vector4(0.65f, 0.65f, 0.6f, 1.0f));
                    currentMusic = musicDay.CreateInstance();

                }
                else
                {
                    skyColor = Color.DarkSlateGray;
                    effect.Parameters["material"].StructureMembers["ambient"].SetValue(new Vector4(0.1f, 0.1f, 0.15f, 1.0f));
                    currentMusic = musicNight.CreateInstance();
                }
                enemy.Apply3DAudio(listener, enemy.Position, currentMusic);
                currentMusic.Play();

            }
        }
Example #24
0
        public void Update(Vector2 pos, MouseState mouse, GamePadState gps, GameTime gameTime)
        {
            //check user Drag Drop Events
            if (mouse.LeftButton == ButtonState.Pressed || gps.Buttons.A == ButtonState.Pressed)
            {
                //CHECK BUTTONS
                int clickedID = getClickedID(new Vector2(pos.X, pos.Y));
                if (clickedID >= 0)
                {
                    if (clickedID == 1)
                    {
                        main.stateManager.loadNextScreen(2, 0, gameTime);
                    }
                    if (clickedID == 2)
                    {
                        main.stateManager.loadNextScreen(4, 0, gameTime);
                    }
                    if (clickedID == 3)
                    {
                        main.lastState = 1;
                        main.stateManager.loadNextScreen(5, 0, gameTime);
                    }

                    Console.WriteLine("BUTTON PRESSED: clickedID: "+clickedID);
                    //APACURRO BOTONES
                }

            }
        }
Example #25
0
        public void UpdateJump(KeyboardState aCurrentKeyboardState, GamePadState aCurrentGamePadState)
        {
            if ((CurrentState == State.Walking || CurrentState == State.Still) && (aCurrentKeyboardState.IsKeyDown(Keys.Up) == true || aCurrentGamePadState.DPad.Up == ButtonState.Pressed || aCurrentGamePadState.Buttons.A == ButtonState.Pressed))
            {
                Jump();
            }

            if (CurrentState == State.Jumping)
            {

                if (StartPosition.Y - Position.Y > 80)  //At peak of jump...
                {
                    Dir.Y = MOVE_DOWN;
                    MoveSpeed.Y = 3.0f;
                }

                Position.Y = (Dir.Y == MOVE_DOWN) ? Position.Y + MoveSpeed.Y : Position.Y - MoveSpeed.Y; //Change Y position

                //END JUMP LOGIC
                if (Position.Y > StartPosition.Y)
                {
                    Position.Y = StartPosition.Y;
                    CurrentState = State.Still;
                    Source = new Rectangle(0, 0, 28, Source.Height);
                    Dir.Y = 0;
                    MoveSpeed.X = 6.0f;
                    MoveSpeed.Y = 3.5f;
                }
            }
        }
Example #26
0
 public Controls()
 {
     this.kb = Keyboard.GetState();
     this.kbo = Keyboard.GetState();
     this.gp = GamePad.GetState(PlayerIndex.One);
     this.gpo = GamePad.GetState(PlayerIndex.One);
 }
 /// <summary>
 /// Handles input, performs physics, and animates the player sprite.
 /// </summary>
 /// <remarks>
 /// We pass in all of the input states so that our game is only polling the hardware
 /// once per frame. We also pass the game's orientation because when using the accelerometer,
 /// we need to reverse our motion when the orientation is in the LandscapeRight orientation.
 /// </remarks>
 public void Update(
     GameTime gameTime,
     KeyboardState keyboardState,
     GamePadState gamePadState)
 {
     base.Update(gameTime);
 }
Example #28
0
 public void Update()
 {
     kbo = kb;
     gpo = gp;
     kb = Keyboard.GetState();
     this.gp = GamePad.GetState(PlayerIndex.One);
 }
Example #29
0
 static Input()
 {
     oldGamePadStates = new GamePadState[MaxInputs];
     newGamePadStates = new GamePadState[MaxInputs];
     //oldKeyboardState = new KeyboardState[MaxInputs];
     //newKeyboardState = new KeyboardState[MaxInputs];
 }
Example #30
0
        // Adds an attack when the attack button is pressed accompanied by sound and animation
        public static void AttackAdd(ContentManager Content, Player ninja, List<PlayerAttack> ninjaAttacks, 
            KeyboardState presentKey, KeyboardState pastKey,
            GamePadState pressentButton, GamePadState pastButton)
        {
            if (presentKey.IsKeyDown(Keys.Space) && pastKey.IsKeyUp(Keys.Space)
                || pressentButton.IsButtonDown(Buttons.A) && pastButton.IsButtonUp(Buttons.A))
            {
                // if the attack button is pressed a new attack will be added to the list
                ninjaAttacks.Add(new PlayerAttack(Content.Load<Texture2D>("Images\\Attack"),
                    new Vector2(ninja.PositionX + (int)(ninja.Texture.Width * 0.8),
                    ninja.PositionY + (int)(ninja.Texture.Height / 2.25))));

                // A sound effect will be played each time we press the attack button
                ninja.PlaySound();

            }

            // The animation texture of the character will change with each attack
            if (presentKey.IsKeyDown(Keys.Space) || pressentButton.IsButtonDown(Buttons.A))
            {
                ninja.Texture = Content.Load<Texture2D>("Images\\NinjaFrame1-2");
            }
            else
            {
                ninja.Texture = Content.Load<Texture2D>("Images\\NinjaFrame1-1");
            }
        }