IsKeyDown() public méthode

public IsKeyDown ( Keys key ) : bool
key Keys
Résultat bool
Exemple #1
0
        private void UpdateMovement(KeyboardState aCurrentKeyboardState)
        {
            if (mCurrentState == State.Walking)
            {
                mSpeed = Vector2.Zero;
                mDirection = Vector2.Zero;

                if (aCurrentKeyboardState.IsKeyDown(Keys.Left) == true)
                {
                    mSpeed.X = NERD_SPEED;
                    mDirection.X = MOVE_LEFT;
                }
                else if (aCurrentKeyboardState.IsKeyDown(Keys.Right) == true)
                {
                    mSpeed.X = NERD_SPEED;
                    mDirection.X = MOVE_RIGHT;
                }

                if (aCurrentKeyboardState.IsKeyDown(Keys.Up) == true)
                {
                    mSpeed.Y = NERD_SPEED;
                    mDirection.Y = MOVE_UP;
                }
                else if (aCurrentKeyboardState.IsKeyDown(Keys.Down) == true)
                {
                    mSpeed.Y = NERD_SPEED;
                    mDirection.Y = MOVE_DOWN;
                }
            }
        }
        public void Update(GameTime time)
        {
            oldState = currentState;
            currentState = Microsoft.Xna.Framework.Input.Keyboard.GetState();
            shiftDown = currentState.IsKeyDown(Keys.LeftShift) || currentState.IsKeyDown(Keys.RightShift);

            currentlyPressed = currentState.GetPressedKeys();
            previouslyPressed = oldState.GetPressedKeys();

            if (currentlyPressed.Length != previouslyPressed.Length)
            {
                keyHoldTimer = 0.0f;
                keyHeld = false;
                lastKeyHeld = FindLastKeyPressed();
            }

            if (!keyHeld && currentlyPressed.Length > 0)
            {
                keyHoldTimer += (float)time.ElapsedGameTime.TotalMilliseconds;
                if (keyHoldTimer > keyHoldWait)
                {
                    keyHeld = true;
                }
            }
        }
        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))
            {

            }
        }
        public void Code(KeyboardState keyboard, KeyboardState oldkeyboard, Extra extra)
        {
            if (keyboard.IsKeyDown(Keys.Enter) && oldkeyboard.IsKeyUp(Keys.Enter))
            {
                SelectionMade = true;
            }
            if (keyboard.IsKeyDown(Keys.Up))
            {
                if (selection > 0)
                    selection--;
            }
            if (keyboard.IsKeyDown(Keys.Down))
            {
                if (selection < 1)
                    selection++;
            }

            switch (selection)
            {
                case 0:
                    nimbusX = 140;
                    nimbusY = 400;
                    break;
                case 1:
                    nimbusX = 170;
                    nimbusY = 430;
                    break;
            }
            extra.NimbusRect = new Rectangle(nimbusX, nimbusY, 25, 25);
        }
        protected override void handleInput(KeyboardState keyboard, MouseState mouse)
        {
            base.handleInput(keyboard, mouse);

            if (DisplayGraph)
            {
                if (keyboard.IsKeyDown(Keys.D0))
                    clearPathDisplay();

                bool leftAlt = keyboard.IsKeyDown(Keys.LeftAlt);
                bool rightAlt = keyboard.IsKeyDown(Keys.RightAlt);

                if (leftAlt || rightAlt)
                {
                    bool leftMouseButton = mouse.LeftButton == ButtonState.Pressed;

                    if (leftMouseButton)
                    {
                        Vector2 mouseVec = AStarGame.MousePositionInWorld();
                        checkForClickedNode(mouseVec, leftAlt, rightAlt);

                        updatePathDisplay();
                    }
                }
            }
        }
Exemple #6
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 (xnaInput.GamePad.GetState(PlayerIndex.One).Buttons.Back == xnaInput.ButtonState.Pressed || xnaInput.Keyboard.GetState().IsKeyDown(xnaInput.Keys.Escape))
            {
                Exit();
            }
            xnaInput.KeyboardState state = xnaInput.Keyboard.GetState();

            if (state.IsKeyDown(xnaInput.Keys.Left))
            {
                Camera.Move(new Vector2(1, 0) * CAMERASPEED);
            }
            if (state.IsKeyDown(xnaInput.Keys.Right))
            {
                Camera.Move(new Vector2(-1, 0) * CAMERASPEED);
            }
            if (state.IsKeyDown(xnaInput.Keys.Up))
            {
                Camera.Move(new Vector2(0, 1) * CAMERASPEED);
            }
            if (state.IsKeyDown(xnaInput.Keys.Down))
            {
                Camera.Move(new Vector2(0, -1) * CAMERASPEED);
            }
            xnaInput.KeyboardState lastFrame = keyboardState;
            keyboardState = xnaInput.Keyboard.GetState();

            if (keyboardState.IsKeyDown(xnaInput.Keys.D1))
            {
                lineDrawer.NumberBeingDrawn = 0;
            }
            if (keyboardState.IsKeyDown(xnaInput.Keys.D2))
            {
                lineDrawer.NumberBeingDrawn = 1;
            }
            if (keyboardState.IsKeyDown(xnaInput.Keys.D3))
            {
                lineDrawer.NumberBeingDrawn = 2;
            }
            if (keyboardState.IsKeyDown(xnaInput.Keys.D4))
            {
                lineDrawer.NumberBeingDrawn = 3;
            }

            if (keyboardState.IsKeyUp(xnaInput.Keys.A) && lastFrame.IsKeyDown(xnaInput.Keys.A))
            {
                if (lineDrawer.DrawSingle)
                {
                    lineDrawer.DrawSingle = false;
                }
                else
                {
                    lineDrawer.DrawSingle = true;
                }
            }



            base.Update(gameTime);
        }
Exemple #7
0
 public static void Handler(KeyboardState KeyState, GameTime gameTime)
 {
     float _speed = 5;
     //Clear attack state on every update
     _attack = false;
     if (KeyState.IsKeyDown(Keys.W) | KeyState.IsKeyDown(Keys.Up))
     {
         Player.hiLocation.Y = Player.hiLocation.Y - _speed;
         //Move up
     }
     if (KeyState.IsKeyDown(Keys.A) | KeyState.IsKeyDown(Keys.Left))
     {
         //Move left
         Player.hiLocation.X = Player.hiLocation.X - _speed;
     }
     if (KeyState.IsKeyDown(Keys.S) | KeyState.IsKeyDown(Keys.Down))
     {
         //Move down
         Player.hiLocation.Y = Player.hiLocation.Y + _speed;
     }
     if (KeyState.IsKeyDown(Keys.D) | KeyState.IsKeyDown(Keys.Right))
     {
         //Move right
         Player.hiLocation.X = Player.hiLocation.X + _speed;
     }
     if (KeyState.IsKeyDown(Keys.Space))
     {
         //Attack
         if (attackHold <= 250 && attackWait <= 0)
         {
             //If not held attack
             _attack = true;
             attackHold++;
             timer = ((int)250 - (int)attackHold).ToString();
         }
         if(attackHold >= 250)
         {
             //If held to long block attack for 125 frames
             attackHold = 0;
             attackWait = 125;
             timer = "125C";
         }
     }
     if(KeyState.IsKeyUp(Keys.Space) && attackWait <= 0 || PositionChecker.dead)
     {
         //Reset hold and pause on key up
         attackHold = 0;
         attackWait = 0;
         timer = "250";
     }
     if (attackWait > 0)
     {
         timer = String.Format("{0}C", attackWait.ToString());
         attackWait--;
     }
     if (KeyState.IsKeyDown(Keys.F1) && Game1.debug)
         Game1.spawn = !Game1.spawn;
     //Validate new position
     PositionChecker.PosChecker();
 }
Exemple #8
0
        public override void Update()
        {
            keyboard = Keyboard.GetState();
            mouse = Mouse.GetState();
            if (keyboard.IsKeyDown(Keys.W))
            {
                position.Y -= speed;
            }
            if (keyboard.IsKeyDown(Keys.A))
            {
                position.X -= speed;
            }
            if (keyboard.IsKeyDown(Keys.D))
            {
                position.X += speed;
            }
            if (keyboard.IsKeyDown(Keys.S))
            {
                position.Y += speed;
            }

            rotation = point_direction(position.X, position.Y, mouse.X,mouse.Y);

            prevKeyBoard = keyboard;
            prevMouse = mouse;
            base.Update();
        }
Exemple #9
0
        public void Update(KeyboardState keyboard, MouseState mouse, Engine engine)
        {
            // Rortational Origin
            Rectangle originRect = new Rectangle((int) position.X, (int) position.Y,
                (int) texture.Width, (int) texture.Height);
            origin = new Vector2(originRect.Width / 2, originRect.Height / 2);

            int playerSpeed = 2;

            if (keyboard.IsKeyDown(Keys.A))
                position.X -= playerSpeed;

            if (keyboard.IsKeyDown(Keys.D))
                position.X += playerSpeed;

            if (keyboard.IsKeyDown(Keys.W))
                position.Y -= playerSpeed;

            if (keyboard.IsKeyDown(Keys.S))
                position.Y += playerSpeed;

            float deltaY = mouse.Y - position.Y;
            float deltaX = mouse.X - position.X;
            float radians = (float) Math.Atan2(deltaY, deltaX);
            setRotation(radians);
        }
Exemple #10
0
        public override void Update()
        {
            Microsoft.Xna.Framework.Input.KeyboardState stateKey = Keyboard.GetState();

            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.Up))
            {
                jump = true;
            }
            if (stateKey.IsKeyUp(Keys.Up))
            {
                jump = false;
            }
        }
        private void HandleKeyboardInput(KeyboardState keyState)
        {
            if (keyState.IsKeyDown(Keys.Up))
            {
                playerSprite.Velocity += new Vector2(0, -1);
            }

            if (keyState.IsKeyDown(Keys.Down))
            {
                playerSprite.Velocity += new Vector2(0, 1);
            }

            if (keyState.IsKeyDown(Keys.Left))
            {
                playerSprite.Velocity += new Vector2(-1, 0);
            }

            if (keyState.IsKeyDown(Keys.Right))
            {
                playerSprite.Velocity += new Vector2(1, 0);
            }

            if (keyState.IsKeyDown(Keys.Space))
            {
                FireShot();
            }
        }
Exemple #12
0
        public void Update(GameTime gameTime, Vector2 mapSize)
        {
            lastKeyboardState = keyboardState;
            keyboardState = Keyboard.GetState();

            position = new Vector2((int)deplacement.X * 16, (int)deplacement.Y * 16);

            //choisis la texture
            if (keyboardState.IsKeyDown(Keys.F5) && lastKeyboardState.IsKeyUp(Keys.F5))
                Texture = ressource.ARBRE;

            else if (keyboardState.IsKeyDown(Keys.F6) && lastKeyboardState.IsKeyUp(Keys.F6))
                Texture = ressource.SOL;

            else if (keyboardState.IsKeyDown(Keys.F7) && lastKeyboardState.IsKeyUp(Keys.F7))
                Texture = ressource.STATUT;

            //deplace le curseur
            if (keyboardState.IsKeyDown(Keys.J) && lastKeyboardState.IsKeyUp(Keys.J) && position.X > 0)
                deplacement.X--;

            if (keyboardState.IsKeyDown(Keys.L) && lastKeyboardState.IsKeyUp(Keys.L) && position.X < mapSize.X - 1)
                deplacement.X++;

            if (keyboardState.IsKeyDown(Keys.I) && lastKeyboardState.IsKeyUp(Keys.I) && position.Y > 0)
                deplacement.Y--;

            if (keyboardState.IsKeyDown(Keys.K) && lastKeyboardState.IsKeyUp(Keys.K) && position.Y < mapSize.Y - 1)
                deplacement.Y++;
        }
Exemple #13
0
        private void UpdateMovement(KeyboardState aCurrentKeyboardState)
        {
            if (_currentState != State.Moving) return;

            _speed = Vector2.Zero;
            _direction = Vector2.Zero;

            if (_isPlayer1)
            {
                if (aCurrentKeyboardState.IsKeyDown(Keys.W))
                {
                    _speed.Y = BumperSpeed;
                    _direction.Y = MoveUp;
                }
                else if (aCurrentKeyboardState.IsKeyDown(Keys.S))
                {
                    _speed.Y = BumperSpeed;
                    _direction.Y = MoveDown;
                }
            }
            else
            {
                if (aCurrentKeyboardState.IsKeyDown(Keys.Up))
                {
                    _speed.Y = BumperSpeed;
                    _direction.Y = MoveUp;
                }
                else if (aCurrentKeyboardState.IsKeyDown(Keys.Down))
                {
                    _speed.Y = BumperSpeed;
                    _direction.Y = MoveDown;
                }
            }
        }
Exemple #14
0
 internal override void Update(GameTime gameTime)
 {
     NeedDraw = true;
     NeedUpdate = true;
     currentKey = Keyboard.GetState();
     if (currentKey.IsKeyDown(Keys.D1) && prevKey.IsKeyUp(Keys.D1))
     {
         _GLOBAL.GameStateManager.activate(new Sample1());
         NeedDraw = false;
         NeedUpdate = false;
     }
     else if (currentKey.IsKeyDown(Keys.D2) && prevKey.IsKeyUp(Keys.D2))
     {
         _GLOBAL.GameStateManager.activate(new Sample2());
         NeedDraw = false;
         NeedUpdate = false;
     }
     else if (currentKey.IsKeyDown(Keys.Escape) && prevKey.IsKeyUp(Keys.Escape))
     {
         _GLOBAL.GameStateManager.activate(new Opening());
         NeedDraw = false;
         NeedUpdate = false;
         _GLOBAL.inGameState = false;
     }
     prevKey = currentKey;
 }
Exemple #15
0
        /// <summary>
        /// This function updates the game state.
        /// </summary>
        /// <param name="currentKey">current key press</param>
        public void Update(KeyboardState currentKey)
        {
            if (currentKey.IsKeyDown(Keys.Escape) && !previousKey.IsKeyDown(Keys.Escape)) //if the escape key is pressed
            {
                back = true; //inform higher class to iterate back to main menu screen
            }
            else if (currentKey.IsKeyDown(Keys.Enter) && !previousKey.IsKeyDown(Keys.Enter) && !ignore) //if the enter key is pressed
            {
                exit = true; //exit the screen and proceed
            }
            else if (currentKey.IsKeyDown(Keys.Up) && !previousKey.IsKeyDown(Keys.Up)) //if the up key is pressed
            {
                if (selection != 0) //if the selection is not already at the top
                    selection--; //move selection up
            }
            else if (currentKey.IsKeyDown(Keys.Down) && !previousKey.IsKeyDown(Keys.Down)) //if the down key is pressed
            {
                if (selection != 2) //if the selection is not already at the bottom
                    selection++; //move selection down
            }

            toggleRectangle.Y = changeSelection(); //move the toggle texture to the new selection

            previousKey = currentKey; //set the previous key state

            if (ignore) //if the frst iteration has completed
                ignore = false; //allow program to enter if statement
        }
 public override void Update(GameTime gameTime, KeyboardState kbs, MouseState ms)
 {
     //_PlayerCharacter.Update(gameTime, kbs, ms);
     _ComputerCharacter.Update(gameTime, kbs, ms);
     _Ground.Update(gameTime, kbs, ms);
     Vector3 newCameraPos = _Camera.CameraPosition;
     if(kbs.IsKeyDown(Keys.Up))
     {
         newCameraPos.Y++;
     }
     if (kbs.IsKeyDown(Keys.Down))
     {
         newCameraPos.Y--;
     }
     if (kbs.IsKeyDown(Keys.Left))
     {
         newCameraPos.X--;
     }
     if (kbs.IsKeyDown(Keys.Right))
     {
         newCameraPos.X++;
     }
     if (kbs.IsKeyDown(Keys.Z))
     {
         newCameraPos.Z--;
     }
     if (kbs.IsKeyDown(Keys.X))
     {
         newCameraPos.Z++;
     }
     _Camera.CameraPosition = newCameraPos;
     _Camera.Update(gameTime, kbs, ms);
 }
Exemple #17
0
        private void UpdateMovement(KeyboardState aCurrentKeyboardState)
        {
            m_playerSpeed = Vector2.Zero;
            m_direction = Vector2.Zero;

            if (aCurrentKeyboardState.IsKeyDown(Keys.A) == true)
            {
                m_playerSpeed.X = SPEED;
                m_direction.X = MOVE_LEFT;
            }
            else if (aCurrentKeyboardState.IsKeyDown(Keys.D) == true)
            {
                m_playerSpeed.X = SPEED;
                m_direction.X = MOVE_RIGHT;
            }

            if (aCurrentKeyboardState.IsKeyDown(Keys.W) == true)
            {
                m_playerSpeed.Y = SPEED;
                m_direction.Y = MOVE_UP;
            }
            else if (aCurrentKeyboardState.IsKeyDown(Keys.S) == true)
            {
                m_playerSpeed.Y = SPEED;
                m_direction.Y = MOVE_DOWN;
            }
        }
        void CheckCollison(int x, int y,Game1 game)
        {
            keyboardState = Keyboard.GetState();
            // Console.WriteLine("Checking collison");
            if ((50 * x) < game.player.position.X + (game.player.PlayerTexture.Width) /2 && (50 * x) + 50 > game.player.position.X &&
                 (50 * y) < game.player.position.Y + (game.player.PlayerTexture.Height) /2 && (50 * y) + 50 > game.player.position.Y)
            {

                if (keyboardState.IsKeyDown(Keys.W))
                {
                    game.player.position.Y += game.player.speed * 2;
                }
                if (keyboardState.IsKeyDown(Keys.S))
                {
                    game.player.position.Y -= game.player.speed * 2;
                }
                if (keyboardState.IsKeyDown(Keys.D))
                {
                    game.player.position.X -= game.player.speed * 2;
                }
                if (keyboardState.IsKeyDown(Keys.A))
                {
                    game.player.position.X += game.player.speed * 2;
                }
            }
        }
        protected virtual void HandleInput(GameTime gameTime)
        {
            keyState = Keyboard.GetState();

            Vector2 force = Vector2.Zero;
            if (keyState.IsKeyDown(Keys.A))
            {
                force.X -= forcePower * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (keyState.IsKeyDown(Keys.D))
            {
                force.X += forcePower * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (keyState.IsKeyDown(Keys.W))
            {
                force.Y -= forcePower * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (keyState.IsKeyDown(Keys.S))
            {
                force.Y += forcePower * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            body.ApplyLinearImpulse(force, body.Position);

            //oldState = keyState;
        }
Exemple #20
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;
        }
        private void UpdateMovement(KeyboardState aCurrentKeyboardState)
        {
            if (aCurrentKeyboardState.IsKeyDown(Keys.Left) == true)
            {
                Left = !Left;
                Right = false;

            }
            else if (aCurrentKeyboardState.IsKeyDown(Keys.Right) == true)
            {
                Right = !Right;
                Left = false;

            }

            if (aCurrentKeyboardState.IsKeyDown(Keys.Up) == true)
            {
                Up = !Up;
                Down = false;

            }
            else if (aCurrentKeyboardState.IsKeyDown(Keys.Down) == true)
            {
               Down = !Down;
               Up  = false;

            }

                //Reset movement to not moving
            if (aCurrentKeyboardState.IsKeyUp(Keys.Down) == true)
            {

                Down = false;
            }
            if (aCurrentKeyboardState.IsKeyUp(Keys.Up) == true)
            {

                Up = false;
            }
            if (aCurrentKeyboardState.IsKeyUp(Keys.Left) == true)
            {

                Left = false;
            }
            if (aCurrentKeyboardState.IsKeyUp(Keys.Right) == true)
            {

                Right = false;
            }

            //Update movement
            if (Right)
                rectangle.X++;
            if (Left)
                rectangle.X--;
            if (Up)
                rectangle.Y--;
            if (Down)
                rectangle.Y++;
        }
        public void Update(KeyboardState keyboard)
        {
            if (keyboard.IsKeyDown(up))
            {
                player.MoveUp();
            }
            else if (keyboard.IsKeyDown(down))
            {
                player.MoveDown();
            }
            else if (keyboard.IsKeyDown(left))
            {
                player.MoveLeft();
            }
            else if (keyboard.IsKeyDown(right))
            {
                player.MoveRight();
            }
            else
            {
                player.MoveStop();
            }

            if (keyboard.IsKeyDown(run))
            {
                player.Run();
            }
            else
            {
                player.Walk();
            }
        }
        public void Update(KeyboardState clavier, Menu menu)
        {
            if (clavier.IsKeyDown(Keys.Escape))
                pauseactive = true;

            if (clavier.IsKeyUp(Keys.Escape) && pauseactive)
            {
                if (Etat == etat.InGame)
                {
                    Etat = etat.Pause;
                    menu.mode = Menu.Mode.Pause;
                }

                pauseactive = false;
            }

            if (clavier.IsKeyDown(Keys.Space))
                combatactive = true;

            if (clavier.IsKeyUp(Keys.Space) && combatactive)
            {
                if (Etat == etat.InGame)
                {
                    combat = !combat;
                }

                combatactive = false;
            }
        }
Exemple #24
0
        //Update Method
        public void Update(GameTime gameTime)
        {
            KeyboardState keyState = Keyboard.GetState(); //create a keyboard state variable to hold current keyboard state
            if (keyState.IsKeyDown(Keys.Back) && keyState.IsKeyDown(Keys.Back))
            {
                gameState.CurrentScreen = Screen.StartScreen;
            }
            lastState = keyState;

            if (keyState.IsKeyDown(Keys.S) && lastState.IsKeyDown(Keys.S)) // if s key is pressed
            {
                gameState.CurrentScreen = Screen.StartScreen; // switches to start screen
            }
            if (keyState.IsKeyDown(Keys.G) && lastState.IsKeyDown(Keys.G)) // if G key is pressed
            {
                gameState.StartGame("test.txt", "level2"); // calls start game method to switch to game
            }
            if (keyState.IsKeyDown(Keys.O) && lastState.IsKeyDown(Keys.O))
            {
                gameState.SwitchOption(game);//calls switch option method to switch to option screen
            }
            if (keyState.IsKeyDown(Keys.L) && lastState.IsKeyDown(Keys.L))
            {
                gameState.SwitchLevel(game);
            }
            if (keyState.IsKeyDown(Keys.I) && lastState.IsKeyDown(Keys.I))
            {
                gameState.SwitchInstruct(game);
            }
            lastState = keyState; // assigns current keyboard state to the last keyboard state
        }
Exemple #25
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);
        }
        public void Update()
        {
            _curState = Keyboard.GetState();

            KeyLeftPressing = false;
            KeyRightPressing = false;
            KeyUpPressing = false;
            KeyDownPressing = false;

            if (_curState.IsKeyDown(Keys.A))
                KeyLeftPressing = true;
            else if (_curState.IsKeyDown(Keys.D))
                KeyRightPressing = true;

            if (_curState.IsKeyDown(Keys.W))
            {
                KeyUpPressing = true;
                KeyUpPressed = _prevState.IsKeyUp(Keys.W);
            }
            else if (_curState.IsKeyDown(Keys.S))
            {
                KeyDownPressing = true;
                KeyDownPressed = _prevState.IsKeyUp(Keys.S);
            }

            KeyJumpPressed = IsKeyClick(Keys.Space);
            KeyAttackPressed = IsKeyClick(Keys.J);
            KeySecondaryPressed = IsKeyClick(Keys.K);
            KeyStartPressed = IsKeyClick(Keys.Enter);

            _prevState = _curState;
        }
Exemple #27
0
        public void Update(GameTime gameTime)
        {
            _previousState = _currentState;
             _currentState = Keyboard.GetState();

             if (_currentState.IsKeyDown(Keys.Up))
                 position.Y -= player_movement_speed;
             if (_currentState.IsKeyDown(Keys.Right))
                 position.X += player_movement_speed;
             if (_currentState.IsKeyDown(Keys.Left))
                 position.X -= player_movement_speed;
             if (_currentState.IsKeyDown(Keys.Down))
                 position.Y += player_movement_speed;
              Rectangle = new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height);

              // If player pressed the gamepad thumbstick, move the sprite
              GamePadState gamepadState = GamePad.GetState(PlayerIndex.One);
              if (gamepadState.ThumbSticks.Left.X != 0)
                  position.X += gamepadState.ThumbSticks.Left.X;
              if (gamepadState.ThumbSticks.Left.Y != 0)
                  position.Y -= gamepadState.ThumbSticks.Left.Y;

             /*
              _currentMouseState = Mouse.GetState();

             mouse = new Rectangle(_currentMouseState.X, _currentMouseState.Y, mouse.Width+20, mouse.Height+20 );
              if (_currentMouseState.LeftButton == ButtonState.Pressed &&mouse.Intersects(position))
             {

                 position = new Rectangle(_currentMouseState.X,_currentMouseState.Y, 100, 100);
             }
            */
        }
Exemple #28
0
        static public void CheckKey(KeyboardState keyboardState)
        {
            changed = true;
            if (keyboardState.IsKeyDown(Keys.Up))
            {
                if (++characters[characterIndex] > 'Z')
                    characters[characterIndex] = 'A';

            } else if (keyboardState.IsKeyDown(Keys.Down))
            {
                if (--characters[characterIndex] < 'A')
                    characters[characterIndex] = 'Z';

            } else if (keyboardState.IsKeyDown(Keys.Left))
            {
                if (--characterIndex < 0)
                    characterIndex = characterNumber - 1;

            } else if (keyboardState.IsKeyDown(Keys.Right))
            {
                if (++characterIndex > characterNumber - 1)
                    characterIndex = 0;
            }

        }
Exemple #29
0
        public override void Update(GameTime gameTime)
        {
            newKeyState = Keyboard.GetState();

            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (newKeyState.IsKeyDown(leftKey))
                Movement(elapsed, -1);
            if (newKeyState.IsKeyDown(rightKey))
                Movement(elapsed, 1);
            if (newKeyState.IsKeyDown(shootKey) && oldKeyState.IsKeyUp(shootKey))
                Shoot();

            if (position.X < 0)
                position.X = 0;
            if (position.X > Globals.ScreenWidth - srcRect.Width)
                position.X = Globals.ScreenWidth - srcRect.Width;

            bounds.X = (int)position.X;
            bounds.Y = (int)position.Y;

            foreach (Bullet bullet in bullets)
            {
                bullet.Update(gameTime);

                if (!bullet.bounds.IsInsideScreen())
                {
                    bullets.Remove(bullet);
                    break;
                }
            }

            base.Update(gameTime);
            oldKeyState = newKeyState;
        }
Exemple #30
0
        /// <summary>
        /// Handles where to send what control to send the Input to, either
        /// a character, or a menu etc
        /// </summary>
        /// <param name="state">Where to send the input.</param>
        public void InputManager(GameState state)
        {
            kbState = Keyboard.GetState();

            //if the game is in the main gameplay mode
            if (state.GetType() == typeof(GameStateMain))
            {

                // Allows the game to exit
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                    this.Exit();

                else if (kbState.IsKeyDown(Keys.Escape))
                {
                    this.Exit();
                }

                else if (kbState.IsKeyDown(Keys.F) && oldKbState.IsKeyUp(Keys.F))
                {
                    FeedAction feeding = new FeedAction(session.user);
                    screenBG = Color.Aqua;
                    feeding.FeedPet(session.pet, new FoodFruit());
                }

                else if (kbState.IsKeyDown(Keys.Space) && oldKbState.IsKeyUp(Keys.Space))
                {
                    mSprite.GoToNextFrame();
                }
            }

            oldKbState = kbState;
        }
Exemple #31
0
        public bool[] Zwracanie2()
        {
            for (int i = 0; i < 5; i++)
            {
                tab[i] = false;               
            }
            keyboardState = Keyboard.GetState();
            if (keyboardState.IsKeyDown(Keys.W))
            {
                tab[(int)klawisz.Up] = true;               
            }
            if (keyboardState.IsKeyDown(Keys.S))
            {
                tab[(int)klawisz.Down] = true;
            }
            if (keyboardState.IsKeyDown(Keys.A))
            {
                tab[(int)klawisz.Left] = true;
            }

            if (keyboardState.IsKeyDown(Keys.D))
            {
                tab[(int)klawisz.Right] = true;
            }
            if (keyboardState.IsKeyDown(Keys.LeftControl))
            {
                tab[(int)klawisz.Action] = true;
            }
            return tab;
        }
Exemple #32
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 (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();
            keyBoardState = Keyboard.GetState();
            //Перемещение объекта
            if (keyBoardState.IsKeyDown(Keys.Up)) 
                position.Y -= 5;
            if (keyBoardState.IsKeyDown(Keys.Down))
                position.Y += 5;
            if (keyBoardState.IsKeyDown(Keys.Left))
                position.X -= 5;
            if (keyBoardState.IsKeyDown(Keys.Right))
                position.X += 5;
            //Рамки экрана
            if (position.X <= 0) 
                position.X = 0;
            if (position.Y <= 0)
                position.Y = 0;
            if (position.Y > graphics.PreferredBackBufferHeight -vader.Height)
                position.Y = graphics.PreferredBackBufferHeight - vader.Height;
            if (position.X > graphics.PreferredBackBufferWidth - vader.Width)
                position.X = graphics.PreferredBackBufferWidth - vader.Width;

            base.Update(gameTime);
        }
 private bool GetInternal0(XnaInput.KeyboardState st, Buttons btn)
 {
     return(btn switch
     {
         Buttons.A => st.IsKeyDown(XnaInput.Keys.Q),
         Buttons.B => st.IsKeyDown(XnaInput.Keys.E),
         Buttons.Start => st.IsKeyDown(XnaInput.Keys.Space),
         _ => false,
     });
Exemple #34
0
 public void UpdateKeyboard()
 {
     kNoEvent = true;
     Microsoft.Xna.Framework.Input.KeyboardState keyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();
     for (var i = 1; i <= (int)Microsoft.Xna.Framework.Input.Keys.VolumeUp; i++)
     {
         if (keyboardState.IsKeyDown((Keys)i))
         {
             keyState[i] = InputState.KeyDown;
             kNoEvent    = false;
         }
         else
         {
             if (keyState[i] == InputState.KeyDown)
             {
                 keyState[i] = InputState.KeyPress;
                 kNoEvent    = false;
             }
             else
             {
                 keyState[i] = InputState.None;
             }
         }
     }
 }
Exemple #35
0
 private void OnGameBaseKeyPress(Keys[] keys, Microsoft.Xna.Framework.Input.KeyboardState state)
 {
     if (state.IsKeyDown(Keys.F12))
     {
         IsGameRunning = false;
         Exit();
     }
     else if (keys.Length > 0)
     {
         OnKeyPress(keys, state);
     }
 }
        internal void updateInput(Microsoft.Xna.Framework.Input.KeyboardState currentKState, Microsoft.Xna.Framework.Input.KeyboardState previousKState)
        {
            if (currentKState.IsKeyDown(Keys.Up) && previousKState.IsKeyUp(Keys.Up))
            {
                incForward();
            }
            if (currentKState.IsKeyDown(Keys.Down) && previousKState.IsKeyUp(Keys.Down))
            {
                incBackward();
            }
            if (currentKState.IsKeyDown(Keys.Left) && previousKState.IsKeyUp(Keys.Left))
            {
                incLeft();
            }
            if (currentKState.IsKeyDown(Keys.Right) && previousKState.IsKeyUp(Keys.Right))
            {
                incRight();
            }

            if (currentKState.IsKeyDown(Keys.Space) && previousKState.IsKeyUp(Keys.Space))
            {
                reset();
            }
        }
Exemple #37
0
        private void UpdateKeyboard(TimeSpan timeElapsed)
        {
            XnaInput.KeyboardState keyboardState = XnaInput.Keyboard.GetState();

            if (keyboardState.IsKeyDown(XnaInput.Keys.Down))
            {
                movementVector += Vector2.UnitY;
            }
            else if (keyboardState.IsKeyDown(XnaInput.Keys.Up))
            {
                movementVector -= Vector2.UnitY;
            }

            if (keyboardState.IsKeyDown(XnaInput.Keys.Right))
            {
                movementVector += Vector2.UnitX;
            }
            else if (keyboardState.IsKeyDown(XnaInput.Keys.Left))
            {
                movementVector -= Vector2.UnitX;
            }

            Point newPosition = (movementVector * (float)timeElapsed.TotalSeconds * 25).ToPoint();

            if (newPosition.Equals(ViewPositionConsole.Position))
            {
                return;
            }

            // Do viewPosition.
            ViewPositionConsole.Position = newPosition;

            // Do realPosition.
            Font.Size.Deconstruct(out int x, out int y);
            RealPositionConsole.Position = (newPosition + new Point((x / 2), (y / 2))).PixelLocationToConsole(Font);
        }
Exemple #38
0
        //* -----------------------------------------------------------------------*
        /// <summary>入力状態更新のスレッドです。</summary>
        ///
        /// <returns>スレッドが実行される間、<c>true</c></returns>
        private IEnumerator <object> threadStateReflesh()
        {
            while (true)
            {
                yield return(null);

                bool[] bState = new bool[BUTTON_STATE.Length];
#if WINDOWS
                Microsoft.Xna.Framework.Input.KeyboardState stateKey =
                    Microsoft.Xna.Framework.Input.Keyboard.GetState();
                for (int i = 0; i < bState.Length; i++)
                {
                    bState[i] = stateKey.IsKeyDown(assignKeyboard[i]);
                }
                if (legacy != null)
                {
                    Microsoft.DirectX.DirectInput.JoystickState legacystate = legacy.state;
                    byte[] buttons = legacystate.GetButtons();
                    bState[( int )EDirType.Up]    = bState[( int )EDirType.Up] || (legacystate.Y < -600);
                    bState[( int )EDirType.Down]  = bState[( int )EDirType.Down] || (legacystate.Y > 600);
                    bState[( int )EDirType.Left]  = bState[( int )EDirType.Left] || (legacystate.X < -600);
                    bState[( int )EDirType.Right] = bState[( int )EDirType.Right] || (legacystate.X > 600);
                    for (int i = ( int )EDirType.__reserved; i < bState.Length; i++)
                    {
                        int nButtonID = assignLegacy[i - ( int )EDirType.__reserved];
                        bState[i] = bState[i] ||
                                    (buttons.Length > nButtonID && buttons[nButtonID] != 0);
                    }
                }
#else
                for (int i = 0; i < bState.Length; bState[i++] = false)
                {
                    ;
                }
#endif
                if (isUseXBOX360GamePad)
                {
                    GamePadState stateButton = GamePad.GetState(PlayerIndex.One);
                    Vector2      leftStick   = stateButton.ThumbSticks.Left;
                    if (leftStick.Length() > 0.7f)
                    {
                        double dAngle = Math.Atan2(leftStick.Y, leftStick.X);
                        bState[( int )EDirType.Up]    = bState[( int )EDirType.Up] || (dAngle <= MathHelper.PiOver4 * 3.5 && dAngle >= MathHelper.PiOver4 * 0.5);
                        bState[( int )EDirType.Down]  = bState[( int )EDirType.Down] || (dAngle >= MathHelper.PiOver4 * -3.5 && dAngle <= MathHelper.PiOver4 * -0.5);
                        bState[( int )EDirType.Left]  = bState[( int )EDirType.Left] || Math.Abs(dAngle) >= MathHelper.PiOver4 * 2.5;
                        bState[( int )EDirType.Right] = bState[( int )EDirType.Right] || Math.Abs(dAngle) <= MathHelper.PiOver4 * 1.5;
                    }
                    else
                    {
                        bState[( int )EDirType.Up]    = bState[( int )EDirType.Up] || stateButton.IsButtonDown(Buttons.DPadUp);
                        bState[( int )EDirType.Down]  = bState[( int )EDirType.Down] || stateButton.IsButtonDown(Buttons.DPadDown);
                        bState[( int )EDirType.Left]  = bState[( int )EDirType.Left] || stateButton.IsButtonDown(Buttons.DPadLeft);
                        bState[( int )EDirType.Right] = bState[( int )EDirType.Right] || stateButton.IsButtonDown(Buttons.DPadRight);
                    }
                    for (int i = ( int )EDirType.__reserved; i < bState.Length; i++)
                    {
                        bState[i] = bState[i] || stateButton.IsButtonDown(assignXBOX360[i - ( int )EDirType.__reserved]);
                    }
                }
                for (int i = 0; i < bState.Length; i++)
                {
                    BUTTON_STATE[i].refresh(bState[i]);
                }
            }
        }
Exemple #39
0
        public void UpdateControls()
        {
            this.mouseState    = Mouse.GetState(Program.MainView.Window);
            this.keyboardState = Keyboard.GetState();
            if (this.mouseState.Position != this.oldMouseState.Position)
            {
                cancelUnselectedBone = true;
            }
            if (this.mouseState.LeftButton == ButtonState.Pressed)
            {
                if (this.oldMouseState.LeftButton == ButtonState.Released)
                {
                    if (this.HighlightedBone)
                    {
                        if (selectedBone != this.HighlightedBoneParentID)
                        {
                            SelectBone(this.HighlightedBoneParentID);
                        }
                    }
                    else
                    {
                        cancelUnselectedBone = false;
                    }
                }
            }
            else if (!cancelUnselectedBone)
            {
                SelectBone(-1);
            }

            if (keyboardState.IsKeyDown(Keys.Left))
            {
                if (leftKeyCount == 0)
                {
                    leftKeyCount = 1;
                }
            }
            else
            {
                leftKeyCount = 0;
            }


            if (keyboardState.IsKeyDown(Keys.Right))
            {
                if (rightKeyCount == 0)
                {
                    rightKeyCount = 1;
                }
            }
            else
            {
                rightKeyCount = 0;
            }


            if (leftKeyCount == 1 || leftKeyCount > 20)
            {
                View.focusedObject.Skeleton.SelectBone(View.focusedObject.Skeleton.SelectedBone.ID - 1);
            }

            if (rightKeyCount == 1 || rightKeyCount > 20)
            {
                View.focusedObject.Skeleton.SelectBone(View.focusedObject.Skeleton.SelectedBone.ID + 1);
            }

            if (leftKeyCount > 0)
            {
                leftKeyCount++;
            }

            if (rightKeyCount > 0)
            {
                rightKeyCount++;
            }

            this.oldKeyboardState = keyboardState;
            this.oldMouseState    = mouseState;
        }
        /// <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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
            {
                this.Exit();
            }

            Microsoft.Xna.Framework.Input.KeyboardState keys = Keyboard.GetState();

            //--Zoom
            if (keys.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.O))
            {
                controller.ZoomIn();
            }
            else if (keys.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.P))
            {
                controller.ZoomOut();
            }
            //--

            //--Rotate
            if (keys.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.A))
            {
                controller.RotateX(MathHelper.ToRadians(keys.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift) ? -10 : 10));
            }
            else if (keys.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D))
            {
                controller.RotateY(MathHelper.ToRadians(keys.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift) ? -10 : 10));
            }
            else if (keys.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.S))
            {
                controller.RotateZ(MathHelper.ToRadians(keys.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift) ? -10 : 10));
            }
            //--

            //View
            if (keys.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D1))
            {
                controller.View1();
            }
            else if (keys.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D2))
            {
                controller.View2();
            }
            //--

            //Move
            if (keys.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up))
            {
                controller.MoveUp();
            }
            else if (keys.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down))
            {
                controller.MoveDown();
            }
            else if (keys.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left))
            {
                controller.MoveLeft();
            }
            else if (keys.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right))
            {
                controller.MoveRight();
            }
            //--

            base.Update(gameTime);
        }
Exemple #41
0
 public static bool IsKeyDown(input.Keys key)
 {
     return(currentKeyboard.IsKeyDown(key));
 }
 public bool KeyPressed(Keys k)
 {
     return(currentKeyboardState.IsKeyDown(k) &&
            previousKeyboardState.IsKeyUp(k));
 }
Exemple #43
0
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime, Microsoft.Xna.Framework.Input.KeyboardState keyboard, Microsoft.Xna.Framework.Input.MouseState mouse)
        {
            if (findingNetwork)
            {
                if (introTime > 8.1f)
                {
                    introTime -= (float)gameTime.ElapsedGameTime.TotalSeconds * 4;
                }
                networkTime -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (networkTime < lastNetTime)
                {
                    lastNetTime--;
                    Network.FindServer();
                    if (Network.IsConnected)
                    {
                        Login();
                    }
                }
                if (networkTime <= 0)
                {
                    findingNetwork = false;
                    lastNetTime    = 10;
                    netFailString  = "No Network Found.";
                }
            }
            else
            {
                introTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (networkTime < 10)
                {
                    networkTime += (float)gameTime.ElapsedGameTime.TotalSeconds * 2;
                }
            }
            if (introTime < 0 && introTime > -1)
            {
                MobileFortressClient.Game.Exit();
            }
            if (introTime > 8)
            {
                Manager.Update(gameTime, mouse);
                if (keyboard.IsKeyDown(Keys.Enter))
                {
                    if (!loginMenuScroll)
                    {
                        loginButton.DoClick();
                    }
                    else
                    {
                        loginConfirmButton.DoClick();
                    }
                }
            }
            else
            {
                if (keyboard.IsKeyDown(Keys.Escape) || keyboard.IsKeyDown(Keys.Enter))
                {
                    introTime = 8;
                }
            }
            Viewport viewport = MobileFortressClient.Game.GraphicsDevice.Viewport;

            if (loginMenuScroll)
            {
                Color disabledColor = new Color(96, 64, 64);
                loginButton.canClick   = false;
                loginButton.color      = Color.Lerp(loginButton.color, disabledColor, 0.3f);
                optionsButton.canClick = false;
                optionsButton.color    = Color.Lerp(optionsButton.color, disabledColor, 0.3f);
                exitButton.canClick    = false;
                exitButton.color       = Color.Lerp(exitButton.color, disabledColor, 0.3f);
                if (scrolledAmt < loginMenu.Height)
                {
                    foreach (UIElement element in Manager.Elements)
                    {
                        element.dimensions.Y -= 4;
                    }
                    scrolledAmt += 4;
                }
                loginDimensions.Y = viewport.Height - scrolledAmt;
            }
            else
            {
                loginButton.canClick   = true;
                loginButton.color      = Color.Lerp(loginButton.color, Color.LightGray, 0.3f);
                optionsButton.canClick = true;
                optionsButton.color    = Color.Lerp(optionsButton.color, Color.LightGray, 0.3f);
                exitButton.canClick    = true;
                exitButton.color       = Color.Lerp(exitButton.color, Color.LightGray, 0.3f);
                if (scrolledAmt > 0)
                {
                    foreach (UIElement element in Manager.Elements)
                    {
                        element.dimensions.Y += 4;
                    }
                    scrolledAmt -= 4;
                }
                loginDimensions.Y = viewport.Height - scrolledAmt;
            }
        }
Exemple #44
0
        static void KeyboardUpdate(double dt)
        {
            xnainput.KeyboardState newstate = xnainput.Keyboard.GetState();
            for (int i = 0; i < (int)config.NUM_KEY; i++)
            {
                if (!(oldKeyboardState.IsKeyDown(KeyboardConfig[i])) &&
                    newstate.IsKeyDown(KeyboardConfig[i]))                         //今押された
                {
                    onKeyDown[i] = true;
                    onKeyUp[i]   = false;
                    continue;                    //今押されたって事は、今離されたかどうかなんて聞くまでも無いだろって事で。
                }
                else
                {
                    onKeyDown[i] = false;
                }
                if (oldKeyboardState.IsKeyDown(KeyboardConfig[i]) &&
                    !(newstate.IsKeyDown(KeyboardConfig[i])))                         //今離された
                {
                    onKeyUp[i] = true;
                    keyTime[i] = 0.0;
                }
                else
                {
                    onKeyUp[i] = false;
                }
            }
            for (int i = 0; i < (int)config.NUM_KEY; i++)
            {
                if (newstate.IsKeyDown(KeyboardConfig[i]))                  //古い状態を捨てて新しい状態に切り替え
                {
                    Key[i]      = true;
                    keyTime[i] += dt;
                }
                else
                {
                    Key[i] = false;
                }
            }
            int horizontal = 0;

            if (newstate.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right))
            {
                horizontal++;
            }
            if (newstate.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left))
            {
                horizontal--;
            }
            int vertical = 0;

            if (newstate.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up))
            {
                vertical++;
            }
            if (newstate.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down))
            {
                vertical--;
            }
            V.X = (float)horizontal;
            V.Y = (float)-vertical;            //2DでY軸が下向きのためそれの補正
            if (V.LengthSquared() != 0)
            {
                V = Vector2.Normalize(V);
            }
            Direction oldDirection = stickDirection;

            if (V.Y <= -0.7071)                //0.7071==√2
            {
                stickDirection = Direction.UP; //上
            }
            else if (V.Y >= 0.7071)
            {
                stickDirection = Direction.DOWN;                //下
            }
            else if (V.X <= -0.7071)
            {
                stickDirection = Direction.LEFT;                //左
            }
            else if (V.X >= 0.7071)
            {
                stickDirection = Direction.RIGHT;                //右
            }
            else
            {
                stickDirection = Direction.NEWTRAL;               //ニュートラル
            }
            if (oldDirection == stickDirection)
            {
                stickTime += dt;
                onStickDirectionChanged = false;
            }
            else
            {
                stickTime = 0.0;
                onStickDirectionChanged = true;
            }
            oldKeyboardState = newstate;
        }
Exemple #45
0
        public void UpdateMouse()
        {
            mouseState    = Mouse.GetState(Program.MainView.Window);
            keyboardState = Keyboard.GetState();

            if (mouseState.LeftButton == ButtonState.Pressed)
            {
            }
            else if (oldMouseState.LeftButton == ButtonState.Pressed)
            {
                this.cmbX.Highlight = false;
                this.cmbY.Highlight = false;
                this.cmbZ.Highlight = false;
            }

            if (keyboardState.IsKeyDown(Keys.LeftShift))
            {
                if (middleButtonPress > 0)
                {
                    middleButtonPress++;
                }
                if (middleButtonPress < 0)
                {
                    middleButtonPress--;
                }

                if (mouseState.MiddleButton == ButtonState.Pressed)
                {
                    if (middleButtonPress < 0)
                    {
                        for (int i = 0; i < View.focusedObject.Skeleton.Bones.Length; i++)
                        {
                            View.focusedObject.Skeleton.Bones[i].RotateX_Addition = 0;
                            View.focusedObject.Skeleton.Bones[i].RotateY_Addition = 0;
                            View.focusedObject.Skeleton.Bones[i].RotateZ_Addition = 0;
                        }
                        middleButtonPress = 0;
                    }

                    if (middleButtonPress == 0)
                    {
                        middleButtonPress = 1;
                    }
                }
                else
                {
                    if (middleButtonPress > 0 && middleButtonPress < 8)
                    {
                        middleButtonPress = -1;
                    }
                    if (middleButtonPress > 0 || middleButtonPress < -8)
                    {
                        middleButtonPress = 0;
                    }
                }
                if (middleButtonPress > 0)
                {
                    View.focusedObject.Skeleton.SelectedBone.RotateX_Addition = 0;
                    View.focusedObject.Skeleton.SelectedBone.RotateY_Addition = 0;
                    View.focusedObject.Skeleton.SelectedBone.RotateZ_Addition = 0;
                }

                if (mouseState.LeftButton == ButtonState.Pressed)
                {
                    int xDiff = (mouseState.Position.X - oldMouseState.X);
                    int yDiff = (mouseState.Position.Y - oldMouseState.Y);
                    this.cmbX.Highlight = xDiff != 0;
                    this.cmbY.Highlight = yDiff != 0;

                    View.focusedObject.Skeleton.SelectedBone.RotateX_Addition += xDiff / 100f;
                    View.focusedObject.Skeleton.SelectedBone.RotateY_Addition += yDiff / 100f;
                }
                if (mouseState.RightButton == ButtonState.Pressed)
                {
                    int zDiff = (mouseState.Position.Y - oldMouseState.Y);
                    this.cmbZ.Highlight = zDiff != 0;
                    View.focusedObject.Skeleton.SelectedBone.RotateZ_Addition += zDiff / 100f;
                }
            }
            else if (oldKeyboardState.IsKeyDown(Keys.LeftShift))
            {
                this.cmbX.Highlight = false;
                this.cmbY.Highlight = false;
                this.cmbZ.Highlight = false;
            }
            oldKeyboardState = keyboardState;
            oldMouseState    = mouseState;
        }
Exemple #46
0
        void updateCamera(GameTime gameTime)
        {
            colision_map.load_map();


            JoystickState state = new JoystickState();

            bool[]        buttonData;
            int[]         hats, uv;
            SlimDX.Result r;


            try
            {
                if ((r = joystick.Acquire()).IsFailure)
                {
                    throw new DirectInputException(r);
                }

                if ((joystick.Capabilities.Flags & DeviceFlags.PolledDevice) != 0)
                {
                    if ((r = joystick.Poll()).IsFailure)
                    {
                        throw new DirectInputException(r);
                    }
                }


                state = joystick.GetCurrentState();
                //    state = joystick.GetCurrentState();
                if (SlimDX.Result.Last.IsFailure)
                {
                    throw new DirectInputException(SlimDX.Result.Last);
                }

                buttonData = state.GetButtons();
                hats       = state.GetPointOfViewControllers();
                uv         = state.GetForceSliders();
            }
            catch (DirectInputException e)
            {
                int I = 0;
            }
            if (state.X != 0)
            {
                xval = state.X;
            }
            if (state.Y != 0)
            {
                yval = (-1 * (state.Y - 5000));
            }

            if (state.RotationZ < 1)
            {
                bval = -1 * (state.RotationZ);
            }
            float iangle;

            iangle = (((float)xval)) * 1.4f / 5000.0f / 3.1415f;
            float iaccel;

            iaccel = yval / 100.0f + 1.0f;
            iaccel = (float)Math.Log10((double)iaccel) + 1.0f;
            iaccel = (float)Math.Pow(2, (double)iaccel) - 2;
            float daccel;

            daccel = bval / 100.0f + 1.0f;
            daccel = (float)Math.Log10((double)daccel) + 1.0f;
            daccel = (float)Math.Pow(3, (double)daccel) - 3;

            // Get the new keyboard and mouse state
            Microsoft.Xna.Framework.Input.MouseState    mouseState = Microsoft.Xna.Framework.Input.Mouse.GetState();
            Microsoft.Xna.Framework.Input.KeyboardState keyState   = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            // Determine how much the camera should turn
            float deltaX = ((float)lastMouseState.X - (float)mouseState.X) * 0.02f;
            float deltaY = ((float)lastMouseState.Y - (float)mouseState.Y) * 0.02f;

            // Rotate the camera
            /// ((FreeCamera)camera).Rotate(deltaX * .01f, deltaY * .01f);

            double steer = 0;

            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.I))
            {
                driver_pos = 2.42f;
                mode       = 1;
                dis        = 1.36f;
                yalt       = 1.45f;
                angle      = -2.9115f;
                yxalt      = 1.23f;
                rangle     = -1.45f; // -2.34f;
                langle     = 1.45f;  //2.34f;
            }

            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape))
            {
                Bus_models[0].position = new Microsoft.Xna.Framework.Vector3(1228.729f, 0.2f, -3246.247f);
            }
            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.O))
            {
                mode  = 0;
                dis   = 13.5f;
                yalt  = 6.0f;
                angle = 0;
                yxalt = 2.44f;
            }

            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.P))
            {
                mode  = 0;
                dis   = 4.3f;
                yalt  = 1.2f;
                angle = 4.77f;
                yxalt = 1.4f;
            }

            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D7))
            {
                rangle += .010f;
            }
            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D8))
            {
                rangle -= .010f;
            }
            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D9))
            {
                langle += .0100f;
            }
            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D0))
            {
                langle -= .0100f;                                                             //100 km/hr
            }
            if (mode == 0)
            {
                if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Y))
                {
                    driver_pos += .010f;
                }
                if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.U))
                {
                    driver_pos -= .010f;
                }
            }
            else
            {
                if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Y))
                {
                    driver_pos += .0010f;
                }
                if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.U))
                {
                    driver_pos -= .0010f;
                }
            }

            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D5))
            {
                driver_posx += .0010f;
            }
            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D6))
            {
                driver_posx -= .0010f;
            }


            // Determine in which direction to move the camera
            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Z))
            {
                dis += .010f;
            }
            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.X))
            {
                dis -= .010f;
            }
            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.C))
            {
                dis += .0200f;
            }
            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.V))
            {
                dis -= .0200f;                                                            //100 km/hr
            }
            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Q))
            {
                yalt += 5.0f;
            }
            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.W))
            {
                yalt += .010f;
            }
            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.S))
            {
                yalt -= .010f;
            }
            if (mode == 0)
            {
                if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.A))
                {
                    angle += .02f;
                }
                if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D))
                {
                    angle -= .02f;
                }
            }
            else
            {
                if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D))
                {
                    angle += .01f;
                }
                if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.A))
                {
                    angle -= .01f;
                }
            }
            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.G))
            {
                yxalt -= 0.010f;
            }
            if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.T))
            {
                yxalt += 0.010f;
            }


            Bus_models[0].ProcessKeyboard(gameTime, iangle, iaccel, daccel);
            Bus_models[0].Update(gameTime);
            Bus_models[0].doit();

            if (mode == 1)
            {
                tempbus_Position_I = new Microsoft.Xna.Framework.Vector3((float)(Bus_models[0].Position.X - driver_pos * Math.Sin(Bus_models[0].Rotation.Y) - driver_posx * Math.Cos(Bus_models[0].Rotation.Y)), yalt, (float)(Bus_models[0].Position.Z - driver_pos * Math.Cos(Bus_models[0].Rotation.Y) + driver_posx * Math.Sin(Bus_models[0].Rotation.Y)));
                tempbus_Position_C = new Microsoft.Xna.Framework.Vector3((float)(Bus_models[0].Position.X - driver_pos * Math.Sin(Bus_models[0].Rotation.Y) - driver_posx * Math.Cos(Bus_models[0].Rotation.Y)), yalt, (float)(Bus_models[0].Position.Z - driver_pos * Math.Cos(Bus_models[0].Rotation.Y) + driver_posx * Math.Sin(Bus_models[0].Rotation.Y)));
                tempbus_Position_D = new Microsoft.Xna.Framework.Vector3((float)(Bus_models[0].Position.X - driver_pos * Math.Sin(Bus_models[0].Rotation.Y) - driver_posx * Math.Cos(Bus_models[0].Rotation.Y)), yalt, (float)(Bus_models[0].Position.Z - driver_pos * Math.Cos(Bus_models[0].Rotation.Y) + driver_posx * Math.Sin(Bus_models[0].Rotation.Y)));

                // ((TargetCamera)camera).Position = target;
                //  ((TargetCamera)camera).Target = new Vector3(car_position.X, yxalt, car_position.Z);
                tempbus_target_I = new Microsoft.Xna.Framework.Vector3((float)(tempbus_Position_I.X - dis * (Math.Sin(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle + langle))), yalt - (yalt - yxalt) * .6f, (float)(tempbus_Position_I.Z - dis * (Math.Cos(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle + langle))));
                tempbus_target_C = new Microsoft.Xna.Framework.Vector3((float)(tempbus_Position_I.X - dis * (Math.Sin(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle))), yxalt, (float)(tempbus_Position_I.Z - dis * (Math.Cos(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle))));
                tempbus_target_D = new Microsoft.Xna.Framework.Vector3((float)(tempbus_Position_I.X - dis * (Math.Sin(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle + rangle))), yalt - (yalt - yxalt) * .3f, (float)(tempbus_Position_I.Z - dis * (Math.Cos(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle + rangle))));
            }


            if (mode == 0)
            {
                tempbus_target_I = new Microsoft.Xna.Framework.Vector3((float)(Bus_models[0].Position.X - driver_pos * Math.Sin(Bus_models[0].Rotation.Y) - 0.3 * Math.Cos(Bus_models[0].Rotation.Y)), yxalt, (float)(Bus_models[0].Position.Z - driver_pos * Math.Cos(Bus_models[0].Rotation.Y) + .3f * Math.Sin(Bus_models[0].Rotation.Y)));
                tempbus_target_C = new Microsoft.Xna.Framework.Vector3((float)(Bus_models[0].Position.X - driver_pos * Math.Sin(Bus_models[0].Rotation.Y) - 0.3 * Math.Cos(Bus_models[0].Rotation.Y)), yxalt, (float)(Bus_models[0].Position.Z - driver_pos * Math.Cos(Bus_models[0].Rotation.Y) + .3f * Math.Sin(Bus_models[0].Rotation.Y)));
                tempbus_target_D = new Microsoft.Xna.Framework.Vector3((float)(Bus_models[0].Position.X - driver_pos * Math.Sin(Bus_models[0].Rotation.Y) - 0.3 * Math.Cos(Bus_models[0].Rotation.Y)), yxalt, (float)(Bus_models[0].Position.Z - driver_pos * Math.Cos(Bus_models[0].Rotation.Y) + .3f * Math.Sin(Bus_models[0].Rotation.Y)));

                tempbus_Position_I = new Microsoft.Xna.Framework.Vector3((float)(tempbus_target_I.X - dis * (Math.Sin(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle - 1.57f))), yalt, (float)(tempbus_target_I.Z - dis * (Math.Cos(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle - 1.57f))));
                tempbus_Position_C = new Microsoft.Xna.Framework.Vector3((float)(tempbus_target_C.X - dis * (Math.Sin(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle))), yalt, (float)(tempbus_target_C.Z - dis * (Math.Cos(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle))));
                tempbus_Position_D = new Microsoft.Xna.Framework.Vector3((float)(tempbus_target_D.X - dis * (Math.Sin(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle + 1.57f))), yalt, (float)(tempbus_target_D.Z - dis * (Math.Cos(Bus_models[0].Rotation.Y + MathHelper.ToRadians(180) - angle + 1.57f))));
            }



            double fps = (1000 / gameTime.ElapsedGameTime.TotalMilliseconds);

            fps = Math.Round(fps, 0);

            this.Window.Title = " pos " + roadcode + " th " + BusModel.last_theta + " LF " + maps_loaded + " Distance " + dis + "," + fps.ToString() + " FPS";
            // Update the mouse state
            lastMouseState = mouseState;
        }
Exemple #47
0
        private static void UpdateKeyboardEvents(GameTime gameTime)
        {
            KeyboardState current = Keyboard.GetState();

            // Build the modifiers that currently apply to the current situation.
            var modifiers = Modifiers.None;

            if (current.IsKeyDown(Keys.LeftControl) || current.IsKeyDown(Keys.RightControl))
            {
                modifiers |= Modifiers.Control;
            }

            if (current.IsKeyDown(Keys.LeftShift) || current.IsKeyDown(Keys.RightShift))
            {
                modifiers |= Modifiers.Shift;
            }

            if (current.IsKeyDown(Keys.LeftAlt) || current.IsKeyDown(Keys.RightAlt))
            {
                modifiers |= Modifiers.Alt;
            }

            // Key pressed and initial key typed events for all keys.
            foreach (Keys key in Enum.GetValues(typeof(Keys)))
            {
                if (current.IsKeyDown(key) && _previousKeyboardState.IsKeyUp(key))
                {
                    RaiseKeyDownEvent(key, modifiers);
                    char?keyChar = KeyboardUtil.ToChar(key, modifiers);
                    if (keyChar.HasValue)
                    {
                        RaiseCharacterEvent(keyChar.Value);
                    }

                    // Maintain the state of last key pressed.
                    _lastKey   = key;
                    _lastPress = gameTime.TotalGameTime;
                    _isInitial = true;
                }

                if (current.IsKeyUp(key) && _previousKeyboardState.IsKeyDown(key))
                {
                    RaiseKeyUpEvent(key, modifiers);
                }
            }

            // Handle keys being held down and getting multiple KeyTyped events in sequence.
            var elapsedTime = (gameTime.TotalGameTime - _lastPress).TotalMilliseconds;

            if (current.IsKeyDown(_lastKey) &&
                ((_isInitial && elapsedTime > _initialDelay) || (!_isInitial && elapsedTime > _repeatDelay)))
            {
                RaiseKeyDownEvent(_lastKey, modifiers);
                char?lastKeyChar = KeyboardUtil.ToChar(_lastKey, modifiers);
                if (lastKeyChar.HasValue)
                {
                    RaiseCharacterEvent(lastKeyChar.Value);
                    _lastPress = gameTime.TotalGameTime;
                    _isInitial = false;
                }
            }

            _previousKeyboardState = current;
        }
Exemple #48
0
        public override void Update(GameTime time)
        {
            if (!parent.IsOver)
            {
                if (parent.IsLoaded)
                {
                    if (!isQuestShowed)
                    {
                        nigObjective.Show();
                        isQuestShowed = true;
                    }
                    if (!isColorShowed && nigObjective.IsHidden)
                    {
                        nigColor.Show();
                        isColorShowed = true;
                    }

                    XI.KeyboardState keyState = XI.Keyboard.GetState();

                    if (!isEscPressed)
                    {
                        isEscPressed = keyState.IsKeyDown(XI.Keys.Escape);
                        if (isEscPressed)
                        {
                            if (nigMenu.IsHidden)
                            {
                                nigMenu.Show();
                            }

                            //nigFail.Show();
                            //if (!exitConfirm.IsShown)
                            //{
                            //    exitConfirm.Show();
                            //}
                            //else
                            //{
                            //    parent.Over();
                            //}
                        }
                    }
                    else
                    {
                        isEscPressed = keyState.IsKeyDown(XI.Keys.Escape);
                    }


                    if (exit.IsExitClicked)
                    {
                        if (nigMenu.IsHidden)
                        {
                            nigMenu.Show();
                        }
                        //if (!exitConfirm.IsShown)
                        //{
                        //    exitConfirm.Show();
                        //}
                        //else
                        //{
                        //    parent.Over();
                        //}
                    }

                    parent.IsPaused = !nigMenu.IsHidden || !nigFail.IsHidden || !nigObjective.IsHidden || !nigWin.IsHidden || !nigColor.IsHidden;

                    base.Update(time);
                }
            }
        }
        public override bool Get(Buttons btn)
        {
            switch (btn)
            {
            case Buttons.A: return(st.IsKeyDown(XnaInput.Keys.A));

            case Buttons.B: return(st.IsKeyDown(XnaInput.Keys.S));

            case Buttons.X: return(st.IsKeyDown(XnaInput.Keys.Q));

            case Buttons.Y: return(st.IsKeyDown(XnaInput.Keys.W));

            case Buttons.R: return(st.IsKeyDown(XnaInput.Keys.D1));

            case Buttons.L: return(st.IsKeyDown(XnaInput.Keys.D2));

            case Buttons.LeftStick: return(false);

            case Buttons.RightStick: return(false);

            case Buttons.DPad_Left: return(st.IsKeyDown(XnaInput.Keys.Left));

            case Buttons.DPad_Right: return(st.IsKeyDown(XnaInput.Keys.Right));

            case Buttons.DPad_Up: return(st.IsKeyDown(XnaInput.Keys.Up));

            case Buttons.DPad_Down: return(st.IsKeyDown(XnaInput.Keys.Down));

            case Buttons.Select: return(st.IsKeyDown(XnaInput.Keys.F1));

            case Buttons.Start: return(st.IsKeyDown(XnaInput.Keys.Space));
            }
            return(false);
        }