Holds the state of keystrokes by a keyboard.
Exemple #1
1
        public override void Update()
        {
            // Bounding Box
            rectangle = new Rectangle
            (
                (int)Position.X,
                (int)Position.Y,
                (int)Size.X,
                (int)Size.Y
            );

            KeyboardState keyboardState = Keyboard.GetState();
            if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                Position += movingVector;
                body.ApplyLinearImpulse(movingImpulse);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                Position -= movingVector;
                body.ApplyLinearImpulse(-movingImpulse);
            }
            if (Keyboard.GetState().IsKeyDown(Keys.W) && !prevKeyboardState.IsKeyDown(Keys.W))
            {
                if ((DateTime.Now - previousJump).TotalSeconds >= jumpInterval)
                {
                    jumpEffect.Play();
                    body.ApplyLinearImpulse(jumpingImpulse);
                    previousJump = DateTime.Now;
                }
            }

            prevKeyboardState = keyboardState;
        }
        public InputController()
        {
            m_DragArgs = new DragArgs();

            m_LastMouseState = Mouse.GetState();
            m_LastKeyboardState = Keyboard.GetState();
        }
        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;
                }
            }
        }
Exemple #4
0
 public void Check(KeyboardState last, KeyboardState curr)
 {
     if (last == null)
         return;
     // if the modifier keys don't match what we're looking for
     if (!matchMods(curr))
         // then it's not a match
         return;
     //based on the type of event
     switch (KeyEvent)
     {
         case KeyEvent.Released:
             if (!(keyDown(Key, last) && keyUp(Key, curr)))
                 return;
             break;
         case KeyEvent.Pressed:
             if (!(keyUp(Key, last) && keyDown(Key, curr)))
                 return;
             break;
         case KeyEvent.Down:
             if (!(keyDown(Key, curr)))
                 return;
             break;
         case KeyEvent.Up:
             if (!(keyUp(Key, curr)))
                 return;
             break;
         default:
             return;
     }
     // we made it through! Do something freakin' awesome
     CallDelegate();
 }
Exemple #5
0
 public InputManager(GameManager gameManager)
 {
     _lastKeyboardState = Keyboard.GetState();
     _gameManager = gameManager;
     HasTouchCapabilities = TouchPanel.GetCapabilities().IsConnected;
     TouchPanel.EnabledGestures = GestureType.Tap;
 }
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
        /// <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
            oldstate = Keyboard.GetState();

            base.Initialize();
        }
Exemple #8
0
        public override void move(ArrayList colidables)
        {
            KeyboardState newKeyBoardState = Keyboard.GetState();
            if (newKeyBoardState.IsKeyDown(Keys.Up))
            {
                if (checkCollision(colidables, 0, +velocity) == true)
                    y -= velocity;
            }
            else if (newKeyBoardState.IsKeyDown(Keys.Down))
            {
                if (checkCollision(colidables, 0, -velocity) == true)
                    y += velocity;
            }
            else if (newKeyBoardState.IsKeyDown(Keys.Left))
            {
                if (checkCollision(colidables, velocity, 0) == true)
                     x -= velocity;
            }
            else if (newKeyBoardState.IsKeyDown(Keys.Right))
            {
                if (checkCollision(colidables, -velocity, 0) == true)
                    x += velocity;
            }

            oldKeyBoardState = newKeyBoardState;
            hitBox = new Rectangle(x, y, width, height);
        }
Exemple #9
0
 //Update methode
 public static void Update()
 {
     oks = ks;
     oms = ms;
     ks = Keyboard.GetState();
     ms = Mouse.GetState();
 }
Exemple #10
0
 private Console()
 {
     booleanValues = new Dictionary<string, bool>();
     floatValues = new Dictionary<string, float>();
     integerValues = new Dictionary<string, int>();
     integerValues.Add("consoleHeight", 512);
     integerValues.Add("consoleWidth", 768);
     integerValues.Add("consolePositionX", 64);
     integerValues.Add("consolePositionY", 64);
     integerValues.Add("consoleBorderWidth", 16);
     integerValues.Add("consoleAlpha", 220);
     booleanValues.Add("consoleActive", false);
     commandHistory = new ConsoleHistory(120);
     messageHistory = new ConsoleHistory(120);
     lines = new List<String>();
     currentCommand = "";
     lastState = new KeyboardState();
     booleanValues.Add("texInfo", false);
     booleanValues.Add("meshCountInfo", false);
     booleanValues.Add("showPosition", false);
     booleanValues.Add("occluderInfo", false);
     booleanValues.Add("drawshadowtex", false);
     booleanValues.Add("glow", true);
     floatValues.Add("hdrpower", 4.0f);
 }
Exemple #11
0
 public void Update()
 {
     oldkey = key;
     om = m;
     key = Keyboard.GetState();
     m = Mouse.GetState();
 }
Exemple #12
0
 public override void HandleKeyboardInput(KeyboardState oldKeyboardState)
 {
     KeyboardState currentKeyboardState = Keyboard.GetState();
     if (currentKeyboardState.IsKeyDown(Keys.Escape)
         && oldKeyboardState.IsKeyUp(Keys.Escape))
         videoPlayer.Stop();
 }
Exemple #13
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;
            }
        }
Exemple #14
0
 public void Update()
 {
     previousMouseState = currentMouseState;
     previousKeyboardState = currentKeyboardState;
     currentMouseState = Mouse.GetState();
     currentKeyboardState = Keyboard.GetState();
 }
Exemple #15
0
 public override void Update(GameTime gameTime)
 {
     base.Update(gameTime);
     MouseState mouseState = Mouse.GetState();
     deltaMousePos = new Point(mouseState.X - mousePosition.X, mouseState.Y - mousePosition.Y);
     mousePosition.X = mouseState.X;
     mousePosition.Y = mouseState.Y;
     deltaScroll = mouseState.ScrollWheelValue - mouseScrollValue;
     mouseScrollValue = mouseState.ScrollWheelValue;
     leftMouseDown = mouseState.LeftButton == ButtonState.Pressed;
     rightMouseDown = mouseState.RightButton == ButtonState.Pressed;
     prevState = curState;
     curState = Keyboard.GetState();
     int posX = (curState.IsKeyDown(Keys.D) || curState.IsKeyDown(Keys.Right)) ? 1 : 0;
     int negX = (curState.IsKeyDown(Keys.A) || curState.IsKeyDown(Keys.Left)) ? -1 : 0;
     int posY = (curState.IsKeyDown(Keys.W) || curState.IsKeyDown(Keys.Up)) ? 1 : 0;
     int negY = (curState.IsKeyDown(Keys.S) || curState.IsKeyDown(Keys.Down)) ? -1 : 0;
     movementDir = new Vector2(posX + negX, posY + negY);
     if (movementDir != Vector2.Zero)
         movementDir.Normalize();
     spaceBarPressed = curState.IsKeyDown(Keys.Space) && prevState.IsKeyUp(Keys.Space);
     shiftDown = curState.IsKeyDown(Keys.LeftShift) || curState.IsKeyDown(Keys.RightShift);
     shiftUp = curState.IsKeyUp(Keys.LeftShift) && curState.IsKeyUp(Keys.RightShift);
     enterDown = curState.IsKeyDown(Keys.Enter);
     escapeDown = curState.IsKeyDown(Keys.Escape);
 }
        public void accessObject(LLESprite playerCharacter, KeyboardState keyboardState, KeyboardState prevKeyboardState)
        {
            mPlayerCharacter = playerCharacter;

            if (playerCharacter != null && (playerCharacter.getDirection() == LLESprite.DIRECTION_UP || playerCharacter.getDirection() == LLESprite.DIRECTION_LEFT_UP || playerCharacter.getDirection() == LLESprite.DIRECTION_RIGHT_UP)

                && keyboardState.IsKeyDown(Keys.Z) == true && prevKeyboardState.IsKeyDown(Keys.Z) == false)
            {
                for (int i = 0; i < mapObjects.Count; i++)
                {
                    if (mapObjects[i] != null && mapObjects[i].getSprite() != null)
                    {
                        LLESprite target = mapObjects[i].getSprite();

                        if (playerCharacter.isCollidingMap(new Vector4(target.getX(), target.getY(), target.getHeight(), target.getWidth()), new Vector2(cameraX, cameraY), false, true, 4) == true)
                        {
                            scriptProcessor.extractObjectVariables(mapObjects[i]);

                            attack = false;

                            break;
                        }
                    }
                }
            }
        }
Exemple #17
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 #18
0
 public Initializer(SpriteBatch spriteBatch, RogueLike ingame)
 {
     this.spriteBatch = spriteBatch;
     this.ingame = ingame;
     this.oldkeyboardState = Keyboard.GetState();
     output18 = ingame.Content.Load<SpriteFont>("Output18pt");
 }
Exemple #19
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);
        }
 public static void ClearState()
 {
     previousMouseState = Mouse.GetState();
     currentMouseState = Mouse.GetState();
     previousKeyState = Keyboard.GetState();
     currentKeyState = Keyboard.GetState();
 }
Exemple #21
0
        public static void Update(MouseState mouse, KeyboardState keyboard)
        {
            MouseMoving(mouse);
            MouseClicking(mouse);

            DevInput(mouse, keyboard);
        }
Exemple #22
0
        public override void Update(GameTime gameTime, Microsoft.Xna.Framework.Input.KeyboardState keyboardState)
        {
            base.Update(gameTime, keyboardState);

            KeyboardState newKeyState = keyboardState;

            if (_state == PuzzleState.eCompleted || _state == PuzzleState.eFailed)
            {
                if (!(completionWaitTime >= timeSinceCompletion.TotalMilliseconds))
                {
                    _finished = true;
                }
                else
                {
                    timeSinceCompletion += gameTime.ElapsedGameTime;
                }
            }
            else
            {
                if (_state != PuzzleState.eRouteConnected)
                {
                    CheckPathSuccess();

                    UpdateInput(newKeyState);
                }

                UpdateFlow(gameTime);

                timeSinceStart += gameTime.ElapsedGameTime;

                oldKeyState = newKeyState;
            }
        }
Exemple #23
0
 public GUI()
 {
     this.lastKbState = Keyboard.GetState();
     this.KeysDown = new List<KeyRepeat>();
     foreach (Keys k in this.lastKbState.GetPressedKeys())
         this.KeysDown.Add(new KeyRepeat(k));
 }
Exemple #24
0
        public void UpdateKeyboard(KeyboardState keyboardState)
        {
            float moveX = 0f;
            float moveY = 0f;
            float oldX = scene.paddlePos.X;
            float oldY = scene.paddlePos.Y;

            if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S))      //down
            {
                moveY = -1 * moveSensitivity;
            }

            if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W))      //up
            {
                moveY = 1 * moveSensitivity;
            }

            if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A))      //left
            {
                moveX = -1 * moveSensitivity;
            }

            if (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D))      //right
            {
                moveX = 1 * moveSensitivity;
            }

            if (keyboardState.IsKeyDown(Keys.Space))        //respawn the ball if you press 
            {
                scene.TriggerBallSpawn();
            }
            
            scene.paddlePos = CheckBounds(new Vector3 (oldX + moveX, oldY + moveY, 2400f));
        }
Exemple #25
0
 public void kill(KeyboardState kb, MouseState ms)
 {
     stateTimer = 0.0f;
     state = State.EXIT;
     this.update(kb, ms);
     this.init();
 }
        public override void UpdateObjects(ContentManager content)
        {
            this.mouse = Mouse.GetState();
            this.keyboard = Keyboard.GetState();

            this.UpdateCursor();

            if (this.keyboard.IsKeyDown(Keys.Enter) && this.previousKeyboard.IsKeyUp(Keys.Enter) &&
                this.controlScreenItems.Count != 0)
            {
                if (this.controlScreenItems[this.selectedEntry].ItemText == "Back")
                {
                    Rpg.PActiveWindow=EnumActiveWindow.MainMenu;
                }
            }

            if (this.mouse.LeftButton == ButtonState.Pressed)
            {
                foreach (var item in this.controlScreenItems)
                {
                    if (this.mouse.X > item.ItemPosition.X && this.mouse.X < item.ItemPosition.X + item.ItemTexture.Bounds.Width &&
                        this.mouse.Y > item.ItemPosition.Y && this.mouse.Y < item.ItemPosition.Y + item.ItemTexture.Bounds.Height)
                    {
                        if (item.ItemText == "Back")
                        {
                            Rpg.PActiveWindow=EnumActiveWindow.MainMenu;
                            break;
                        }
                    }
                }
            }

            this.previousKeyboard = this.keyboard;
        }
Exemple #27
0
    public void Update(KeyboardState k)
    {
        PressedFire = IsPressed(k, Fire, FireKey);
        PressedBlock = IsPressed(k, Block, BlockKey);
        PressedSpecial = IsPressed(k, Special, SpecialKey);
        PressedUse = IsPressed(k, Use, UseKey);

        PressedUp = IsPressed(k, Up, UseKey);
        PressedLeft = IsPressed(k, Left, LeftKey);
        PressedRight = IsPressed(k, Right, RightKey);
        PressedDown = IsPressed(k, Down, DownKey);

        PressedInventoryR = IsPressed(k, InventoryR, InventoryRKey);
        PressedInventoryL = IsPressed(k, InventoryL, InventoryLKey);
        PressedStart = IsPressed(k, Start, StartKey);

        Fire = IsHeld(k, Fire, FireKey);
        Block = IsHeld(k, Block, BlockKey);
        Special = IsHeld(k, Special, SpecialKey);
        Use = IsHeld(k, Use, UseKey);

        Up = IsHeld(k, Up, UpKey);
        Left = IsHeld(k, Left, LeftKey);
        Right = IsHeld(k, Right, RightKey);
        Down = IsHeld(k, Down, DownKey);

        InventoryR = IsHeld(k, InventoryR, InventoryRKey);
        InventoryL = IsHeld(k, InventoryL, InventoryLKey);
        Start = IsHeld(k, Start, StartKey);
    }
Exemple #28
0
 public Input(MouseState cms, MouseState pms, KeyboardState cks, KeyboardState pks)
 {
     Pms = pms;
     Pks = pks;
     Cms = cms;
     Cks = cks;
 }
Exemple #29
0
        public void Update(Player player, 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 viewDistance = 200;

            double distance = Math.Sqrt(Math.Pow(player.position.X - position.X, 2) +
                Math.Pow(player.position.Y - position.Y, 2));

            if (distance < viewDistance)
            {
                float deltaX = player.position.X - position.X;
                float deltaY = player.position.Y - position.Y;
                float radians = (float)Math.Atan2(deltaY, deltaX);
                setRotation(radians);

                float zombieSpeed = 1.5f;
                float dx = (float) Math.Cos(rotation) * zombieSpeed;
                float dy = (float) Math.Sin(rotation) * zombieSpeed;
                position.X += dx;
                position.Y += dy;
            }
        }
Exemple #30
0
 public void Check(KeyboardState last, KeyboardState curr)
 {
     if (last == null)
         return;
     if (!matchMods(curr))
         return;
     switch (KeyEvent)
     {
         case KeyEvent.Released:
             if (!(keyDown(Key, last) && keyUp(Key, curr)))
                 return;
             break;
         case KeyEvent.Pressed:
             if (!(keyUp(Key, last) && keyDown(Key, curr)))
                 return;
             break;
         case KeyEvent.Down:
             if (!(keyDown(Key, curr)))
                 return;
             break;
         case KeyEvent.Up:
             if (!(keyUp(Key, curr)))
                 return;
             break;
         default:
             return;
     }
     // we made it through! Do something freakin' awesome
     CallDelegate();
 }
Exemple #31
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 #32
0
        public int Update(GameTime gameTime)
        {
            KeyboardState keyState;
            keyState = Keyboard.GetState(PlayerIndex.One);

            if (keyState.IsKeyDown(Keys.Up) && !prevKeyState.IsKeyDown(Keys.Up))
            {
                if (selected > 0)
                {
                    selected--;
                }
            }

            if (keyState.IsKeyDown(Keys.Down) && !prevKeyState.IsKeyDown(Keys.Down))
            {
                if (selected < buttonList.Count - 1)
                {
                    selected++;
                }
            }

            if (keyState.IsKeyDown(Keys.Enter))
            {
                return selected;
            }

            prevKeyState = keyState;
            return -1;
        }
Exemple #33
0
        public override void HandleInput(GameTime time)
        {
            //throw new NotImplementedException();
            newState = Keyboard.GetState();

            Keys[] newDown = newState.GetPressedKeys();
            Keys[] oldDown = oldState.GetPressedKeys();

            foreach(Keys k in oldDown)
            {
                if(!newDown.Contains(k))
                {
                    if(k == Keys.Back)
                    {
                        if (text.Length > 0) text = text.Substring(0, text.Length - 1);
                    }
                    else if(k == Keys.Space)
                    {
                        text += " ";
                    }
                    else
                    {
                        text += k.ToString();
                    }
                }
            }

            oldState = newState;
        }
    public void Update(GameTime gameTime)
    {
        previousMouseState    = currentMouseState;
        previousKeyboardState = currentKeyboardState;
        previousGamePadState  = (GamePadState[])currentGamePadState.Clone();
        //previousJoyState = currentJoyState;

        currentMouseState    = Mouse.GetState();
        currentKeyboardState = Keyboard.GetState();

        foreach (PlayerIndex index in Enum.GetValues(typeof(PlayerIndex)))
        {
            currentGamePadState[(int)index] = GamePad.GetState(index);
        }

        if (RumbleDuration > 0)
        {
            GamePadVibration(PlayerIndex.One, leftMotor, rightMotor);
            rumbleDuration -= (float)gameTime.ElapsedGameTime.TotalSeconds;
        }

        if (!currentGamePadState[0].IsConnected && enableControllers && joystick == null)
        {
            JoystickPing -= (float)gameTime.ElapsedGameTime.TotalSeconds;
            if (JoystickPing < 0)
            {
                JoystickPing = JoystickPingDuration;
                var th = new Thread(GenericControllerConnection);
                th.Start();
#if DEBUG
                Console.WriteLine("A new thread has been created!");
#endif
            }
        }
        else if (joystick != null && enableControllers)
        {
            joystick.Poll();
#if DEBUG
            Console.WriteLine("Polling Joystick...");
#endif
            try
            {
                JoystickState state = joystick.GetCurrentState();
                currentJoyState = joystick.GetCurrentState();
                bool[] button = state.Buttons;
                int[]  hats   = state.PointOfViewControllers;
                Console.WriteLine("[{0}]", string.Join(", ", hats));
            }
            catch (Exception)
            {
#if DEBUG
                Console.WriteLine("Oops, the controller disconnected!");
#endif
                joystick = null;
            }
        }
    }
 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,
     });
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime, Microsoft.Xna.Framework.Input.KeyboardState keyboard, Microsoft.Xna.Framework.Input.MouseState mouse)
        {
            float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;

            introTime += dt;
            pointerDimensions.Location = new Point(mouse.X, mouse.Y);
            shipRotation = Matrix.CreateRotationY(MathHelper.PiOver4 * introTime);
            Manager.Update(gameTime, mouse);
        }
Exemple #37
0
        /// <summary>
        /// Gets an array of keys that were pressed and released.
        /// </summary>
        /// <returns>The list of keys pressed.</returns>
        public Keys[] KeysPressed()
        {
            var lastState = this._lastState.GetPressedKeys();

            this._lastState = Microsoft.Xna.Framework.Input.Keyboard.GetState();
            var currentState = this._lastState.GetPressedKeys();

            return(lastState.Except(currentState).ToArray());
        }
Exemple #38
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);
     }
 }
        /// <summary>
        /// This function is used to update the contents of the text box.
        /// </summary>
        /// <param name="CurrTime">Currend time information</param>
        /// <param name="CurrKeyboard">Current state of the keyboard.</param>
        /// <param name="CurrMouse">Current state of the mouse.</param>
        /// <param name="ProcessMouseEvent">Set true to allow this object to process mouse events, false to ignore them</param>
        protected override void UpdateContents(GameTime CurrTime, Microsoft.Xna.Framework.Input.KeyboardState CurrKeyboard, Microsoft.Xna.Framework.Input.MouseState CurrMouse, bool ProcessMouseEvent)
        {
            if ((ProcessMouseEvent == true) && ((CurrMouse.LeftButton == ButtonState.Pressed) || (CurrMouse.LeftButton == ButtonState.Pressed))) //Mouse button is pressed
            {
                if (ClientRegion.Contains(CurrMouse.Position) == false)                                                                          //Mouse is outside of the control, it has lost focus
                {
                    if (HasFocus != false)
                    {
                        HasChanged = true;
                    }

                    HasFocus = false;
                }
            }

            if (HasFocus != false)               //Only update if the control has focus
            {
                string Input = MGInput.GetTypedChars(CurrKeyboard, cPriorKeys);

                if (CurrTime.TotalGameTime.Milliseconds <= 500)
                {
                    if (cCursorOn == false)
                    {
                        HasChanged = true;
                    }

                    cCursorOn = true;
                }
                else
                {
                    if (cCursorOn == true)
                    {
                        HasChanged = true;
                    }

                    cCursorOn = false;
                }

                if (Input.CompareTo("\b") == 0)
                {
                    if (Text.Length > 0)
                    {
                        Text       = Text.Substring(0, Text.Length - 1);
                        HasChanged = true;
                    }
                }
                else
                {
                    Text      += Input;
                    HasChanged = true;
                }
            }
        }
Exemple #40
0
 /// <summary>
 /// Processes the current keystate to set a keybinding.
 /// </summary>
 /// <param name="currentState"></param>
 internal void ProcessKey(Microsoft.Xna.Framework.Input.KeyboardState currentState)
 {
     foreach (TabPage tp in tcControlGroups.Controls)
     {
         // if the tab page is one of the custom tab pages (should always be the case)
         if (tp is FlowLayoutTabPage)
         {
             // make it so
             FlowLayoutTabPage fltp = tp as FlowLayoutTabPage;
             // in case this tab page contains the active keybinding control needing to set its binding.
             fltp.ProcessKey(currentState);
         }
     }
 }
Exemple #41
0
        public override void Update(GameTime gameTime, Microsoft.Xna.Framework.Input.KeyboardState currentKeyState, Microsoft.Xna.Framework.Input.KeyboardState lastKeyState, bool resetMovement = false)
        {
            HandleInput(currentKeyState, lastKeyState);

            // movement.X = -1;
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (velocity.X == 0)
            {
                float speed = 7;
                LeftLegRotation  = MathHelper.Lerp(LeftLegRotation, 0f, (float)gameTime.ElapsedGameTime.TotalSeconds * speed);
                RightLegRotation = MathHelper.Lerp(RightLegRotation, 0f, (float)gameTime.ElapsedGameTime.TotalSeconds * speed);
                LeftArmRotation  = MathHelper.Lerp(LeftArmRotation, -.1f, (float)gameTime.ElapsedGameTime.TotalSeconds * speed);
                RightArmRotation = MathHelper.Lerp(RightArmRotation, .1f, (float)gameTime.ElapsedGameTime.TotalSeconds * speed);
                animationFadeIn  = 0;
            }
            else
            {
                LeftLegRotation  = MathHelper.Lerp((float)Math.Cos((position.X / 20) * 0.6662F) * 2.0F * .7f * 0.5F, LeftLegRotation, 1f - animationFadeIn);
                RightLegRotation = MathHelper.Lerp((float)Math.Cos((position.X / 20) * 0.6662F + Math.PI) * 2.0F * .7f * 0.5F, RightLegRotation, 1f - animationFadeIn);

                LeftArmRotation  = MathHelper.Lerp((float)Math.Cos((position.X / 20) * 0.6662F) * 2.0F * .4f * 0.5F, LeftArmRotation, 1f - animationFadeIn);
                RightArmRotation = MathHelper.Lerp((float)Math.Cos((position.X / 20) * 0.6662F + Math.PI) * 2.0F * .4f * 0.5F, RightArmRotation, 1f - animationFadeIn);
                if (animationFadeIn < 1f)
                {
                    if (animationFadeIn < 1f)
                    {
                        animationFadeIn += elapsed * 4;
                    }
                }
            }
            Vector2 direction = (level.MainCamera.Position + new Vector2(level.Players[0].Position.X, level.Players[0].Position.Y));

            direction.Normalize();
            HeadRotation = (float)Math.Atan2((double)direction.Y, (double)direction.X) + MathHelper.PiOver2 + MathHelper.ToRadians(90);

            if (HeadRotation < MathHelper.ToRadians(90))
            {
                HeadRotation = MathHelper.Clamp(HeadRotation, MathHelper.ToRadians(0), MathHelper.ToRadians(15));
            }
            else if (HeadRotation > MathHelper.ToRadians(270))
            {
                HeadRotation = MathHelper.Clamp(HeadRotation, MathHelper.ToRadians(345), MathHelper.ToRadians(360));
            }
            else if (HeadRotation > MathHelper.ToRadians(90))
            {
                HeadRotation = MathHelper.Clamp(HeadRotation, MathHelper.ToRadians(165), MathHelper.ToRadians(195));
            }
            base.Update(gameTime, currentKeyState, lastKeyState, false);
        }
Exemple #42
0
        internal void ProcessKey(Microsoft.Xna.Framework.Input.KeyboardState currentState)
        {
            foreach (KeyBindingControl kbc in flpBindings.Controls)
            {
                // if this keybindingcontrol is in edit mode
                if (kbc.Editing)
                {
                    // apply the pressed key to it
                    kbc.SetKey(currentState);

                    // get focus off of the textbox
                    flpBindings.Focus();
                }
            }
        }
Exemple #43
0
    public static void Update(int ms, Microsoft.Xna.Framework.Input.KeyboardState ks, GamePadState[] gs)
    {
        SlimDX.DirectInput.JoystickState[] joyStates = ControllerManager.GetState();

        for (int i = 0; i != 4; i++)
        {
            if (Inputs[i] is KeyboardInput)
            {
                ((KeyboardInput)Inputs[i]).Update(ks);
            }
        }

        State newState;

        switch (GState)
        {
        case State.Title:
            newState = Title.Update(ms, ks);
            if (newState == State.CharSelect)
            {
                GState     = State.CharSelect;
                CharSelect = new CharSelect();
            }
            break;

        case State.CharSelect:

            newState = CharSelect.Update(ms);
            if (newState == State.InGame)
            {
                GState = State.InGame;
                InGame = new InGame(CharSelect.CharacterSelect);
            }
            break;


        case State.InGame:

            newState = InGame.Update(ms);
            if (newState == State.Title)
            {
            }
            break;
        }
    }
        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 #45
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 #46
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;
            }
        }
        /// <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 #48
0
 public static void update_input()
 {
     ks = Keyboard.GetState();
 }
Exemple #49
0
 public static void Update()
 {
     oldKeyboard     = currentKeyboard;
     currentKeyboard = input.Keyboard.GetState();
 }
Exemple #50
0
        void UpdateMouse()
        {
            this.mouseState    = Mouse.GetState(Program.MainView.Window);
            this.keyboardState = Keyboard.GetState();

            if (View.Controls.keyboardState.IsKeyDown(Keys.LeftShift))
            {
                return;
            }


            if (View.Controls.MouseDragState == 0)
            {
                dragInstance = -1;
            }

            if (dragInstance > -1)
            {
                if (this.ID != dragInstance)
                {
                    this.Highlight = false;
                    return;
                }
            }

            Vector2 centre = Object3D.GetOrtho(this.position);

            double xDiff = mouseState.X - centre.X;
            double yDiff = mouseState.Y - centre.Y;


            Vector2 angle0      = Object3D.GetOrtho(this.position + Vector3.Transform(new Vector3(this.rayon, 0, 0), this.Matrice));
            Vector2 anglePIsur2 = Object3D.GetOrtho(this.position + Vector3.Transform(new Vector3(0, this.rayon, 0), this.Matrice));

            if (angle0.X < centre.X)
            {
                xDiff = -xDiff;
            }
            if (anglePIsur2.Y < centre.Y)
            {
                yDiff = -yDiff;
            }

            double hypo       = Math.Pow(xDiff * xDiff + yDiff * yDiff, 0.5);
            float  angleMouse = (float)Math.Atan2(yDiff / hypo, xDiff / hypo);

            Object3D.MesurePositive(ref angleMouse);


            double smallest       = Single.MaxValue;
            double realAngleMouse = 0;
            int    smallestI      = 0;

            for (int i = 0; i < 100; i++)
            {
                double  angle    = (i / 100d) * Math.PI * 2;
                Vector2 posOrtho = Object3D.GetOrtho(this.position + Vector3.Transform(new Vector3((float)(this.rayon * Math.Cos(angle)),
                                                                                                   (float)(this.rayon * Math.Sin(angle)), 0), this.Matrice));

                double xDiffSeek = posOrtho.X - centre.X;
                double yDiffSeek = posOrtho.Y - centre.Y;

                if (angle0.X < centre.X)
                {
                    xDiffSeek = -xDiffSeek;
                }
                if (anglePIsur2.Y < centre.Y)
                {
                    yDiffSeek = -yDiffSeek;
                }
                double hypoSeek = Math.Pow(xDiffSeek * xDiffSeek + yDiffSeek * yDiffSeek, 0.5);

                float angleOrtho = (float)Math.Atan2(yDiffSeek / hypoSeek, xDiffSeek / hypoSeek);
                Object3D.MesurePositive(ref angleOrtho);

                double diff = Math.Abs(angleOrtho - angleMouse);

                if (diff < smallest)
                {
                    realAngleMouse = angle;
                    smallest       = diff;
                    smallestI      = i;
                }
            }

            Vector2 posRayonOrthoAtMouseAngle = Object3D.GetOrtho(this.position + Vector3.Transform(new Vector3((float)(this.rayon * Math.Cos(realAngleMouse)),
                                                                                                                (float)(this.rayon * Math.Sin(realAngleMouse)), 0), this.Matrice));

            xDiff = posRayonOrthoAtMouseAngle.X - centre.X;
            yDiff = posRayonOrthoAtMouseAngle.Y - centre.Y;

            if (angle0.X < centre.X)
            {
                xDiff = -xDiff;
            }
            if (anglePIsur2.Y < centre.Y)
            {
                yDiff = -yDiff;
            }

            double hypo2     = Math.Pow(xDiff * xDiff + yDiff * yDiff, 0.5);
            bool   highlight = View.Controls.keyboardState.IsKeyUp(Keys.LeftShift) && Math.Abs(hypo - hypo2) <= hypo2 * 0.1f;


            if (highlight)
            {
                dragInstance = this.ID;
            }

            this.Highlight = View.Controls.MouseDragState > 0;

            if (View.Controls.mouseState.LeftButton == ButtonState.Released && View.Controls.MouseDragState == 2)
            {
                this.Release?.Invoke(null, null);
                this.endAngle   = 0;
                this.startAngle = 0;
                View.Controls.MouseDragState = 0;
            }

            if (highlight)
            {
                if (View.Controls.MouseDragState == 0 && View.Controls.mouseState.LeftButton == ButtonState.Released)
                {
                    View.Controls.MouseDragState = 1;
                }

                if (View.Controls.mouseState.LeftButton == ButtonState.Pressed)
                {
                    if (View.Controls.MouseDragState == 1)
                    {
                        this.endAngle   = (float)realAngleMouse;
                        this.startAngle = (float)realAngleMouse;
                        View.Controls.MouseDragState = 2;
                    }
                }
                else
                {
                    View.Controls.MouseDragState = 1;
                }
            }
            else
            {
                if (View.Controls.MouseDragState == 1)
                {
                    View.Controls.MouseDragState = 0;
                }
            }

            if (View.Controls.MouseDragState == 2)
            {
                this.endAngle = (float)realAngleMouse;
                float start = this.startAngle;
                float end   = this.endAngle;

                float val = end - start;
                this.ValueChanged?.Invoke(val, null);
            }
            oldKeyboardState = keyboardState;
            oldMouseState    = mouseState;
        }
 public override void Update(GameTime gameTime)
 {
     this.lastState = this.st;
     this.st        = XnaInput.Keyboard.GetState();
 }
Exemple #52
0
 public override void KeyboardCallback(Keys key, int x, int y, GameTime gameTime, bool released, ref Microsoft.Xna.Framework.Input.KeyboardState newState, ref Microsoft.Xna.Framework.Input.KeyboardState oldState)
 {
     if (key == Keys.OemPeriod)
     {
         ShootTrimesh(GetCameraPosition(), GetCameraTargetPosition());
     }
     else
     {
         base.KeyboardCallback(key, x, y, gameTime, released, ref newState, ref oldState);
     }
 }
Exemple #53
0
 public override void HandleKeys(Microsoft.Xna.Framework.Input.KeyboardState keyboard, bool isNewKey)
 {
 }
Exemple #54
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 #55
0
 public override void KeyboardCallback(Microsoft.Xna.Framework.Input.Keys key, int x, int y, GameTime gameTime, bool released, ref Microsoft.Xna.Framework.Input.KeyboardState newState, ref Microsoft.Xna.Framework.Input.KeyboardState oldState)
 {
     base.KeyboardCallback(key, x, y, gameTime, released, ref newState, ref oldState);
     if (key == Keys.V && released)
     {
         DropBall();
     }
 }
Exemple #56
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);
                }
            }
        }
Exemple #57
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 #58
0
        public override void Update(GameTime gameTime, Microsoft.Xna.Framework.Input.KeyboardState currentKeyState, Microsoft.Xna.Framework.Input.KeyboardState lastKeyState, bool resetMovement = true)
        {
            Item SelectedItem = Inventory[ZarknorthClient.Interface.MainWindow.inventory.Selected].Item;

            if (SelectedItem is MineItem)
            {
                if (level.currentMouseState.LeftButton == ButtonState.Pressed)
                {
                    timeHeld += (float)gameTime.ElapsedGameTime.TotalSeconds * (SelectedItem as MineItem).Multiplier * 1.35f;
                }
                if (timeHeld > .5f)
                {
                    timeHeld = 0;
                }
            }
            HandleInput(currentKeyState, lastKeyState);
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            sandboxShadowRotation += movement.X == 0 ? elapsed / 3 : (elapsed * 1.5f) * movement.X;

            if ((Level.Gamemode == GameMode.Sandbox && velocity.X == 0 && !isClimbing) || (Level.Gamemode != GameMode.Sandbox && movement.X == 0))
            {
                float speed = 7;
                LeftLegRotation  = MathHelper.Lerp(LeftLegRotation, 0f, (float)gameTime.ElapsedGameTime.TotalSeconds * speed);
                RightLegRotation = MathHelper.Lerp(RightLegRotation, 0f, (float)gameTime.ElapsedGameTime.TotalSeconds * speed);
                LeftArmRotation  = MathHelper.Lerp(LeftArmRotation, 0f, (float)gameTime.ElapsedGameTime.TotalSeconds * speed);
                RightArmRotation = MathHelper.Lerp(RightArmRotation, 0f, (float)gameTime.ElapsedGameTime.TotalSeconds * speed);
                animationFadeIn  = 0;
            }
            else
            {
                if (isClimbing)
                {
                    //Swingin' Hands
                    LeftLegRotation  = MathHelper.Lerp(((float)Math.Cos(((position.Y / 5) * 0.6662F) * 2.0F * .4f * 0.5F) / 4) * (Flip == SpriteEffects.None ? 1 : -1), LeftLegRotation, 1f - animationFadeIn);
                    RightLegRotation = MathHelper.Lerp(((float)Math.Cos(((position.Y / 5) * 0.6662F + Math.PI) * 2.0F * .4f * 0.5F) / 4) * (Flip == SpriteEffects.None ? 1 : -1), RightLegRotation, 1f - animationFadeIn);

                    LeftArmRotation  = MathHelper.Lerp(((float)Math.Cos(((position.Y / 7) * 0.6662F) * 2.0F * .4f * 0.5F) + MathHelper.ToRadians(180)) * (Flip == SpriteEffects.None ? 1 : -1), LeftArmRotation, 1f - animationFadeIn);
                    RightArmRotation = MathHelper.Lerp(((float)Math.Cos(((position.Y / 7) * 0.6662F + Math.PI) * 2.0F * .4f * 0.5F) + MathHelper.ToRadians(180)) * (Flip == SpriteEffects.None ? 1 : -1), RightArmRotation, 1f - animationFadeIn);
                    if (animationFadeIn < 1f)
                    {
                        if (animationFadeIn < 1f)
                        {
                            animationFadeIn += elapsed * 5.5f;
                        }
                    }
                }
                else
                {
                    //Swingin' Hands
                    LeftLegRotation  = MathHelper.Lerp(((float)Math.Cos((position.X / 20) * 0.6662F) * 2.0F * .7f * 0.5F) * (Flip == SpriteEffects.None ? 1 : -1), LeftLegRotation, 1f - animationFadeIn);
                    RightLegRotation = MathHelper.Lerp(((float)Math.Cos((position.X / 20) * 0.6662F + Math.PI) * 2.0F * .7f * 0.5F) * (Flip == SpriteEffects.None ? 1 : -1), RightLegRotation, 1f - animationFadeIn);

                    LeftArmRotation  = MathHelper.Lerp(((float)Math.Cos((position.X / 20) * 0.6662F) * 2.0F * .4f * 0.5F) * (Flip == SpriteEffects.None ? 1 : -1), LeftArmRotation, 1f - animationFadeIn);
                    RightArmRotation = MathHelper.Lerp(((float)Math.Cos((position.X / 20) * 0.6662F + Math.PI) * 2.0F * .4f * 0.5F) * (Flip == SpriteEffects.None ? 1 : -1), RightArmRotation, 1f - animationFadeIn);
                    if (animationFadeIn < 1f)
                    {
                        if (animationFadeIn < 1f)
                        {
                            animationFadeIn += elapsed * 5.5f;
                        }
                    }
                }
            }
            if (!isOnGround && !isClimbing && velocity.X == 0)
            {
                //Jump/Fall Animation
                if (Flip == SpriteEffects.None)
                {
                    RightArmRotation += 7f * elapsed;
                    LeftArmRotation  += -7f * elapsed;
                    RightLegRotation += 7f * elapsed;
                    LeftLegRotation  += -7f * elapsed;
                }
                else
                {
                    RightArmRotation -= 10f * elapsed;
                    LeftArmRotation  -= -10f * elapsed;
                    RightLegRotation -= 10f * elapsed;
                    LeftLegRotation  -= -10f * elapsed;
                }
                animationFadeIn = .08f;
                float speed = 7;
                LeftLegRotation  = MathHelper.Lerp(LeftLegRotation, 0f, (float)gameTime.ElapsedGameTime.TotalSeconds * speed);
                RightLegRotation = MathHelper.Lerp(RightLegRotation, 0f, (float)gameTime.ElapsedGameTime.TotalSeconds * speed);
                LeftArmRotation  = MathHelper.Lerp(LeftArmRotation, 0f, (float)gameTime.ElapsedGameTime.TotalSeconds * speed);
                RightArmRotation = MathHelper.Lerp(RightArmRotation, 0f, (float)gameTime.ElapsedGameTime.TotalSeconds * speed);
                if (animationFadeIn < 1f)
                {
                    if (animationFadeIn < 1f)
                    {
                        animationFadeIn += elapsed * 5.5f;
                    }
                }
                animationFadeIn = 0;
            }

            Vector2 direction = (level.MainCamera.Position + new Vector2(Game.mouseState.X, Game.mouseState.Y)) - HeadPosition;

            direction.Normalize();
            HeadRotation = (float)Math.Atan2((double)direction.Y, (double)direction.X) + MathHelper.PiOver2 + MathHelper.ToRadians(90);

            if (HeadRotation < MathHelper.ToRadians(90))
            {
                HeadRotation = MathHelper.Clamp(HeadRotation, MathHelper.ToRadians(0), MathHelper.ToRadians(15));
            }
            else if (HeadRotation > MathHelper.ToRadians(270))
            {
                HeadRotation = MathHelper.Clamp(HeadRotation, MathHelper.ToRadians(345), MathHelper.ToRadians(360));
            }
            else if (HeadRotation > MathHelper.ToRadians(90))
            {
                HeadRotation = MathHelper.Clamp(HeadRotation, MathHelper.ToRadians(165), MathHelper.ToRadians(195));
            }

            SelectedItem = Inventory[ZarknorthClient.Interface.MainWindow.inventory.Selected].Item;
            Vector2 ArmDirection = (level.MainCamera.Position + new Vector2(Game.mouseState.X, Game.mouseState.Y)) - HeadPosition;

            ArmDirection.Normalize();
            bool flip = level.currentMouseState.X > level.game.GraphicsDevice.PresentationParameters.BackBufferWidth / 2;

            if (SelectedItem != Item.Blank && (Level.EditType != EditType.Erase && (Level.EditTool == EditTool.Default)))
            {
                if (SelectedItem is BlockItem)
                {
                    LeftArmRotation = (float)Math.Atan2((double)ArmDirection.Y, (double)ArmDirection.X) - MathHelper.PiOver2;
                }
                if (SelectedItem is MineItem && level.currentMouseState.LeftButton == ButtonState.Pressed)
                {
                    LeftArmRotation = (float)Math.Atan2((double)ArmDirection.Y, (double)ArmDirection.X) - MathHelper.PiOver2 - MathHelper.ToRadians((timeHeld * 40) * (flip ? -1 : 1));
                }
            }

            base.Update(gameTime, currentKeyState, lastKeyState);
        }
 public override void Update(GameTime gameTime)
 {
     st = XnaInput.Keyboard.GetState();
 }
Exemple #60
-1
        /// <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)
        {
            currentstate = Keyboard.GetState();

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();

            // TODO: Add your update logic here
            else
            {
                if (currentstate.IsKeyDown(Keys.A) && !oldstate.IsKeyDown(Keys.A))
                {
                    sounds[0].Play();
                    //var sd = soundEffects[0].CreateInstance();
                    //sd.IsLooped = false;
                    //sd.Play();
                    //sd.Dispose();
                }
                if (currentstate.IsKeyDown(Keys.R) && !oldstate.IsKeyDown(Keys.R)) { rd.BMS파일분석(); }
                if (currentstate.IsKeyDown(Keys.Y) && !oldstate.IsKeyDown(Keys.Y)) { rd.노트시간계산();sdmgr.시간들 = rd.시간들; }
                if (currentstate.IsKeyDown(Keys.S) && !oldstate.IsKeyDown(Keys.S))
                {
                    sdmgr.Play();
                    //var sd = soundEffects[1].CreateInstance();
                    //sd.Play();
                }

                oldstate = currentstate;
            }
            

            base.Update(gameTime);
        }