Ejemplo n.º 1
0
        private void MoveBat(KeyboardState keyboardState, float elapsed)
        {
            Bat.Direction = Vector2.Zero;
            if (keyboardState.IsPressed(Key.Left))
            {
                Bat.Direction.X += -1;
            }
            if (keyboardState.IsPressed(Key.Right))
            {
                Bat.Direction.X += +1;
            }

            if (Bat.Kind == Bat.Kinds.Inverted)
            {
                Bat.Position -= Bat.Direction * Bat.Speed * elapsed;
            }
            else
            {
                Bat.Position += Bat.Direction * Bat.Speed * elapsed;
            }

            //CHEATMODE
            //Bat.Position.X = Ball.Position.X - random.NextFloat(0, Bat.Size.X);

            if (Bat.Position.X < 0)
            {
                Bat.Position.X = 0;
            }
            else if (Bat.Position.X > BoundaryCoordinates.X - Bat.Size.X)
            {
                Bat.Position.X = BoundaryCoordinates.X - Bat.Size.X;
            }
        }
Ejemplo n.º 2
0
        public bool?IsPressed(string frontierkeyname)        // frontier naming convention..  GetEvents must have filled in ks
        {
            frontierkeyname = frontierkeyname.Substring(4);
            if (frontierkeyname.Length == 1 && (frontierkeyname[0] >= '0' && frontierkeyname[0] <= '9'))
            {
                frontierkeyname = "D" + frontierkeyname;
            }
            else if (frontierkeyname.StartsWith("Numpad_") && char.IsDigit(frontierkeyname[7]))
            {
                frontierkeyname = "NumberPad" + frontierkeyname[7];
            }
            else
            {
                int i = Array.FindIndex(strtx, x => x.Item2.Equals(frontierkeyname));
                if (i >= 0)
                {
                    frontierkeyname = strtx[i].Item1;
                }
            }

            Key k;

            if (Enum.TryParse <Key>(frontierkeyname, out k))
            {
                return((ks != null) ? ks.IsPressed(k) : false);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("FAILED IsPressed " + frontierkeyname);
            }

            return(false);
        }
        public override void Update()
        {
            turbo = !turbo;
            if (keyboard.Acquire().IsSuccess)
            {
                state = keyboard.GetCurrentState();
                DATA  = 0;

                if (state.IsPressed(KeyA))
                {
                    DATA |= 1;
                }

                if (state.IsPressed(KeyB))
                {
                    DATA |= 2;
                }

                if (state.IsPressed(KeyTurboA) && turbo)
                {
                    DATA |= 1;
                }

                if (state.IsPressed(KeyTurboB) && turbo)
                {
                    DATA |= 2;
                }

                if (state.IsPressed(KeySelect))
                {
                    DATA |= 4;
                }

                if (state.IsPressed(KeyStart))
                {
                    DATA |= 8;
                }

                if (state.IsPressed(KeyUp))
                {
                    DATA |= 0x10;
                }

                if (state.IsPressed(KeyDown))
                {
                    DATA |= 0x20;
                }

                if (state.IsPressed(KeyLeft))
                {
                    DATA |= 0x40;
                }

                if (state.IsPressed(KeyRight))
                {
                    DATA |= 0x80;
                }
            }
        }
Ejemplo n.º 4
0
 public static bool IsPressed(Key k)
 {
     if (currState != null)
     {
         return(currState.IsPressed(k));
     }
     return(false);
 }
Ejemplo n.º 5
0
        public bool IsKeyDown(Key key)
        {
            if (prevKeyboardState == null | currentKeyboardState == null)
            {
                return(false);
            }

            if (prevKeyboardState.IsPressed(key) == false &&
                currentKeyboardState.IsPressed(key) == true)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 6
0
        public void Update(float elapsed)
        {
            Elapsed = elapsed;
            KeyboardState keyboard = Keyboard.GetCurrentState();

            if (Ball.Direction.IsZero)
            {
                Ball.Position.X = Player.Position.X + Player.Size.X * 0.5f;
                Ball.Position.Y = Player.Position.Y - Ball.Size.Y - 1;
            }
            if (keyboard.IsPressed(Key.Left) && Player.IsValidMovementLeft(Player, Gameboard))
            {
                Player.Position.X += -Player.Speed;
            }
            if (keyboard.IsPressed(Key.Right) && Player.IsValidMovementRight(Player, Gameboard))
            {
                Player.Position.X += Player.Speed;
            }
            if (keyboard.IsPressed(Key.Space) && Ball.Direction.IsZero && Player.Life >= 0)
            {
                Ball.Direction = new Vector2(0, -1);
            }
            //if (keyboard.IsPressed(Key.Escape))
            //    Pause(keyboard);
            ////debug player,ball
            //Player playerBase = new Player(new Vector2(0, 0));
            //Ball ballBase = new Ball(playerBase);
            ////debug playerSize+
            //if (keyboard.IsPressed(Key.F1))
            //{
            //    Player.Size.X += playerBase.Size.X / 3;
            //    if (!Gameboard.IncludesGameObject(Player))
            //        Player.Position.X = Gameboard.Width - Player.Size.X;
            //}
            ////debug playerSize-
            //if (keyboard.IsPressed(Key.F2))
            //    Player.Size.X -= playerBase.Size.X / 3;
            //debug ball imba
            if (keyboard.IsPressed(Key.F7))
            {
                Ball.BallImbalanced = true;
                Ball.BallImbaNow.Start();
            }
            ////debug ball split
            //if (keyboard.IsPressed(Key.F8))
            //    GobjectList.Add(new Ball(Ball));

            MoveGameObjetcs();
        }
Ejemplo n.º 7
0
        public bool?IsPressed(string keyname)                            // keyname is in keys
        {
            Key?k = SharpKeyConversion.KeysToSharpKey(keyname.ToVkey()); // to VKEY, then to Sharp key

            if (k != null)
            {
                return((ks != null) ? ks.IsPressed(k.Value) : false);        // use keyboard state to determine
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("FAILED IsPressed " + keyname);
            }

            return(false);
        }
Ejemplo n.º 8
0
        public bool?IsPressed(string frontierkeyname)        // frontier naming convention..  GetEvents must have filled in ks
        {
            Key?k = KeyConversion.FrontierNameToSharpKey(frontierkeyname);

            if (k != null)
            {
                return((ks != null) ? ks.IsPressed(k.Value) : false);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("FAILED IsPressed " + frontierkeyname);
            }

            return(false);
        }
Ejemplo n.º 9
0
        public static void Poll()
        {
            KeyboardState kstate = keyboard.GetCurrentState();

            foreach (Key k in kstate.AllKeys)
            {
                if (kstate.IsPressed(k))
                {
                    keyStates[k] = true;
                }
                if (kstate.IsReleased(k))
                {
                    keyStates[k] = false;
                }
            }

            MouseState mState = mouseRel.GetCurrentState();

            LMBPressed    = mState.GetButtons()[0];
            RMBPressed    = mState.GetButtons()[1];
            MMBPressed    = mState.GetButtons()[2];
            mouseDeltaPos = new Vector3(mState.X, mState.Y, mState.Z);

            mouseAbsPosNormalized.X = (Renderer.viewport.PointToClient(System.Windows.Forms.Control.MousePosition).X - (Renderer.viewport.Width / 2F)) / (float)Renderer.viewport.Width;
            mouseAbsPosNormalized.Y = (Renderer.viewport.PointToClient(System.Windows.Forms.Control.MousePosition).Y - (Renderer.viewport.Height / 2F)) / (float)Renderer.viewport.Height;

            mouseAbsPosScreen.X = Renderer.viewport.PointToClient(System.Windows.Forms.Control.MousePosition).X;
            mouseAbsPosScreen.Y = Renderer.viewport.PointToClient(System.Windows.Forms.Control.MousePosition).Y;
        }
Ejemplo n.º 10
0
        public bool?IsPressed(string keyname)
        {
            keyname = keyname.Substring(4);
            if (keyname.Length == 1 && (keyname[0] >= '0' && keyname[0] <= '9'))
            {
                keyname = "D" + keyname;
            }
            else if (keyname.StartsWith("Numpad_") && char.IsDigit(keyname[7]))
            {
                keyname = "NumberPad" + keyname[7];
            }
            else
            {
                int i = Array.FindIndex(strtx, x => x.Item2.Equals(keyname));
                if (i >= 0)
                {
                    keyname = strtx[i].Item1;
                }
            }

            Key k;

            if (Enum.TryParse <Key>(keyname, out k))
            {
                return(ks.IsPressed(k));
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("FAILED IsPressed " + keyname);
            }

            return(false);
        }
Ejemplo n.º 11
0
        public bool IsDown(int keycode, bool value = false)
        {
            // Returns true if the key is currently being pressed
            var key = (SharpDX.DirectInput.Key)ScanCodeMap[keycode];

            return(KeyState.IsPressed(key) || MyKeyDown[keycode]);
        }
Ejemplo n.º 12
0
        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            base.OnKeyPress(e);
            if (!KeyboardState.IsPressed(Key.LeftShift))
            {
                return;
            }

            switch (e.KeyChar)
            {
            case 'R':
                ResetStage(DefaultStage);
                break;

            case 'P':
                Context.StopWorld = !Context.StopWorld;
                break;

            case ' ':
                TriggerStart();
                break;

            case 'F':
                if (FormBorderStyle == FormBorderStyle.Sizable)
                {
                    WindowState     = FormWindowState.Maximized;
                    FormBorderStyle = FormBorderStyle.None;
                }
                else
                {
                    FormBorderStyle = FormBorderStyle.Sizable;
                }
                break;
            }
        }
Ejemplo n.º 13
0
        // Check to see which keys are pressed
        public static void CheckKeys()
        {
            if (!isKeyboardAcquired())
            {
                return;
            }

            diState = diDev.GetCurrentState();
            int i = 0;

            //Scan through all the keys to check which are depressed
            for (i = 1; i <= 211; i++)
            {
                if (diState.IsPressed((Key)i))
                {
                    aKeys[i] = true;
                    //If the key is pressed, set the appropriate array index to true
                }
                else
                {
                    aKeys[i] = false;
                    //If the key is not pressed, set the appropriate array index to false
                }
                Application.DoEvents();
            }
        }
        public bool IsDIPressed(Key k, bool recheck = false) // check. Optional rescan or use GetEvents
        {
            if (recheck || ks == null)
            {
                ks = keyboard.GetCurrentState();
            }

            return(ks.IsPressed(k));
        }
Ejemplo n.º 15
0
        //-----------------------------------------------------------------------
        public bool IsKeyDown(int keycode)
        {
            // Returns true if the key is currently being pressed
            var  key  = (SlimDX.DirectInput.Key)keycode;
            bool down = KeyState.IsPressed(key) || MyKeyDown[keycode];

            return(down);
        }
Ejemplo n.º 16
0
 public bool IsKeyPressed(Key key)
 {
     if (_keyboardState == null)
     {
         return(false);
     }
     return(_keyboardState.IsPressed(key));
 }
Ejemplo n.º 17
0
        public bool IsDown(int code, bool value = false)
        {
            if (code <= (int)Key.LastKey)
            {
                return(KeyState.IsPressed((SharpDX.DirectInput.Key)code) || MyKeyDown[code]);
            }

            return(CurrentMouseState.Buttons[code - (int)Mouse.Left] || MyKeyDown[code]);
        }
Ejemplo n.º 18
0
        static public bool Camera(KeyboardState kbd, Camera camera, int msticks)
        {
            Vector3 cameraActionRotation = Vector3.Zero;

            var angle = (float)msticks * 0.075f;

            if (kbd.IsPressed(Keys.NumPad4))
            {
                cameraActionRotation.Z = -angle;
            }
            if (kbd.IsPressed(Keys.NumPad6))
            {
                cameraActionRotation.Z = angle;
            }
            if (kbd.IsAnyPressed(Keys.NumPad5, Keys.NumPad2))
            {
                cameraActionRotation.X = -angle;
            }
            if (kbd.IsPressed(Keys.NumPad8))
            {
                cameraActionRotation.X = angle;
            }
            if (kbd.IsAnyPressed(Keys.NumPad7, Keys.Q))
            {
                cameraActionRotation.Y = angle;
            }
            if (kbd.IsAnyPressed(Keys.NumPad9, Keys.E))
            {
                cameraActionRotation.Y = -angle;
            }

            if (cameraActionRotation.LengthSquared > 0)
            {
                camera.Rotate(cameraActionRotation);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 19
0
        private void UpdateKeyboard()
        {
            KeyboardState keyState = InputHandler.Get().KeyboardState;

            if (keyState.IsPressed(Key.Up))
            {
                this.AddToCameraPosition(new Vector3(0, 0, -1));
            }
            if (keyState.IsPressed(Key.Down))
            {
                this.AddToCameraPosition(new Vector3(0, 0, 1));
            }
            if (keyState.IsPressed(Key.Right))
            {
                this.AddToCameraPosition(new Vector3(-1, 0, 0));
            }
            if (keyState.IsPressed(Key.Left))
            {
                this.AddToCameraPosition(new Vector3(1, 0, 0));
            }
        }
Ejemplo n.º 20
0
        public void Update(INESController controller)
        {
            var nesController = controller as NES001Controller;

            if (nesController != null)
            {
                Keyboard.GetCurrentState(ref State);

                if (State.IsPressed(Key.A))
                {
                    nesController.State |= NES001Controller.Buttons.A;
                }

                if (State.IsPressed(Key.S))
                {
                    nesController.State |= NES001Controller.Buttons.B;
                }

                if (State.IsPressed(Key.RightShift))
                {
                    nesController.State |= NES001Controller.Buttons.Select;
                }

                if (State.IsPressed(Key.Return))
                {
                    nesController.State |= NES001Controller.Buttons.Start;
                }

                if (State.IsPressed(Key.Up))
                {
                    nesController.State |= NES001Controller.Buttons.Up;
                }

                if (State.IsPressed(Key.Down))
                {
                    nesController.State |= NES001Controller.Buttons.Down;
                }

                if (State.IsPressed(Key.Left))
                {
                    nesController.State |= NES001Controller.Buttons.Left;
                }

                if (State.IsPressed(Key.Right))
                {
                    nesController.State |= NES001Controller.Buttons.Right;
                }
            }
        }
        public override void Update()
        {
            turbo = !turbo;
            if (keyboard.Acquire().IsSuccess)
            {
                state = keyboard.GetCurrentState();
                DATA = 0;

                if (state.IsPressed(KeyA))
                    DATA |= 1;

                if (state.IsPressed(KeyB))
                    DATA |= 2;

                if (state.IsPressed(KeyTurboA) && turbo)
                    DATA |= 1;

                if (state.IsPressed(KeyTurboB) && turbo)
                    DATA |= 2;

                if (state.IsPressed(KeySelect))
                    DATA |= 4;

                if (state.IsPressed(KeyStart))
                    DATA |= 8;

                if (state.IsPressed(KeyUp))
                    DATA |= 0x10;

                if (state.IsPressed(KeyDown))
                    DATA |= 0x20;

                if (state.IsPressed(KeyLeft))
                    DATA |= 0x40;

                if (state.IsPressed(KeyRight))
                    DATA |= 0x80;
            }
        }
Ejemplo n.º 22
0
        public static bool IsPressed(Key key)
        {
            if (state.IsPressed(key))
            {
                return(true);
            }

            if (key == Key.LeftShift && state.IsPressed(Key.RightShift))
            {
                return(true);
            }
            if (key == Key.LeftControl && state.IsPressed(Key.RightControl))
            {
                return(true);
            }
            if (key == Key.LeftAlt && state.IsPressed(Key.RightAlt))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 23
0
        public bool IsDown(int code, bool hook = false)
        {
            if (hook && memory != null)
            {
                return(getBit(code) || MyKeyDown[code]);
            }

            if (code <= (int)Key.LastKey)
            {
                return(KeyState.IsPressed((SharpDX.DirectInput.Key)code) || MyKeyDown[code]);
            }

            return(CurrentMouseState.Buttons[code - (int)Mouse.Left] || MyKeyDown[code]);
        }
Ejemplo n.º 24
0
        protected override void OnDraw(DeviceContext renderTarget)
        {
            var worldScale  = renderTarget.Size.Width / StageWidth;
            var worldOffset = -CameraY * worldScale;

            GlobalTransform = Matrix3x2.Scaling(worldScale) * Matrix3x2.Translation(0.0f, worldOffset);

            base.OnDraw(renderTarget);

            if (KeyboardState.IsPressed(SharpDX.DirectInput.Key.LeftShift))
            {
                DrawDiagnostics(renderTarget);
            }
        }
Ejemplo n.º 25
0
        static public bool KeyPressed()
        {
            KeyboardState keys    = keyboard.GetCurrentState();
            bool          pressed = false;

            if (keys.IsPressed(Key.W))
            {
                pressed = true;
            }
            if (keys.IsPressed(Key.A))
            {
                pressed = true;
            }
            if (keys.IsPressed(Key.S))
            {
                pressed = true;
            }
            if (keys.IsPressed(Key.D))
            {
                pressed = true;
            }
            return(pressed);
        }
Ejemplo n.º 26
0
            public override double GetValue(int index)
            {
                if (State == null)
                {
                    return(0);
                }

                if (State.IsPressed((Key)index))
                {
                    return(1);
                }

                return(0);
            }
Ejemplo n.º 27
0
        public override void Update(DemoTime demoTime, KeyboardState key)
        {
            var player_01 = Tanks.Where(row => row.Name == "P_01").FirstOrDefault();

            if (key.IsPressed(Key.Left))
            {
                player_01.Move(-GlobalSpeed * player_01.Speed, 0, FormBoxRange);
            }

            if (key.IsPressed(Key.Up))
            {
                player_01.Move(0, -GlobalSpeed * player_01.Speed, FormBoxRange);
            }

            if (key.IsPressed(Key.Right))
            {
                player_01.Move(GlobalSpeed * player_01.Speed, 0, FormBoxRange);
            }

            if (key.IsPressed(Key.Down))
            {
                player_01.Move(0, GlobalSpeed * player_01.Speed, FormBoxRange);
            }
        }
Ejemplo n.º 28
0
            public bool GetKey(Key key, int mode = 2)
            {
                keys_new.IsPressed(Key.D1);
                switch (mode)
                {
                case 0:     //down
                    return(keys_new.IsPressed(key) && keys_old.IsReleased(key));

                case 1:     //up
                    return(keys_new.IsReleased(key) && keys_old.IsPressed(key));

                default:     //raw
                    return(keys_new.IsPressed(key));
                }
            }
Ejemplo n.º 29
0
        public override void ClickSelection(Vector2 pos)
        {
            try
            {
                KeyboardState state = Renderer.Singleton.Camera.Keyboard.GetCurrentState();
                if (state.IsPressed(Key.Period))
                {
                    SelectCore(pos);
                    return;
                }
            }
            catch (Exception e) { }

            PaintOnPosition(pos);
            Renderer.Singleton.Remove(_mouseCloud);
        }
Ejemplo n.º 30
0
        private static void RenderCallback()
        {
            Console.Clear();
            DirectInput directInput = new DirectInput();
            Keyboard    keyboard    = new Keyboard(directInput);

            keyboard.SetCooperativeLevel(form, CooperativeLevel.Background | CooperativeLevel.NonExclusive);
            keyboard.Acquire();
            KeyboardState keyState = keyboard.GetCurrentState();

            if (keyState.IsPressed(Key.Escape))
            {
                form.Close();
                form.Dispose();
            }
        }
Ejemplo n.º 31
0
        public bool GetKeyPress(Key key, bool ignorePressStamp = false)
        {
            if (_keyState == null || !_keyState.IsPressed(key))
            {
                return(false);
            }

            var pressed = true;

            if (ignorePressStamp == false)
            {
                if (_keyPressStamp[(int)key] == _pressStamp - 1 || _keyPressStamp[(int)key] == _pressStamp)
                {
                    pressed = false;
                }
            }
            _keyPressStamp[(int)key] = _pressStamp;

            return(pressed);
        }
        public override void Update()
        {
            if (keyboard.Acquire().IsSuccess)
            {
                state = keyboard.GetCurrentState();

                data4016 = 0;

                if (state.IsPressed(CreditServiceButton))
                    data4016 |= 0x04;
                if (state.IsPressed(DIPSwitch1))
                    data4016 |= 0x08;
                if (state.IsPressed(DIPSwitch2))
                    data4016 |= 0x10;
                if (state.IsPressed(CreditLeftCoinSlot))
                    leftCoin = true;
                if (leftCoin)
                    data4016 |= 0x20;
                if (state.IsPressed(CreditRightCoinSlot))
                    rightCoin = true;
                if (rightCoin)
                    data4016 |= 0x40;

                data4017 = 0;
                if (state.IsPressed(DIPSwitch3))
                    data4017 |= 0x04;
                if (state.IsPressed(DIPSwitch4))
                    data4017 |= 0x08;
                if (state.IsPressed(DIPSwitch5))
                    data4017 |= 0x10;
                if (state.IsPressed(DIPSwitch6))
                    data4017 |= 0x20;
                if (state.IsPressed(DIPSwitch7))
                    data4017 |= 0x40;
                if (state.IsPressed(DIPSwitch8))
                    data4017 |= 0x80;
            }
        }