private int clockspeed = 25; // 25 millisecond window for clock on joystick polling.

        public ControllerEngine()
        {
            this.ActiveDevice = 0;
            oldgstate = GamePad.GetState(this.ActiveDevice);
            oldjstate = Joystick.GetState(this.ActiveDevice);
            createNewTimer();
        }
 public MainWindow()
 {
     InitializeComponent();
     createNewTimer();
     oldgstate = GamePad.GetState(activeGamepad);
     oldjstate = Joystick.GetState(activeJoystick);
 }
Example #3
0
            public static void Update(GameTime dt)
            {
                JoyPrev = JoyState;
                JoyState = GamePad.GetState(PlayerIndex.One);

                KeyPrev = KeyState;
                KeyState = Keyboard.GetState(PlayerIndex.One);
            }
 public DemoPlayerInputManager()
 {
     m_gamePads = new GamePadState[MAX_GAMEPADS_COUNT];
     for (int i = 0; i < m_gamePads.Length; ++i)
     {
         m_gamePads[i] = new GamePadState(false);
     }
     m_keyboard = new KeyBoardState(null); // dummy param
 }
		public void UpdateState()
		{
			this.caps = GamePad.GetCapabilities(this.deviceIndex);
			this.state = GamePad.GetState(this.deviceIndex);

			// If it's not a well-known gamepad, check the corresponding joystick whether there are any axes or buttons
			if (!this.caps.IsMapped)
			{
				JoystickCapabilities joystickCaps = Joystick.GetCapabilities(this.deviceIndex);
				this.hasAxesOrButtons = joystickCaps.AxisCount > 0 || joystickCaps.ButtonCount > 0 || joystickCaps.HatCount > 0;
			}
		}
Example #6
0
        private static GamePadState PlatformGetState(int index, GamePadDeadZone deadZoneMode)
        {
            GamePadState state;
            if (index == 0 && Back)
            {
                // Consume state
                Back = false;
                state = new GamePadState(new GamePadThumbSticks(), new GamePadTriggers(), new GamePadButtons(Buttons.Back), new GamePadDPad());
            }
            else
                state = new GamePadState();

            return state;
        }
        public GamePadState GetState(int index)
        {
            XInputState xstate;
            XInputErrorCode error = xinput.GetState((XInputUserIndex)index, out xstate);

            GamePadState state = new GamePadState();
            if (error == XInputErrorCode.Success)
            {
                state.SetConnected(true);

                state.SetAxis(GamePadAxes.LeftX, xstate.GamePad.ThumbLX);
                state.SetAxis(GamePadAxes.LeftY, xstate.GamePad.ThumbLY);
                state.SetAxis(GamePadAxes.RightX, xstate.GamePad.ThumbRX);
                state.SetAxis(GamePadAxes.RightY, xstate.GamePad.ThumbRY);

                state.SetTriggers(xstate.GamePad.LeftTrigger, xstate.GamePad.RightTrigger);

                state.SetButton(TranslateButtons(xstate.GamePad.Buttons), true);
            }

            return state;
        }
Example #8
0
 public static void Initialize()
 {
     JoyPrev = JoyState = GamePad.GetState(PlayerIndex.One);
     KeyPrev = KeyState = Keyboard.GetState(PlayerIndex.One);
 }
 public void Update(GameTime gameTime, KeyboardState teclado, KeyboardState tecladoAnterior, GamePadState _controle, GamePadState _controleanterior)
 {
     if (!playing_musica)
     {
         MediaPlayer.Play(musica);
         playing_musica = true;
     }
     jogador1.Update(gameTime, teclado, tecladoAnterior, _controle, _controleanterior);
     inimigo1.Update(gameTime);
 }
Example #10
0
 private bool Release(GamePadButtons k, GamePadState _state) => !Press(k, _state);
        public void updateCam()
        {
            if (songStarted && t > 2)
            {
                var height = terrainRenderer.GetAltitude(camera.Transform.Position);
                if (0.5f + height > camera.Transform.Position.Y)
                {
                    // camera crashes
                    noisyToggle = true;
                    waveOut.Pause();
                    MediaPlayer.Play(staticNoise);
                    Time.timers.Add(new EventTimer(cameraRestore, 2));
                }
                else if (2 + height > camera.Transform.Position.Y)
                {
                    // graze
                }
            }
            else
            if (camera.Transform.LocalPosition.Y < 22.5f)
            {
                cameraCurrectVelocity.Y += 0.025f;
            }

            // Input
            if ((int)ControllingPlayer < 5)
            {
                GamePadState state = GamePad.GetState(ControllingPlayer);
                if (state.IsButtonDown(Buttons.Back))
                {
                    ExitGameplay();
                }
                curLeftRight += Time.ElapsedGameTime * leftRightSpeed * -state.ThumbSticks.Left.X;
                curUpDown    += Time.ElapsedGameTime * upDownSpeed * -state.ThumbSticks.Left.Y;
            }
            else
            {
                if (InputManager.IsKeyPressed(Keys.Escape))
                {
                    ExitGameplay();
                }

                if (InputManager.IsKeyDown(Keys.A))
                {
                    curLeftRight += Time.ElapsedGameTime * leftRightSpeed;
                }
                if (InputManager.IsKeyDown(Keys.D))
                {
                    curLeftRight -= Time.ElapsedGameTime * leftRightSpeed;
                }

                if (InputManager.IsKeyDown(Keys.W))
                {
                    curUpDown -= Time.ElapsedGameTime * upDownSpeed;
                }
                if (InputManager.IsKeyDown(Keys.S))
                {
                    curUpDown += Time.ElapsedGameTime * upDownSpeed;
                }
            }

            cameraCurrectVelocity.X += curLeftRight;
            cameraCurrectVelocity.Y += curUpDown;

            cameraCurrectVelocity.Y = MathHelper.Clamp(cameraCurrectVelocity.Y, -0.12f, 0.12f);
            cameraCurrectVelocity.X = MathHelper.Clamp(cameraCurrectVelocity.X, -0.2f, 0.2f);
            cameraCurrectVelocity.Z = (camForwardSpeed) * Time.ElapsedGameTime + cameraCurrectVelocity.Y / 5;

            camera.Transform.lookAt(camera.Transform.LocalPosition + cameraCurrectVelocity);
            camera.Transform.LocalPosition += cameraCurrectVelocity;
            camera.Transform.Rotate(camera.Transform.Forward, 2 * cameraCurrectVelocity.X);

            curLeftRight /= 1.2f;
            curUpDown    /= 1.2f;
        }
            public override GamePadState GetState()
            {
                var gamePadState = new GamePadState();

                State xinputState;
                if (instance.GetState(out xinputState))
                {
                    gamePadState.IsConnected = true;
                    gamePadState.Buttons = (GamePadButton)xinputState.Gamepad.Buttons;

                    gamePadState.LeftTrigger = xinputState.Gamepad.LeftTrigger / 255.0f;
                    gamePadState.RightTrigger = xinputState.Gamepad.RightTrigger / 255.0f;

                    gamePadState.LeftThumb.X = ClampDeadZone(xinputState.Gamepad.LeftThumbX / 32768.0f, Gamepad.LeftThumbDeadZone / 32768.0f);
                    gamePadState.LeftThumb.Y = ClampDeadZone(xinputState.Gamepad.LeftThumbY / 32768.0f, Gamepad.LeftThumbDeadZone / 32768.0f);

                    gamePadState.RightThumb.X = ClampDeadZone(xinputState.Gamepad.RightThumbX / 32768.0f, Gamepad.RightThumbDeadZone / 32768.0f);
                    gamePadState.RightThumb.Y = ClampDeadZone(xinputState.Gamepad.RightThumbY / 32768.0f, Gamepad.RightThumbDeadZone / 32768.0f);
                }

                return gamePadState;
            }
            public override GamePadState GetState()
            {
                var gamePadState = new GamePadState();

                if (SDL.SDL_GameControllerGetAttached(instance) == SDL.SDL_bool.SDL_TRUE)
                {
                    const float LeftThumbDeadZone = 7849.0f/32768.0f;
                    const float RightThumbDeadZone = 8689.0f/32768.0f;

                    gamePadState.IsConnected = true;
                    // Iterate through all buttons
                    GamePadButton state = GamePadButton.None;
                    if (SDL.SDL_GameControllerGetButton(instance, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_A) == 1)
                        state |= GamePadButton.A;
                    if (SDL.SDL_GameControllerGetButton(instance, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_B) == 1)
                        state |= GamePadButton.B;
                    if (SDL.SDL_GameControllerGetButton(instance, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_BACK) == 1)
                        state |= GamePadButton.Back;
                    if (SDL.SDL_GameControllerGetButton(instance, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_DOWN) == 1)
                        state |= GamePadButton.PadDown;
                    if (SDL.SDL_GameControllerGetButton(instance, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_UP) == 1)
                        state |= GamePadButton.PadUp;
                    if (SDL.SDL_GameControllerGetButton(instance, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_LEFT) == 1)
                        state |= GamePadButton.PadLeft;
                    if (SDL.SDL_GameControllerGetButton(instance, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_RIGHT) == 1)
                        state |= GamePadButton.PadRight;
                    if (SDL.SDL_GameControllerGetButton(instance, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_X) == 1)
                        state |= GamePadButton.X;
                    if (SDL.SDL_GameControllerGetButton(instance, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_Y) == 1)
                        state |= GamePadButton.Y;
                    if (SDL.SDL_GameControllerGetButton(instance, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSHOULDER) == 1)
                        state |= GamePadButton.LeftShoulder;
                    if (SDL.SDL_GameControllerGetButton(instance, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) == 1)
                        state |= GamePadButton.RightShoulder;
                    if (SDL.SDL_GameControllerGetButton(instance, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSTICK) == 1)
                        state |= GamePadButton.LeftThumb;
                    if (SDL.SDL_GameControllerGetButton(instance, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSTICK) == 1)
                        state |= GamePadButton.RightThumb;
                    if (SDL.SDL_GameControllerGetButton(instance, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_START) == 1)
                        state |= GamePadButton.Start;

                    gamePadState.Buttons = state;

                    var leftThumbX = SDL.SDL_GameControllerGetAxis(instance, SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTX)/32768.0f;
                    var leftThumbY = SDL.SDL_GameControllerGetAxis(instance, SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTY)/32768.0f;

                    gamePadState.LeftThumb.X = ClampDeadZone(leftThumbX, LeftThumbDeadZone);
                    gamePadState.LeftThumb.Y = ClampDeadZone(leftThumbY, LeftThumbDeadZone);

                    var rightThumbX = SDL.SDL_GameControllerGetAxis(instance, SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTX)/32768.0f;
                    var rightThumbY = SDL.SDL_GameControllerGetAxis(instance, SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTY)/32768.0f;

                    gamePadState.RightThumb.X = ClampDeadZone(rightThumbX, RightThumbDeadZone);
                    gamePadState.RightThumb.Y = ClampDeadZone(rightThumbY, RightThumbDeadZone);

                    gamePadState.LeftTrigger = SDL.SDL_GameControllerGetAxis(instance, SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERLEFT)/32768.0f;
                    gamePadState.RightTrigger = SDL.SDL_GameControllerGetAxis(instance, SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERRIGHT)/32768.0f;

                }
                return gamePadState;
            }
 ////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////
 public virtual void SendGamePadState(PlayerIndex playerIndex, GamePadState state, GameTime gameTime)
 {
     UpdateGamePad(playerIndex, state, gameTime);
 }
Example #15
0
    void Update()
    {
        //インプット関連
        if (!playerInputSet_ || !prevState_.IsConnected)
        {
            playerIndex_    = (PlayerIndex)0;
            playerInputSet_ = true;
        }
        prevState_ = padState_;
        padState_  = GamePad.GetState(playerIndex_);
        //インプット関連


        if (prevState_.Buttons.B == ButtonState.Released && padState_.Buttons.B == ButtonState.Pressed ||
            prevState_.Buttons.A == ButtonState.Released && padState_.Buttons.A == ButtonState.Pressed ||
            prevState_.Buttons.X == ButtonState.Released && padState_.Buttons.X == ButtonState.Pressed ||
            prevState_.Buttons.Y == ButtonState.Released && padState_.Buttons.Y == ButtonState.Pressed)
        {
            SoundManager.GetInstance.PlaySE("input_SE3");
            if (!noiseParticle.skipFrag)
            {
                noiseParticle.skipFrag = true; return;
            }
            sceneChangeFlag = true;
        }

        if (sceneChangeFlag)
        {
            CameraPos = transform.position;
            switch (cameraMoveType)
            {
            case CameraMoveType.Rotate:
                var aim = SurveillanceCamera.transform.position - CameraPos;
                // var look = Vector3.RotateTowards(transform.forward, aim, 0.5f * Time.deltaTime, 0f);
                //transform.rotation = Quaternion.LookRotation(look);

                transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(aim), time);
                time += Time.deltaTime;
                if (time >= 1)
                {
                    cameraMoveType = CameraMoveType.Move;
                }
                //Debug.Log("カメラ回転中:" + (transform.position - look) + "見たい数:" + CameraRota);
                break;

            case CameraMoveType.Move:
                transform.position = SurveillanceCamera.transform.position;
                var target = Player.transform.position - CameraPos;
                var look_  = Quaternion.LookRotation(target);
                transform.localRotation = look_;
                time += Time.deltaTime * 0.5f;

                if (time >= 1.5)
                {
                    cameraMoveType = CameraMoveType.Up;
                }
                break;

            case CameraMoveType.Up:
                crtNoise.CRTFlag = true;
                cameraMoveType   = CameraMoveType.None;
                break;

            case CameraMoveType.None:
                break;
            }
        }
    }
Example #16
0
 internal GamePadData(PlayerIndex playerIndex)
 {
     _playerIndex   = playerIndex;
     _previousState = new GamePadState();
     _currentState  = Microsoft.Xna.Framework.Input.GamePad.GetState(_playerIndex);
 }
Example #17
0
 public void Update(GamePadState gamePadState, KeyboardState keyboardState)
 {
     Update(gamePadState);
     Update(keyboardState);
 }
Example #18
0
 public void Update(GamePadState gamePadState)
 {
     currentGamePadState = gamePadState;
     lastGamePadState    = gamePadState;
 }
        public override void Update(GameTime gameTime)
        {
            gamepadstate = GamePad.GetState(PlayerIndex.One);

            levelOneButton.Update(gameTime);
            levelTwoButton.Update(gameTime);
            levelThreeButton.Update(gameTime);
            levelFourButton.Update(gameTime);
            levelFiveButton.Update(gameTime);

            /*
             * if (levelOneButton.masterButtonEffect == true || (gamepadstate.IsButtonDown(Buttons.A)) || (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.A)))
             * {
             *
             *  displayLoading = true;
             *  MediaPlayer.Stop();
             *  DataContractSerializer ds = new DataContractSerializer(typeof(OpeningTitleScreen));
             *  FileStream fs = new FileStream("StrongTitleScreen.xml", FileMode.Open);
             *  XmlDictionaryReader reader =
             *      XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
             *  ScreenManager.Instance.currentTitleScreen = (OpeningTitleScreen)ds.ReadObject(reader);
             *  fs.Close();
             *  ScreenManager.Instance.AddScreen(ScreenManager.Instance.currentTitleScreen);
             * }*/

            if (levelTwoButton.masterButtonEffect == true || (gamepadstate.IsButtonDown(Buttons.B)) || (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.B)))
            {
                // this is for the hands gaame. uncomment this for hands game effects

                /*
                 * displayLoading = true;
                 * MediaPlayer.Stop();
                 * DataContractSerializer ds = new DataContractSerializer(typeof(OpeningTitleScreen));
                 * FileStream fs = new FileStream("HandsTitleScreen.xml", FileMode.Open);
                 * XmlDictionaryReader reader =
                 *  XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
                 * ScreenManager.Instance.currentTitleScreen = (OpeningTitleScreen)ds.ReadObject(reader);
                 * fs.Close();
                 * ScreenManager.Instance.AddScreen(ScreenManager.Instance.currentTitleScreen);
                 */

                //this is for the wakanda con version of the game

                displayLoading = true;
                MediaPlayer.Stop();
                DataContractSerializer ds     = new DataContractSerializer(typeof(OpeningTitleScreen));
                FileStream             fs     = new FileStream("WakandaTitleScreen.xml", FileMode.Open);
                XmlDictionaryReader    reader =
                    XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
                ScreenManager.Instance.currentTitleScreen = (OpeningTitleScreen)ds.ReadObject(reader);
                fs.Close();
                ScreenManager.Instance.AddScreen(ScreenManager.Instance.currentTitleScreen);
            }

            /*
             * if (levelThreeButton.masterButtonEffect == true || (gamepadstate.IsButtonDown(Buttons.X)) || (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.X)))
             * {
             *  displayLoading = true;
             *  MediaPlayer.Stop();
             *  DataContractSerializer ds = new DataContractSerializer(typeof(OpeningTitleScreen));
             *  FileStream fs = new FileStream("RopeTitleScreen.xml", FileMode.Open);
             *  XmlDictionaryReader reader =
             *      XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
             *  ScreenManager.Instance.currentTitleScreen = (OpeningTitleScreen)ds.ReadObject(reader);
             *  fs.Close();
             *  ScreenManager.Instance.AddScreen(ScreenManager.Instance.currentTitleScreen);
             * }
             */
            /*
             * if (levelFourButton.masterButtonEffect == true || (gamepadstate.IsButtonDown(Buttons.Y)) || (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Y)))
             * {
             *  displayLoading = true;
             *  MediaPlayer.Stop();
             *  DataContractSerializer ds = new DataContractSerializer(typeof(OpeningTitleScreen));
             *  FileStream fs = new FileStream("LevelTwoTitleScreen.xml", FileMode.Open);
             *  XmlDictionaryReader reader =
             *      XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
             *  ScreenManager.Instance.currentTitleScreen = (OpeningTitleScreen)ds.ReadObject(reader);
             *  fs.Close();
             *  ScreenManager.Instance.AddScreen(ScreenManager.Instance.currentTitleScreen);
             * }
             *
             * if (levelFiveButton.masterButtonEffect == true || (gamepadstate.IsButtonDown(Buttons.Start)) || (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Enter)))
             * {
             *  displayLoading = true;
             *  MediaPlayer.Stop();
             *  DataContractSerializer ds = new DataContractSerializer(typeof(OpeningTitleScreen));
             *  FileStream fs = new FileStream("DeceptionLevelTwoTitleScreen.xml", FileMode.Open);
             *  XmlDictionaryReader reader =
             *      XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
             *  ScreenManager.Instance.currentTitleScreen = (OpeningTitleScreen)ds.ReadObject(reader);
             *  fs.Close();
             *  ScreenManager.Instance.AddScreen(ScreenManager.Instance.currentTitleScreen);
             * }
             */
        }
Example #20
0
    /// <summary>
    /// reads controller inputs
    /// </summary>
    void Update()
    {
        //grab the current state
        currentState = GamePad.GetState(playerIndex);
        //if start button was just pressed.
        if (currentState.Buttons.Start == ButtonState.Pressed && previousState.Buttons.Start == ButtonState.Released ||
            currentState.Buttons.A == ButtonState.Pressed && previousState.Buttons.A == ButtonState.Released)
        {
            //call activate button.
            Debug.Log("Start Button Pressed.");
            ActivateButton();
        }
        #region OldUpdate1

        /*
         * //check to see if the player pushed the A button
         * if (currentState.Buttons.A == ButtonState.Pressed)
         * {
         *  //set current player as active.
         *  int activateCheck = StaticSpawnController.GetSetPlayers();
         *  StaticSpawnController.ActivatePlayer(playerIndex, true);
         *
         *  //if is player 1 and not active or is player 2 and not active
         *  if ((playerIndex == PlayerIndex.One && activateCheck != 1 && activateCheck != 3) ||
         *      (playerIndex == PlayerIndex.Two && activateCheck != 2 && activateCheck != 3))
         *  {
         *      //set the toSelect button so start button presses can now be used
         *      toSelect = StartGameButton;
         *      //set start hi
         *      StartHighlight.enabled = true;
         *  }
         * }
         * //*/
        #endregion
        //NOTE:  Doesn't work with some XInput emulated device drivers like the popular PS3 Controller one
        //destroy the player instance if the controller disconnects
        if (currentState.IsConnected == false)
        {
            #region OldUpdate2

            /*
             *
             * //if player controller disconnects at the lobby, remove them from the active script.
             * StaticSpawnController.ActivatePlayer(playerIndex, false);
             * if (StaticSpawnController.GetSetPlayers() == 0)
             * {
             *  toSelect = null;
             *  StartHighlight.enabled = false;
             * }
             * //text.enabled = true;
             * //*/
            #endregion
            return;
        }
        else
        {
            #region OldUpdate3

            /*
             * //call action selection
             * ActionSelection();
             * //*/

            /*
             * //remove the player call if the player pushed the Back button
             * if (currentState.Buttons.Back == ButtonState.Pressed)
             * {
             *  //check for players
             *  int removeCheck = StaticSpawnController.GetSetPlayers();
             *  //if appropriate player is activated when they hit the back button,
             *  if ((playerIndex == PlayerIndex.One && removeCheck != 0 && removeCheck != 2) ||
             *      (playerIndex == PlayerIndex.Two && removeCheck != 0 && removeCheck != 1))
             *  {
             *      //set that player to false
             *      StaticSpawnController.ActivatePlayer(playerIndex, false);
             *      //text.enabled = true;
             *      //set screen to null the toSelect button and highlighters if there
             *      //are no active players
             *      if (StaticSpawnController.GetSetPlayers() == 0)
             *      {
             *          toSelect = null;
             *          StartHighlight.enabled = false;
             *      }
             *      return;
             *  }
             *
             * }
             * //*/
            #endregion
            //update packet numbers
            if (currentState.PacketNumber > lastPacketNumber)
            {
                lastPacketNumber = currentState.PacketNumber;
                lastPacketTime   = Time.time;
            }
            else
            {
                //NOTE:  Doesn't work with some XInput emulated device drivers like the popular PS3 Controller one
                if (Time.time - lastPacketTime > 10)
                {
                    //controller has been idle for 10 seconds
                }
            }
        }
        //Set the previous state to the current state and run the set Highlighter.
        previousState = currentState;
        SetHighlighter();
    }
Example #21
0
        public override void Update(float dt, KeyboardState keyboardInput, MouseState mouseInput, GamePadState gamePadInput, Engine Engine, GameplayType gamePlayType)
        {
            //For access from Other Referenced Classes
            this.Engine = Engine;

            //Turn Off Mouse if Right Button is Down
            if (mouseInput.RightButton == ButtonState.Pressed || gamePlayType == GameplayType.level)
            {
                Engine.Game.IsMouseVisible = false;
                Yaw   += (Engine.GraphicsDevice.Viewport.Width / 2 - mouseInput.X) * dt * .12f;
                Pitch += (Engine.GraphicsDevice.Viewport.Height / 2 - mouseInput.Y) * dt * .12f;
            }
            else if (gamePlayType == GameplayType.Sandbox)
            {
                Engine.Game.IsMouseVisible = true;
            }
#endif

            WorldMatrix = Matrix.CreateFromAxisAngle(Vector3.Right, Pitch) * Matrix.CreateFromAxisAngle(Vector3.Up, Yaw);

            if (isChaseCameraMode)
            {
                Vector3 offset;
                if (transformOffset)
                {
                    offset = Matrix3X3.Transform(offsetFromChaseTarget, entityToChase.BufferedStates.InterpolatedStates.OrientationMatrix);
                }
                else
                {
                    offset = offsetFromChaseTarget;
                }
                Vector3 lookAt    = entityToChase.BufferedStates.InterpolatedStates.Position + offset;
                Vector3 backwards = WorldMatrix.Backward;

                //Find the earliest ray hit that isn't the chase target to position the camera appropriately.
                RayCastResult result;
                if (entityToChase.Space.RayCast(new Ray(lookAt, backwards), distanceToTarget, rayCastFilter, out result))
                {
                    Position = lookAt + (result.HitData.T) * backwards; //Put the camera just before any hit spot.
                }
                else
                {
                    Position = lookAt + (distanceToTarget) * backwards;
                }
            }
            else if (UseMovementControls)
            {
                //Only move around if the camera has control over its own position.
                float distance = Speed * dt;
#if !WINDOWS
                MoveForward(gamePadInput.ThumbSticks.Left.Y * distance);
                MoveRight(gamePadInput.ThumbSticks.Left.X * distance);
                if (gamePadInput.IsButtonDown(Buttons.LeftStick))
                {
                    MoveUp(distance);
                }
                if (gamePadInput.IsButtonDown(Buttons.RightStick))
                {
                    MoveUp(-distance);
                }
#endif

                if (keyboardInput.IsKeyDown(Keys.W))
                {
                    MoveForward(distance);
                }
                if (keyboardInput.IsKeyDown(Keys.S))
                {
                    MoveForward(-distance);
                }
                if (keyboardInput.IsKeyDown(Keys.A))
                {
                    MoveRight(-distance);
                }
                if (keyboardInput.IsKeyDown(Keys.D))
                {
                    MoveRight(distance);
                }
                if (keyboardInput.IsKeyDown(Keys.Q))
                {
                    MoveUp(distance);
                }
                if (keyboardInput.IsKeyDown(Keys.Z))
                {
                    MoveUp(-distance);
                }
            }

            WorldMatrix = WorldMatrix * Matrix.CreateTranslation(Position);
            View        = Matrix.Invert(WorldMatrix);

            base.Update(dt, keyboardInput, mouseInput, gamePadInput, Engine, gamePlayType);
        }
Example #22
0
 internal void Update()
 {
     PreviousState = State;
     State = OpenTK.Input.GamePad.GetState(DeviceID);
     Capabilities = OpenTK.Input.GamePad.GetCapabilities(DeviceID);
 }
        public void checkControllerInput()
        {
            if (_gcapi_Write == null)
                return;

            bool boolOverride = false;

            if (frmMain.boolIDE)
                boolOverride = true;

            if ((_gcapi_IsConnected() == 1) || (boolOverride == true))
            {
                //Update gamepad status
                _controls = GamePad.GetState(PlayerIndex.One);

                if (_XboxCount == 0) { _XboxCount = Enum.GetNames(typeof(xbox)).Length; }
                byte[] output = new byte[_XboxCount];

                if (_controls.DPad.Left) { output[(int)xbox.left] = Convert.ToByte(100); }
                if (_controls.DPad.Right) { output[(int)xbox.right] = Convert.ToByte(100); }
                if (_controls.DPad.Up) { output[(int)xbox.up] = Convert.ToByte(100); }
                if (_controls.DPad.Down) { output[(int)xbox.down] = Convert.ToByte(100); }

                if (_controls.Buttons.A) { output[(int)xbox.a] = Convert.ToByte(100); }
                if (_controls.Buttons.B) { output[(int)xbox.b] = Convert.ToByte(100); }
                if (_controls.Buttons.X) { output[(int)xbox.x] = Convert.ToByte(100); }
                if (_controls.Buttons.Y) { output[(int)xbox.y] = Convert.ToByte(100); }

                if (_controls.Buttons.Start) { output[(int)xbox.start] = Convert.ToByte(100); }
                if (_controls.Buttons.Guide) { output[(int)xbox.home] = Convert.ToByte(100); }
                if (_controls.Buttons.Back)
                {
                    if (system.boolBlockMenuButton == false)
                    {
                        _MenuWait++;
                        if (system.boolMenu == false)
                            if (_MenuWait >= _MenuShow + 20)
                                openMenu();
                    }

                    //Remap back buton to touchpad
                    if (system.boolPS4ControllerMode)
                        output[(int)xbox.touch] = Convert.ToByte(100);
                    else
                        output[(int)xbox.back] = Convert.ToByte(100);
                }

                if (_controls.Buttons.LeftShoulder) { output[(int)xbox.leftShoulder] = Convert.ToByte(100); }
                if (_controls.Buttons.RightShoulder) { output[(int)xbox.rightShoulder] = Convert.ToByte(100); }
                if (_controls.Buttons.LeftStick) { output[(int)xbox.leftStick] = Convert.ToByte(100); }
                if (_controls.Buttons.RightStick) { output[(int)xbox.rightStick] = Convert.ToByte(100); }

                if (_controls.Triggers.Left > 0) { output[(int)xbox.leftTrigger] = Convert.ToByte(_controls.Triggers.Left * 100); }
                if (_controls.Triggers.Right > 0) { output[(int)xbox.rightTrigger] = Convert.ToByte(_controls.Triggers.Right * 100); }

                double dblLX = _controls.ThumbSticks.Left.X * 100;
                double dblLY = _controls.ThumbSticks.Left.Y * 100;
                double dblRX = _controls.ThumbSticks.Right.X * 100;
                double dblRY = _controls.ThumbSticks.Right.Y * 100;

                if (system.boolNormalizeControls == true)
                {
                    normalGamepad(ref dblLX, ref dblLY);
                    normalGamepad(ref dblRX, ref dblRY);
                }
                else
                {
                    dblLY = -dblLY;
                    dblRY = -dblRY;
                }

                if (dblLX != 0) { output[(int)xbox.leftX] = (byte)Convert.ToSByte((int)(dblLX)); }
                if (dblLY != 0) { output[(int)xbox.leftY] = (byte)Convert.ToSByte((int)(dblLY)); }
                if (dblRX != 0) { output[(int)xbox.rightX] = (byte)Convert.ToSByte((int)(dblRX)); }
                if (dblRY != 0) { output[(int)xbox.rightY] = (byte)Convert.ToSByte((int)(dblRY)); }

                if (CMHomeCount > 0)
                {
                    output[(int)xbox.home] = Convert.ToByte(100);
                    CMHomeCount--;
                }

                if (Ps4Touchpad == true)
                    output[(int)xbox.touch] = Convert.ToByte(100);

                if (_boolLoadShortcuts)
                    output = checkKeys(output);

                int intTarget = -1;
                if (system.boolPS4ControllerMode == false) { intTarget = (int)xbox.back; } else { intTarget = (int)xbox.touch; }
                /*
                //Back button. Wait until released as its also the menu button
                if (intTarget > -1)
                {
                    if (system.boolBlockMenuButton)
                    {
                        if (output[intTarget] == 100)
                        {
                            _boolHoldBack = true;
                            output[intTarget] = Convert.ToByte(0);
                            _MenuWait++;
                            if (!system.boolMenu)
                            {
                                if (_MenuWait >= _MenuShow)
                                {
                                    _boolHoldBack = false;
                                    openMenu();
                                }
                            }
                        }
                        else
                        {
                            if (_boolHoldBack == true)
                            {
                                _boolHoldBack = false;
                                output[intTarget] = Convert.ToByte(100);
                                _MenuWait = 0;
                            }
                            else
                                _MenuWait = 0;
                        }
                    }
                }
                */
                if (keyboardInterface != null && keyboardInterface.output != null)
                {
                    for (int intCount = 0; intCount < _XboxCount; intCount++)
                    {
                        if (keyboardInterface.output[intCount] != 0)
                            output[intCount] = keyboardInterface.output[intCount];
                    }
                }

                //Block gamepad rumble
                //gcapi_WriteEX(uint8_t *outpacket, uint8_t size)
                /*
                [0xFF,0x01 : 2 byte, Packet Signature]
            [Update LED Command (0,1) : 1 byte]
            [LED 1 Status : 1 byte]
            [LED 2 Status : 1 byte]
            [LED 3 Status : 1 byte]
            [LED 4 Status : 1 byte]
            [Reset LEDs Command (0,1) : 1 byte]
            [Update Rumble Command (0,1) : 1 byte]
            [Rumble 1 Value : 1 byte]
            [Rumble 2 Value : 1 byte]
            [Rumble 3 Value : 1 byte]
            [Rumble 4 Value : 1 byte]
            [Reset Rumble Command (0,1) : 1 byte]
            [Block Rumble Command (0,1) : 1 byte]
            [Turn Off Controller Command (0,1) : 1 byte]
            [Button States : 36 bytes - same format as gcapi_Write]
                _gcapi_WriteEx(output);
                 */

                _gcapi_Write(output);

                if (system.boolUseRumble == true)
                {
                    if (_devId == DevPID.TitanOne)
                    {
                        GCAPI_REPORT_TITANONE report = new GCAPI_REPORT_TITANONE();
                        if (_gcapi_Read_TO(ref report) != IntPtr.Zero)
                            GamePad.SetState(PlayerIndex.One, report.rumble[0], report.rumble[1]);
                    }
                    else
                    {
                        GCAPI_REPORT_CONTROLLERMAX report = new GCAPI_REPORT_CONTROLLERMAX();
                        if (_gcapi_Read_CM(ref report) != IntPtr.Zero)
                            GamePad.SetState(PlayerIndex.One, report.rumble[0], report.rumble[1]);

                    }
                }
            }
            else
            {
                //If device just disconnected open up notice to tell user
                if (_boolNoticeTODisconnected == false)
                {
                    system.debug("titanOne.log", "[NOTE] " + _strTODevice + " is disconnected");
                    _boolNoticeTODisconnected = true;
                }

                //Keep alive for opening the menu
                _controls = GamePad.GetState(PlayerIndex.One);
                if (_controls.Buttons.Back)
                {
                    if (system.boolBlockMenuButton == false)
                    {
                        _MenuWait++;
                        if (!system.boolMenu)
                        {
                            if (_MenuWait >= _MenuShow + 20)
                                frmMain.openMenu();
                        }
                    }
                }
            }
        }
Example #24
0
 public abstract void Update(GameTime gameTime, GamePadState pad, GamePadState oldpad);
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////
        private ButtonState GetVectorState(GamePadButton button, GamePadState state)
        {
            //ButtonState ret = ButtonState.Released;
              //bool down = false;
              //float t = ClickThreshold;

              //switch (button)
              //{
              //  case GamePadButton.LeftStickLeft: down = state.ThumbSticks.Left.X < -t; break;
              //  case GamePadButton.LeftStickRight: down = state.ThumbSticks.Left.X > t; break;
              //  case GamePadButton.LeftStickUp: down = state.ThumbSticks.Left.Y > t; break;
              //  case GamePadButton.LeftStickDown: down = state.ThumbSticks.Left.Y < -t; break;

              //  case GamePadButton.RightStickLeft: down = state.ThumbSticks.Right.X < -t; break;
              //  case GamePadButton.RightStickRight: down = state.ThumbSticks.Right.X > t; break;
              //  case GamePadButton.RightStickUp: down = state.ThumbSticks.Right.Y > t; break;
              //  case GamePadButton.RightStickDown: down = state.ThumbSticks.Right.Y < -t; break;

              //  case GamePadButton.LeftTrigger: down = state.Triggers.Left > t; break;
              //  case GamePadButton.RightTrigger: down = state.Triggers.Right > t; break;
              //}

              //ret = down ? ButtonState.Pressed : ButtonState.Released;

              //return ret;

            return new ButtonState();
        }
Example #26
0
        void ProcessGamePad(CCWindow window, GamePadState gps, PlayerIndex player)
        {
            var dispatcher = window.EventDispatcher;

            var lastState = new GamePadState();

            if (!priorGamePadState.ContainsKey(player) && gps.IsConnected)
            {
                gamePadConnection.IsConnected = true;
                gamePadConnection.Player      = (CCPlayerIndex)player;
                dispatcher.DispatchEvent(gamePadConnection);
            }

            if (priorGamePadState.ContainsKey(player))
            {
                lastState = priorGamePadState[player];
                // Notify listeners when the gamepad is connected/disconnected.
                if ((lastState.IsConnected != gps.IsConnected))
                {
                    gamePadConnection.IsConnected = false;
                    gamePadConnection.Player      = (CCPlayerIndex)player;
                    dispatcher.DispatchEvent(gamePadConnection);
                }
                // TODO: Check button pressed/released status for button tap events.
            }

            if (gps.IsConnected)
            {
                var caps = GamePad.GetCapabilities(player);

                if (caps.HasBackButton ||
                    caps.HasStartButton ||
                    caps.HasBigButton ||
                    caps.HasAButton ||
                    caps.HasBButton ||
                    caps.HasXButton ||
                    caps.HasYButton ||
                    caps.HasLeftShoulderButton ||
                    caps.HasRightShoulderButton)
                {
                    var back          = CCGamePadButtonStatus.NotApplicable;
                    var start         = CCGamePadButtonStatus.NotApplicable;
                    var system        = CCGamePadButtonStatus.NotApplicable;
                    var a             = CCGamePadButtonStatus.NotApplicable;
                    var b             = CCGamePadButtonStatus.NotApplicable;
                    var x             = CCGamePadButtonStatus.NotApplicable;
                    var y             = CCGamePadButtonStatus.NotApplicable;
                    var leftShoulder  = CCGamePadButtonStatus.NotApplicable;
                    var rightShoulder = CCGamePadButtonStatus.NotApplicable;

                    if (caps.HasBackButton)
                    {
                        back = (gps.Buttons.Back == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasStartButton)
                    {
                        start = (gps.Buttons.Start == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasBigButton)
                    {
                        system = (gps.Buttons.BigButton == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasAButton)
                    {
                        a = (gps.Buttons.A == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasBButton)
                    {
                        b = (gps.Buttons.B == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasXButton)
                    {
                        x = (gps.Buttons.X == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasYButton)
                    {
                        y = (gps.Buttons.Y == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasLeftShoulderButton)
                    {
                        leftShoulder = (gps.Buttons.LeftShoulder == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasRightShoulderButton)
                    {
                        rightShoulder = (gps.Buttons.RightShoulder == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }

                    gamePadButton.Back          = back;
                    gamePadButton.Start         = start;
                    gamePadButton.System        = system;
                    gamePadButton.A             = a;
                    gamePadButton.B             = b;
                    gamePadButton.X             = x;
                    gamePadButton.Y             = y;
                    gamePadButton.LeftShoulder  = leftShoulder;
                    gamePadButton.RightShoulder = rightShoulder;
                    gamePadButton.Player        = (CCPlayerIndex)player;

                    dispatcher.DispatchEvent(gamePadButton);
                }


                // Process the game sticks
                if ((caps.HasLeftXThumbStick ||
                     caps.HasLeftYThumbStick ||
                     caps.HasRightXThumbStick ||
                     caps.HasRightYThumbStick ||
                     caps.HasLeftStickButton ||
                     caps.HasRightStickButton))
                {
                    CCPoint vecLeft;
                    if (caps.HasLeftXThumbStick || caps.HasLeftYThumbStick)
                    {
                        vecLeft = new CCPoint(gps.ThumbSticks.Left);
                        vecLeft.Normalize();
                    }
                    else
                    {
                        vecLeft = CCPoint.Zero;
                    }
                    CCPoint vecRight;
                    if (caps.HasRightXThumbStick || caps.HasRightYThumbStick)
                    {
                        vecRight = new CCPoint(gps.ThumbSticks.Right);
                        vecRight.Normalize();
                    }
                    else
                    {
                        vecRight = CCPoint.Zero;
                    }
                    var left = new CCGameStickStatus();
                    left.Direction = vecLeft;
                    left.Magnitude = ((caps.HasLeftXThumbStick || caps.HasLeftYThumbStick) ? gps.ThumbSticks.Left.Length() : 0f);
                    left.IsDown    = ((caps.HasLeftStickButton) ? gps.IsButtonDown(Buttons.LeftStick) : false);
                    var right = new CCGameStickStatus();
                    right.Direction = vecRight;
                    right.Magnitude = ((caps.HasRightXThumbStick || caps.HasRightYThumbStick) ? gps.ThumbSticks.Right.Length() : 0f);
                    right.IsDown    = ((caps.HasLeftStickButton) ? gps.IsButtonDown(Buttons.RightStick) : false);

                    gamePadStick.Left   = left;
                    gamePadStick.Right  = right;
                    gamePadStick.Player = (CCPlayerIndex)player;

                    dispatcher.DispatchEvent(gamePadStick);
                }
                // Process the game triggers
                if (caps.HasLeftTrigger || caps.HasRightTrigger)
                {
                    //GamePadTriggerUpdate (caps.HasLeftTrigger ? gps.Triggers.Left : 0f, caps.HasRightTrigger ? gps.Triggers.Right : 0f, player);
                    gamePadTrigger.Left   = caps.HasLeftTrigger ? gps.Triggers.Left : 0f;
                    gamePadTrigger.Right  = caps.HasRightTrigger ? gps.Triggers.Right : 0f;
                    gamePadTrigger.Player = (CCPlayerIndex)player;

                    dispatcher.DispatchEvent(gamePadTrigger);
                }

                // Process the D-Pad
                if (caps.HasDPadDownButton ||
                    caps.HasDPadUpButton ||
                    caps.HasDPadLeftButton ||
                    caps.HasDPadRightButton)
                {
                    var leftButton  = CCGamePadButtonStatus.NotApplicable;
                    var rightButton = CCGamePadButtonStatus.NotApplicable;
                    var upButton    = CCGamePadButtonStatus.NotApplicable;
                    var downButton  = CCGamePadButtonStatus.NotApplicable;

                    if (caps.HasDPadDownButton)
                    {
                        downButton = (gps.DPad.Down == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasDPadUpButton)
                    {
                        upButton = (gps.DPad.Up == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasDPadLeftButton)
                    {
                        leftButton = (gps.DPad.Left == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasDPadRightButton)
                    {
                        rightButton = (gps.DPad.Right == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }

                    gamePadDPad.Down  = downButton;
                    gamePadDPad.Up    = upButton;
                    gamePadDPad.Left  = leftButton;
                    gamePadDPad.Right = rightButton;

                    gamePadDPad.Player = (CCPlayerIndex)player;

                    dispatcher.DispatchEvent(gamePadDPad);
                }
            }
            priorGamePadState[player] = gps;
        }
Example #27
0
        private void HandleGamePad()
        {
            if (!IsActiveScreen) return;

            bool succeeded = false;
            GamePadState gamePadState = new GamePadState();
            try
            {
                gamePadState = GamePad.GetState(0);
                succeeded = true;
            }
            catch (Exception) { }

            if (succeeded)
            {
                Manager.Player.MoveInput += gamePadState.ThumbSticks.Left;
                Manager.Player.HeadInput += gamePadState.ThumbSticks.Right;

                if (gamePadState.Buttons.X == ButtonState.Pressed && !pressedGamepadInteract)
                    Manager.Player.InteractInput = true;
                pressedGamepadInteract = gamePadState.Buttons.X == ButtonState.Pressed;

                if (gamePadState.Buttons.A == ButtonState.Pressed && !pressedGamepadApply)
                    Manager.Player.ApplyInput = true;
                pressedGamepadApply = gamePadState.Buttons.A == ButtonState.Pressed;

                if (gamePadState.Buttons.Y == ButtonState.Pressed && !pressedGamepadJump)
                    Manager.Player.JumpInput = true;
                pressedGamepadJump = gamePadState.Buttons.Y == ButtonState.Pressed;

                if (gamePadState.Buttons.LeftStick == ButtonState.Pressed && !pressedGamepadFlymode)
                    Manager.Player.FlymodeInput = true;
                pressedGamepadFlymode = gamePadState.Buttons.LeftStick == ButtonState.Pressed;

                if (gamePadState.Buttons.LeftShoulder == ButtonState.Pressed && !pressedGamepadSlotLeft)
                    Manager.Player.SlotLeftInput = true;
                pressedGamepadSlotLeft = gamePadState.Buttons.LeftShoulder == ButtonState.Pressed;

                if (gamePadState.Buttons.RightShoulder == ButtonState.Pressed && !pressedGamepadSlotRight)
                    Manager.Player.SlotRightInput = true;
                pressedGamepadSlotRight = gamePadState.Buttons.RightShoulder == ButtonState.Pressed;

                if (gamePadState.Buttons.Back == ButtonState.Pressed && !pressedGamepadInventory)
                    Manager.NavigateToScreen(new InventoryScreen(Manager));
                pressedGamepadInventory = gamePadState.Buttons.Back == ButtonState.Pressed;
            }
        }
 private void checkGamePads(Object sender, EventArgs e)
 {
     ActionEventArgs args = new ActionEventArgs(this.ActiveDevice);
     if (!args.GamePadState.Equals(oldgstate))
     {
         //call event
         OnGamePadAction(args);
         oldgstate = args.GamePadState;
     }
     if (!args.JoystickState.Equals(oldjstate))
     {
         //call event
         OnJoystickAction(args);
         oldjstate = args.JoystickState;
     }
 }
            public override GamePadState GetState()
            {
                var gamePadState = new GamePadState();

                // Get the current joystick state
                try
                {
                    if (instance == null)
                    {
                        if (directInput.IsDeviceAttached(key.Guid))
                        {
                            instance = new Joystick(directInput, key.Guid);
                        }
                        else
                        {
                            return gamePadState;
                        }
                    }

                    // Acquire the joystick
                    instance.Acquire();

                    // Make sure that the latest state is up to date
                    instance.Poll();

                    // Get the state
                    instance.GetCurrentState(ref joystickState);
                }
                catch (SharpDX.SharpDXException)
                {
                    // If there was an exception, dispose the native instance 
                    try
                    {
                        if (instance != null)
                        {
                            instance.Dispose();
                            instance = null;
                        }

                        // Return a GamePadState that specify that it is not connected
                        return gamePadState;
                    }
                    catch (Exception)
                    {
                    }
                }

                //Console.WriteLine(joystickState);
                gamePadState.IsConnected = true;

                gamePadState.Buttons = GamePadButton.None;
                if (joystickState.Buttons[0])
                {
                    gamePadState.Buttons |= GamePadButton.X;
                }
                if (joystickState.Buttons[1])
                {
                    gamePadState.Buttons |= GamePadButton.A;
                }
                if (joystickState.Buttons[2])
                {
                    gamePadState.Buttons |= GamePadButton.B;
                }
                if (joystickState.Buttons[3])
                {
                    gamePadState.Buttons |= GamePadButton.Y;
                }
                if (joystickState.Buttons[4])
                {
                    gamePadState.Buttons |= GamePadButton.LeftShoulder;
                }
                if (joystickState.Buttons[5])
                {
                    gamePadState.Buttons |= GamePadButton.RightShoulder;
                }
                if (joystickState.Buttons[6])
                {
                    gamePadState.LeftTrigger = 1.0f;
                }
                if (joystickState.Buttons[7])
                {
                    gamePadState.RightTrigger = 1.0f;
                }

                if (joystickState.Buttons[8])
                {
                    gamePadState.Buttons |= GamePadButton.Back;
                }
                if (joystickState.Buttons[9])
                {
                    gamePadState.Buttons |= GamePadButton.Start;
                }

                if (joystickState.Buttons[10])
                {
                    gamePadState.Buttons |= GamePadButton.LeftThumb;
                }
                if (joystickState.Buttons[11])
                {
                    gamePadState.Buttons |= GamePadButton.RightThumb;
                }

                int dPadRawValue = joystickState.PointOfViewControllers[0];
                if (dPadRawValue >= 0)
                {
                    int dPadValue = dPadRawValue / 4500;
                    switch (dPadValue)
                    {
                        case 0:
                            gamePadState.Buttons |= GamePadButton.PadUp;
                            break;
                        case 1:
                            gamePadState.Buttons |= GamePadButton.PadUp;
                            gamePadState.Buttons |= GamePadButton.PadRight;
                            break;
                        case 2:
                            gamePadState.Buttons |= GamePadButton.PadRight;
                            break;
                        case 3:
                            gamePadState.Buttons |= GamePadButton.PadRight;
                            gamePadState.Buttons |= GamePadButton.PadDown;
                            break;
                        case 4:
                            gamePadState.Buttons |= GamePadButton.PadDown;
                            break;
                        case 5:
                            gamePadState.Buttons |= GamePadButton.PadDown;
                            gamePadState.Buttons |= GamePadButton.PadLeft;
                            break;
                        case 6:
                            gamePadState.Buttons |= GamePadButton.PadLeft;
                            break;
                        case 7:
                            gamePadState.Buttons |= GamePadButton.PadLeft;
                            gamePadState.Buttons |= GamePadButton.PadUp;
                            break;
                    }
                }

                // Left Thumb
                gamePadState.LeftThumb = new Vector2(2.0f * (joystickState.X / 65535.0f - 0.5f), -2.0f * (joystickState.Y / 65535.0f - 0.5f));
                gamePadState.LeftThumb.X = ClampDeadZone(gamePadState.LeftThumb.X, GamePadAxisDeadZone);
                gamePadState.LeftThumb.Y = ClampDeadZone(gamePadState.LeftThumb.Y, GamePadAxisDeadZone);

                // Right Thumb
                gamePadState.RightThumb = new Vector2(2.0f * (joystickState.Z / 65535.0f - 0.5f), -2.0f * (joystickState.RotationZ / 65535.0f - 0.5f));
                gamePadState.RightThumb.X = ClampDeadZone(gamePadState.RightThumb.X, GamePadAxisDeadZone);
                gamePadState.RightThumb.Y = ClampDeadZone(gamePadState.RightThumb.Y, GamePadAxisDeadZone);

                return gamePadState;
            }
    private void FixedUpdate()
    {
        state = GamePad.GetState(playerIndex);

        //if (!TPC.GetComponent<ThirdPersonCamera>().stationaryMode)
        //{
        //    roll = state.ThumbSticks.Left.X;
        //    pitch = state.ThumbSticks.Left.Y;

        //}
        //else
        //{
        //    roll = state.ThumbSticks.Right.X;
        //    pitch = state.ThumbSticks.Right.Y;

        //    roll = roll * staticRotMultiplier;
        //    pitch = pitch * staticRotMultiplier;

        //}
        if (!state.IsConnected)
        {
            roll  = Input.GetAxis("Horizontal");
            pitch = Input.GetAxis("Vertical");
        }
        else
        {
            roll  = state.ThumbSticks.Left.X;
            pitch = state.ThumbSticks.Left.Y;
        }


        if (TPC.GetComponent <ThirdPersonCamera>().stationaryMode)
        {
            roll  = roll * staticRotMultiplier;
            pitch = pitch * staticRotMultiplier;
        }


        this.GetComponent <Rigidbody>().AddTorque(transform.forward * -1 * roll * rollSpeed * Time.fixedDeltaTime);
        this.GetComponent <Rigidbody>().AddTorque(transform.right * pitch * pitchSpeed * Time.fixedDeltaTime);

        //Yaw scheme
        yaw  = state.ThumbSticks.Right.X;
        VYaw = state.ThumbSticks.Right.Y;

        this.GetComponent <Rigidbody>().AddTorque(transform.up * yaw * yawSpeed * Time.fixedDeltaTime);
        this.GetComponent <Rigidbody>().AddTorque(transform.right * -1.0f * VYaw * VYawSpeed * Time.fixedDeltaTime);

        bool evasiveMode = false;

        if (state.IsConnected)
        {
            if (state.Buttons.B == ButtonState.Pressed)
            {
                evasiveMode = true;
            }
        }
        else
        {
            evasiveMode = Input.GetKey(KeyCode.RightShift);
        }

        //if(((Mathf.Abs(state.ThumbSticks.Right.X) > 0.1f) || (Mathf.Abs(state.ThumbSticks.Right.Y) > 0.1f))&&(TPC.GetComponent<ThirdPersonCamera>().stationaryMode == false))
        if ((evasiveMode) && (TPC.GetComponent <ThirdPersonCamera>().stationaryMode == false))
        {
            TPC.GetComponent <ThirdPersonCamera>().stationaryMode = true;
            TPC.GetComponent <ThirdPersonCamera>().statRotation   = TPC.transform;
        }
        //else if (((Mathf.Abs(state.ThumbSticks.Right.X) < 0.1f) && (Mathf.Abs(state.ThumbSticks.Right.Y) < 0.1f)) && (TPC.GetComponent<ThirdPersonCamera>().stationaryMode == true))
        else if ((!evasiveMode) && (TPC.GetComponent <ThirdPersonCamera>().stationaryMode == true))

        {
            TPC.GetComponent <ThirdPersonCamera>().stationaryMode = false;
        }

        bool accelerator = false;

        if (!state.IsConnected)
        {
            accelerator = Input.GetKey(KeyCode.LeftShift);
        }
        else
        {
            if (state.Buttons.RightShoulder == ButtonState.Pressed)
            {
                accelerator = true;
            }
        }


        if (accelerator)
        {
            float acc = 0;
            acc = accel * Time.fixedDeltaTime;
            if (TPC.GetComponent <ThirdPersonCamera>().stationaryMode)
            {
                acc = acc * staticAccMultiplier;
            }
            this.GetComponent <Rigidbody>().AddForce(transform.forward * acc);
        }
        else if (TPC.GetComponent <ThirdPersonCamera>().stationaryMode)
        {
            float acc = 0;
            acc = accel * Time.fixedDeltaTime;
            acc = acc * staticAccMultiplier;
            this.GetComponent <Rigidbody>().AddForce(transform.forward * acc);
        }


        //Trail length based on speed
        float t = this.gameObject.GetComponent <Rigidbody>().velocity.magnitude *trailMult;

        LTip.time = t;
        RTip.time = t;

        if (afterburnerOn)
        {
            this.GetComponent <AudioSource>().pitch = 0.8f + (this.GetComponent <Rigidbody>().velocity.magnitude *0.1f);
        }
    }
Example #31
0
        public void Update(float dt, KeyboardState keyboardInput, MouseState mouseInput, GamePadState gamePadInput)
        {
            Yaw   += (200 - mouseInput.X) * dt * .12f;
            Pitch += (200 - mouseInput.Y) * dt * .12f;
#endif

            WorldMatrix = Matrix.CreateFromAxisAngle(Vector3.Right, Pitch) * Matrix.CreateFromAxisAngle(Vector3.Up, Yaw);

            if (isChaseCameraMode)
            {
                Vector3 offset;
                if (transformOffset)
                {
                    offset = MathConverter.Convert(BEPUphysics.MathExtensions.Matrix3X3.Transform(MathConverter.Convert(offsetFromChaseTarget), entityToChase.BufferedStates.InterpolatedStates.OrientationMatrix));
                }
                else
                {
                    offset = offsetFromChaseTarget;
                }
                Vector3 lookAt    = MathConverter.Convert(entityToChase.BufferedStates.InterpolatedStates.Position) + offset;
                Vector3 backwards = WorldMatrix.Backward;

                //Find the earliest ray hit that isn't the chase target to position the camera appropriately.
                RayCastResult result;
                if (entityToChase.Space.RayCast(MathConverter.Convert(new Ray(lookAt, backwards)), distanceToTarget, rayCastFilter, out result))
                {
                    Position = lookAt + (result.HitData.T) * backwards; //Put the camera just before any hit spot.
                }
                else
                {
                    Position = lookAt + (distanceToTarget) * backwards;
                }
            }
            else if (UseMovementControls)
            {
                //Only move around if the camera has control over its own position.
                float distance = Speed * dt;
#if !WINDOWS
                MoveForward(gamePadInput.ThumbSticks.Left.Y * distance);
                MoveRight(gamePadInput.ThumbSticks.Left.X * distance);
                if (gamePadInput.IsButtonDown(Buttons.LeftStick))
                {
                    MoveUp(distance);
                }
                if (gamePadInput.IsButtonDown(Buttons.RightStick))
                {
                    MoveUp(-distance);
                }
#endif

                if (keyboardInput.IsKeyDown(Keys.E))
                {
                    MoveForward(distance);
                }
                if (keyboardInput.IsKeyDown(Keys.D))
                {
                    MoveForward(-distance);
                }
                if (keyboardInput.IsKeyDown(Keys.S))
                {
                    MoveRight(-distance);
                }
                if (keyboardInput.IsKeyDown(Keys.F))
                {
                    MoveRight(distance);
                }
                if (keyboardInput.IsKeyDown(Keys.A))
                {
                    MoveUp(distance);
                }
                if (keyboardInput.IsKeyDown(Keys.Z))
                {
                    MoveUp(-distance);
                }
            }

            WorldMatrix = WorldMatrix * Matrix.CreateTranslation(Position);
            ViewMatrix  = Matrix.Invert(WorldMatrix);
        }
    // Update is called once per frame
    void Update()
    {
        state = GamePad.GetState(playerIndex);

        /*
         * roll = state.ThumbSticks.Left.X;
         * pitch = state.ThumbSticks.Left.Y;
         *
         * this.GetComponent<Rigidbody>().AddTorque(transform.forward * -1 * roll * rollSpeed * Time.deltaTime);
         * this.GetComponent<Rigidbody>().AddTorque(transform.right * pitch * pitchSpeed * Time.deltaTime);
         */

        bool gunTrigger = false;

        if (state.IsConnected)
        {
            if (state.Buttons.LeftShoulder == ButtonState.Pressed)
            {
                gunTrigger = true;
            }
        }
        else
        {
            gunTrigger = Input.GetKey(KeyCode.Space);
        }

        if (gunTrigger)
        {
            gunLight.SetActive(true);
            if (gun1RefireTime <= 0)
            {
                if (leftGun)
                {
                    gun1.GetComponent <gun>().fire();
                    leftGun = false;
                }
                else
                {
                    gun2.GetComponent <gun>().fire();
                    leftGun = true;
                }
                gun1RefireTime = refireDelay;
            }
            else
            {
                gun1RefireTime -= Time.deltaTime;
            }

            //if (gun2RefireTime <= 0)
            //{
            //    gun2.GetComponent<gun>().fire();
            //    gun2RefireTime = refireDelay;
            //}
            //else
            //{
            //    gun2RefireTime -= Time.deltaTime;
            //}
            //gun1RefireTime -= Time.deltaTime;
            //gun2RefireTime -= Time.deltaTime;
        }
        else
        {
            gunLight.SetActive(false);
            gun1RefireTime = 0;
            //gun2RefireTime = 0.5f * refireDelay;
        }

        bool accelerator = false;

        if (state.IsConnected)
        {
            if (state.Buttons.RightShoulder == ButtonState.Pressed)
            {
                accelerator = true;
            }
        }
        else
        {
            accelerator = Input.GetKey(KeyCode.LeftShift);
        }

        if ((accelerator || (TPC.GetComponent <ThirdPersonCamera>().stationaryMode)) && (!afterburnerOn))
        {
            afterburner.GetComponent <ParticleSystem>().enableEmission = true;
            ABGlow.GetComponent <ParticleSystem>().enableEmission      = true;
            //afterburner.SetActive(true);
            afterburnerOn = true;
            this.GetComponent <AudioSource>().Play();
            cam.GetComponent <shake>().shakeSources++;
            burnerLight.SetActive(true);
        }
        if (((!accelerator) && (!TPC.GetComponent <ThirdPersonCamera>().stationaryMode)) && (afterburnerOn))
        {
            afterburner.GetComponent <ParticleSystem>().enableEmission = false;
            ABGlow.GetComponent <ParticleSystem>().enableEmission      = false;
            //afterburner.SetActive(false);
            afterburnerOn = false;
            this.GetComponent <AudioSource>().Stop();
            cam.GetComponent <shake>().shakeSources--;
            burnerLight.SetActive(false);
            if (cam.GetComponent <shake>().shakeSources < 0)
            {
                cam.GetComponent <shake>().shakeSources = 0;
            }
        }

        if ((state.Buttons.A == ButtonState.Pressed) && ((missileTimer + missileCooldown) < Time.time))
        {
            GameObject missInst = Instantiate(missile);
            if (leftMissile)
            {
                missInst.transform.position = missileLauncherL.transform.position;
                missInst.transform.rotation = missileLauncherL.transform.rotation;
                leftMissile = false;
            }
            else
            {
                missInst.transform.position = missileLauncherR.transform.position;
                missInst.transform.rotation = missileLauncherR.transform.rotation;
                leftMissile = true;
            }
            missInst.GetComponent <missileController>().owner = this.gameObject;
            missInst.GetComponent <Rigidbody>().velocity      = this.GetComponent <Rigidbody>().velocity;
            missileTimer = Time.time;
        }

        //death
        if (Input.GetKey(KeyCode.I))
        {
            die();
        }
    }
Example #33
0
        public void Update()
        {
            var buttonarray = new Buttons[14] {
                Buttons.A, Buttons.B, Buttons.Y, Buttons.X, Buttons.DPadUp,
                Buttons.DPadLeft, Buttons.DPadDown, Buttons.DPadRight, Buttons.Back, Buttons.Start, Buttons.LeftShoulder,
                Buttons.RightShoulder, Buttons.LeftTrigger, Buttons.RightTrigger
            };

            var attackarray = new Buttons[] { Buttons.A };
            var oncearray   = new Buttons[] { Buttons.B, Buttons.Y, Buttons.X, Buttons.DPadUp,
                                              Buttons.DPadLeft, Buttons.DPadDown, Buttons.DPadRight, Buttons.Back, Buttons.Start, Buttons.LeftShoulder,
                                              Buttons.RightShoulder, Buttons.LeftTrigger, Buttons.RightTrigger };

            previousState = currentState;
            currentState  = GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One);


            if (oncearray.Contains <Buttons>(lastButtonPressed))
            {
                ICommand command = new StopCommand(this.instance.Link);
                command.Execute();
            }
            else if (attackarray.Contains <Buttons>(lastButtonPressed))
            {
            }
            else if (buttonarray.Contains <Buttons>(lastButtonPressed) && (!currentState.IsButtonDown(lastButtonPressed)))
            {
                ICommand command = new StopCommand(this.instance.Link);
                command.Execute();
            }

            foreach (Buttons button in buttonarray)
            {
                //if the keys in the keyArray are pressed, execute corresponding command

                if (oncearray.Contains <Buttons>(button))
                {
                    if (currentState.IsButtonDown(button) && !previousState.IsButtonDown(button))
                    {
                        gamepadMappings[button]?.Execute();
                        lastButtonPressed = button;
                    }
                }
                else if (attackarray.Contains <Buttons>(button))
                {
                    if (currentState.IsButtonDown(button) && !previousState.IsButtonDown(button))
                    {
                        gamepadMappings[button]?.Execute();
                        lastButtonPressed = button;
                    }
                }
                else if (buttonarray.Contains <Buttons>(button))
                {
                    if (currentState.IsButtonDown(button))

                    {
                        if ((lastButtonPressed == button) || ((lastButtonPressed != button) && currentState.IsButtonUp(lastButtonPressed)))
                        {
                            gamepadMappings[button]?.Execute();
                            lastButtonPressed = button;
                        }
                    }
                }
            }
        }
Example #34
0
        public MenuResult Update(GameTime gameTime)
        {
            cooldown -= gameTime.ElapsedGameTime.Milliseconds;
            if (cooldown < 0)
            {
                cooldown = 0;
            }
            if (state == SummaryMenuState.WAIT && animateTime > 1000)
            {
                SoundEffects.PlayClick();
                result = MenuResult.GoToResults;
                String nextText = null;
                if (TutorialStage.controlLessonIndex == TutorialStage.introIndex)
                {
                    optionList = new List <MenuOption>();
                }
                else
                {
                    optionList = new List <MenuOption>();
                    optionList.Add(new MenuOption(MenuResult.GoToResults, "Continue"));
                }
                state    = SummaryMenuState.READY;
                nextText = TutorialStage.IntroText();
                text     = nextText;
                cooldown = 250;
            }
            if (state == SummaryMenuState.NURSEIN || state == SummaryMenuState.NURSEOUT || state == SummaryMenuState.WAIT)
            {
                animateTime += gameTime.ElapsedGameTime.Milliseconds;
            }
            if (state == SummaryMenuState.NURSEIN && animateTime > 250)
            {
                state = SummaryMenuState.READY;
            }
            if (state == SummaryMenuState.NURSEOUT && animateTime > 250)
            {
                animateTime = 0;
                state       = SummaryMenuState.NURSEIN;
                return(result);
            }
            if (state == SummaryMenuState.READY && cooldown == 0)
            {
                GamePadState gamePadState = GamePad.GetState(Game.playerIndex);
                Vector2      leftStick    = gamePadState.ThumbSticks.Left;
                Vector2      rightStick   = gamePadState.ThumbSticks.Right;
                if (!(TutorialStage.phase != TutorialPhase.None && TutorialStage.introIndex - 1 == TutorialStage.controlLessonIndex))
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A) || gamePadState.IsButtonDown(Buttons.Start))
                    {
                        SoundEffects.PlayClick();
                        result = optionList[selectedOption].result;
                        String nextText = null;
                        if (TutorialStage.phase == TutorialPhase.Intro)
                        {
                            if (TutorialStage.controlLessonIndex == TutorialStage.introIndex)
                            {
                                optionList = new List <MenuOption>();
                            }
                            else
                            {
                                optionList = new List <MenuOption>();
                                optionList.Add(new MenuOption(MenuResult.GoToResults, "Continue"));
                            }
                            nextText = TutorialStage.IntroText();
                        }
                        else if (TutorialStage.phase == TutorialPhase.Pass)
                        {
                            nextText = TutorialStage.SuccessText();
                            if (TutorialStage.IsEndOfSection())
                            {
                                optionList = new List <MenuOption>();
                                optionList.Add(new MenuOption(MenuResult.GoToResults, "Continue"));
                                optionList.Add(new MenuOption(MenuResult.Replay, "Practice"));
                            }
                        }
                        else if (TutorialStage.phase == TutorialPhase.Fail)
                        {
                            nextText = TutorialStage.FailureText();
                            if (TutorialStage.IsEndOfSection())
                            {
                                optionList = new List <MenuOption>();
                                optionList.Add(new MenuOption(MenuResult.Replay, "Try Again"));
                                optionList.Add(new MenuOption(MenuResult.GoToMainMenu, "Main Menu"));
                            }
                        }
                        if (nextText != null)
                        {
                            text     = nextText;
                            cooldown = 250;
                        }
                        else
                        {
                            if ((TutorialStage.phase == TutorialPhase.Pass && result != MenuResult.Replay) || TutorialStage.phase == TutorialPhase.Fail)
                            {
                                return(result);
                            }
                            animateTime = 0;
                            state       = SummaryMenuState.NURSEOUT;
                        }
                    }

                    if (gamePadState.IsButtonDown(Buttons.DPadRight) || gamePadState.IsButtonDown(Buttons.DPadRight) || Keyboard.GetState().IsKeyDown(Keys.Right) || leftStick.X > Game.gameSettings.controlStickTrigger || rightStick.X > Game.gameSettings.controlStickTrigger)
                    {
                        SoundEffects.PlayClick();
                        selectedOption++;
                        if (selectedOption >= optionList.Count())
                        {
                            selectedOption = optionList.Count() - 1;
                        }
                        cooldown = 250;
                    }
                    if (gamePadState.IsButtonDown(Buttons.DPadLeft) || gamePadState.IsButtonDown(Buttons.DPadLeft) || Keyboard.GetState().IsKeyDown(Keys.Left) || leftStick.X < -Game.gameSettings.controlStickTrigger || rightStick.X < -Game.gameSettings.controlStickTrigger)
                    {
                        SoundEffects.PlayClick();
                        selectedOption--;
                        if (selectedOption < 0)
                        {
                            selectedOption = 0;
                        }
                        cooldown = 250;
                    }
                }
                else
                {
                    if (TutorialStage.restrictions == ControlRestrictions.StickOnly && (gamePadState.IsButtonDown(Buttons.DPadUp) || Keyboard.GetState().IsKeyDown(Keys.Up) || gamePadState.ThumbSticks.Left.Y > Game.gameSettings.controlStickTrigger ||
                                                                                        gamePadState.IsButtonDown(Buttons.DPadDown) || Keyboard.GetState().IsKeyDown(Keys.Down) || gamePadState.ThumbSticks.Left.Y < -Game.gameSettings.controlStickTrigger ||
                                                                                        gamePadState.IsButtonDown(Buttons.DPadLeft) || Keyboard.GetState().IsKeyDown(Keys.Left) || gamePadState.ThumbSticks.Left.X > Game.gameSettings.controlStickTrigger ||
                                                                                        gamePadState.IsButtonDown(Buttons.DPadRight) || Keyboard.GetState().IsKeyDown(Keys.Left) || gamePadState.ThumbSticks.Left.X < -Game.gameSettings.controlStickTrigger))
                    {
                        state       = SummaryMenuState.WAIT;
                        animateTime = 0;
                    }
                    if (TutorialStage.restrictions == ControlRestrictions.ShouldersOnly && (gamePadState.IsButtonDown(Buttons.LeftShoulder) || gamePadState.IsButtonDown(Buttons.RightShoulder) || Keyboard.GetState().IsKeyDown(Keys.A) || Keyboard.GetState().IsKeyDown(Keys.S)))
                    {
                        state       = SummaryMenuState.WAIT;
                        animateTime = 0;
                    }
                    if (TutorialStage.restrictions == ControlRestrictions.TriggersOnly && (gamePadState.IsButtonDown(Buttons.LeftTrigger) || gamePadState.IsButtonDown(Buttons.RightTrigger) || Keyboard.GetState().IsKeyDown(Keys.Q) || Keyboard.GetState().IsKeyDown(Keys.W)))
                    {
                        state       = SummaryMenuState.WAIT;
                        animateTime = 0;
                    }
                }
            }
            return(MenuResult.None);
        }
Example #35
0
        private void ProcessInput(float amountOfMovement)
        {
            Vector3 moveVector = new Vector3();

            KeyboardState keys    = Keyboard.GetState();
            GamePadState  buttons = GamePad.GetState(PlayerIndex.One);

            //if (keys.IsKeyDown(Keys.D))
            //    moveVector.X += amountOfMovement;
            //if (keys.IsKeyDown(Keys.A))
            //    moveVector.X -= amountOfMovement;
            //if (keys.IsKeyDown(Keys.S))
            //    moveVector.Z += amountOfMovement;
            //if (keys.IsKeyDown(Keys.W))
            //    moveVector.Z -= amountOfMovement;

            //moveVector.Z += (buttons.DPad.Down == ButtonState.Pressed) ? amountOfMovement : 0.0f;
            //moveVector.X -= (buttons.DPad.Left == ButtonState.Pressed) ? amountOfMovement : 0.0f;
            //moveVector.Z -= (buttons.DPad.Up == ButtonState.Pressed) ? amountOfMovement : 0.0f;
            //moveVector.X += (buttons.DPad.Right == ButtonState.Pressed) ? amountOfMovement : 0.0f;

            angles.Y -= buttons.ThumbSticks.Right.X * amountOfMovement * 0.05f;
            angles.X += buttons.ThumbSticks.Right.Y * amountOfMovement * 0.05f;

            Matrix cameraRotation = Matrix.CreateRotationX(angles.X) * Matrix.CreateRotationY(angles.Y);

            position += Vector3.Transform(moveVector, cameraRotation);

            MouseState currentMouseState = Mouse.GetState();

            if (currentMouseState.RightButton == ButtonState.Pressed && prevMouseState.RightButton == ButtonState.Released)
            {
                Mouse.SetPosition(widthOver2, heightOver2);
            }
            else if (currentMouseState.RightButton == ButtonState.Pressed)
            {
                if (currentMouseState.X != widthOver2)
                {
                    angles.Y -= amountOfMovement / 80.0f * (currentMouseState.X - widthOver2);
                }
                if (currentMouseState.Y != heightOver2)
                {
                    angles.X -= amountOfMovement / 80.0f * (currentMouseState.Y - heightOver2);
                }

                Mouse.SetPosition(widthOver2, heightOver2);
            }

            prevMouseState = currentMouseState;

            if (angles.X > 1.4)
            {
                angles.X = 1.4f;
            }
            if (angles.X < -1.4)
            {
                angles.X = -1.4f;
            }
            if (angles.Y > Math.PI)
            {
                angles.Y -= 2 * (float)Math.PI;
            }
            if (angles.Y < -Math.PI)
            {
                angles.Y += 2 * (float)Math.PI;
            }
        }
Example #36
0
 public ButtonCollection(ref GamePadState padState)
 {
     this._count   = 0;
     this._pressed = (Buttons)0;
     if (padState.IsButtonDown(Buttons.A))
     {
         this._pressed |= Buttons.A;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.B))
     {
         this._pressed |= Buttons.B;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.X))
     {
         this._pressed |= Buttons.X;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.Y))
     {
         this._pressed |= Buttons.Y;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.Start))
     {
         this._pressed |= Buttons.Start;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.Back))
     {
         this._pressed |= Buttons.Back;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.RightTrigger))
     {
         this._pressed |= Buttons.RightTrigger;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.LeftTrigger))
     {
         this._pressed |= Buttons.LeftTrigger;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.RightShoulder))
     {
         this._pressed |= Buttons.RightShoulder;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.LeftShoulder))
     {
         this._pressed |= Buttons.LeftShoulder;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.DPadUp))
     {
         this._pressed |= Buttons.DPadUp;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.DPadRight))
     {
         this._pressed |= Buttons.DPadRight;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.DPadDown))
     {
         this._pressed |= Buttons.DPadDown;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.DPadLeft))
     {
         this._pressed |= Buttons.DPadLeft;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.LeftThumbstickUp))
     {
         this._pressed |= Buttons.LeftThumbstickUp;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.LeftThumbstickRight))
     {
         this._pressed |= Buttons.LeftThumbstickRight;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.LeftThumbstickDown))
     {
         this._pressed |= Buttons.LeftThumbstickDown;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.LeftThumbstickLeft))
     {
         this._pressed |= Buttons.LeftThumbstickLeft;
         this._count++;
     }
 }
Example #37
0
        //Added November 28,2013
        #region Controller Input
        public void getControllerInput(GamePadState gamePadState)
        {
            reset();

            if (gamePadState.IsButtonUp(Buttons.DPadLeft))
            {
                m_WasMoveLeftButtonDown = false;
            }
            else if (gamePadState.IsButtonUp(Buttons.DPadRight))
            {
                m_WasMoveRightButtonDown = false;
            }

            if (gamePadState.IsButtonUp(Buttons.RightThumbstickLeft))
            {
                m_WasMoveCrossLeftButtonDown = false;
            }
            else if (gamePadState.IsButtonUp(Buttons.RightThumbstickRight))
            {
                m_WasMoveCrossRightButtonDown = false;
            }

            if (gamePadState.IsButtonUp(Buttons.RightThumbstickUp))
            {
                m_WasMoveCrossUpButtonDown = false;
            }
            else if (gamePadState.IsButtonUp(Buttons.RightThumbstickDown))
            {
                m_WasMoveCrossDownButtonDown = false;
            }

            if (gamePadState.IsButtonUp(Buttons.A))
            {
                m_WasJumpButtonDown = false;
            }

            if (gamePadState.IsButtonUp(Buttons.RightStick))
            {
                m_WasRainbowButtonDown = false;
            }

            if (gamePadState.IsButtonUp(Buttons.RightTrigger))
            {
                m_WasAttackButtonDown = false;
            }

            if (gamePadState.IsButtonDown(Buttons.DPadLeft) || gamePadState.IsButtonDown(Buttons.LeftThumbstickLeft))
            {
                m_WasMoveLeftButtonDown = true;
            }
            else if (gamePadState.IsButtonDown(Buttons.DPadRight) || gamePadState.IsButtonDown(Buttons.LeftThumbstickRight))
            {
                m_WasMoveRightButtonDown = true;
            }

            if (gamePadState.IsButtonDown(Buttons.RightThumbstickLeft))
            {
                m_WasMoveCrossLeftButtonDown = true;
            }
            else if (gamePadState.IsButtonDown(Buttons.RightThumbstickRight))
            {
                m_WasMoveCrossRightButtonDown = true;
            }

            if (gamePadState.IsButtonDown(Buttons.RightThumbstickUp))
            {
                m_WasMoveCrossUpButtonDown = true;
            }
            else if (gamePadState.IsButtonDown(Buttons.RightThumbstickDown))
            {
                m_WasMoveCrossDownButtonDown = true;
            }

            if (gamePadState.IsButtonDown(Buttons.A))
            {
                m_WasJumpButtonDown = true;
            }

            if (gamePadState.IsButtonDown(Buttons.RightStick))
            {
                m_WasRainbowButtonDown = true;
            }

            if (gamePadState.IsButtonDown(Buttons.RightTrigger))
            {
                m_WasAttackButtonDown = true;
            }
        }
Example #38
0
 public ButtonCollection(ref GamePadState padState, ref GamePadState oldPadState)
 {
     this._count   = 0;
     this._pressed = (Buttons)0;
     if (padState.IsButtonDown(Buttons.A) && !oldPadState.IsButtonDown(Buttons.A))
     {
         this._pressed |= Buttons.A;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.B) && !oldPadState.IsButtonDown(Buttons.B))
     {
         this._pressed |= Buttons.B;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.X) && !oldPadState.IsButtonDown(Buttons.X))
     {
         this._pressed |= Buttons.X;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.Y) && !oldPadState.IsButtonDown(Buttons.Y))
     {
         this._pressed |= Buttons.Y;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.Start) && !oldPadState.IsButtonDown(Buttons.Start))
     {
         this._pressed |= Buttons.Start;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.Back) && !oldPadState.IsButtonDown(Buttons.Back))
     {
         this._pressed |= Buttons.Back;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.RightTrigger) && !oldPadState.IsButtonDown(Buttons.RightTrigger))
     {
         this._pressed |= Buttons.RightTrigger;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.LeftTrigger) && !oldPadState.IsButtonDown(Buttons.LeftTrigger))
     {
         this._pressed |= Buttons.LeftTrigger;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.RightShoulder) && !oldPadState.IsButtonDown(Buttons.RightShoulder))
     {
         this._pressed |= Buttons.RightShoulder;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.LeftShoulder) && !oldPadState.IsButtonDown(Buttons.LeftShoulder))
     {
         this._pressed |= Buttons.LeftShoulder;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.DPadUp) && !oldPadState.IsButtonDown(Buttons.DPadUp))
     {
         this._pressed |= Buttons.DPadUp;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.DPadRight) && !oldPadState.IsButtonDown(Buttons.DPadRight))
     {
         this._pressed |= Buttons.DPadRight;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.DPadDown) && !oldPadState.IsButtonDown(Buttons.DPadDown))
     {
         this._pressed |= Buttons.DPadDown;
         this._count++;
     }
     if (padState.IsButtonDown(Buttons.DPadLeft) && !oldPadState.IsButtonDown(Buttons.DPadLeft))
     {
         this._pressed |= Buttons.DPadLeft;
         this._count++;
     }
     if ((double)padState.ThumbSticks.Left.Y > 0.2 && (double)oldPadState.ThumbSticks.Left.Y <= 0.2 && Utility.thumbstickIsInDirection(0, padState))
     {
         this._pressed |= Buttons.LeftThumbstickUp;
         this._count++;
     }
     if ((double)padState.ThumbSticks.Left.X > 0.2 && (double)oldPadState.ThumbSticks.Left.X <= 0.2 && Utility.thumbstickIsInDirection(1, padState))
     {
         this._pressed |= Buttons.LeftThumbstickRight;
         this._count++;
     }
     if ((double)padState.ThumbSticks.Left.Y < -0.2 && (double)oldPadState.ThumbSticks.Left.Y >= -0.2 && Utility.thumbstickIsInDirection(2, padState))
     {
         this._pressed |= Buttons.LeftThumbstickDown;
         this._count++;
     }
     if ((double)padState.ThumbSticks.Left.X < -0.2 && (double)oldPadState.ThumbSticks.Left.X >= -0.2 && Utility.thumbstickIsInDirection(3, padState))
     {
         this._pressed |= Buttons.LeftThumbstickLeft;
         this._count++;
     }
 }
Example #39
0
        public GamePadState GetState(int index)
        {
            JoystickState joy = Joystick.GetState(index);
            GamePadState pad = new GamePadState();

            if (joy.IsConnected)
            {
                pad.SetConnected(true);
                pad.SetPacketNumber(joy.PacketNumber);

                GamePadConfiguration configuration = GetConfiguration(Joystick.GetGuid(index));

                foreach (GamePadConfigurationItem map in configuration)
                {
                    switch (map.Source.Type)
                    {
                        case ConfigurationType.Axis:
                            {
                                // JoystickAxis -> Buttons/GamePadAxes mapping
                                JoystickAxis source_axis = map.Source.Axis;
                                GamePadAxes target_axis = map.Target.Axis;
                                short value = joy.GetAxisRaw(source_axis);

                                switch (map.Target.Type)
                                {
                                    case ConfigurationType.Axis:
                                        pad.SetAxis(target_axis, value);
                                        break;

                                    case ConfigurationType.Button:
                                        throw new NotImplementedException();
                                        break;
                                }
                            }
                            break;

                        case ConfigurationType.Button:
                            {
                                // JoystickButton -> Buttons/GamePadAxes mapping
                                JoystickButton source_button = map.Source.Button;
                                Buttons target_button = map.Target.Button;
                                bool pressed = joy.GetButton(source_button) == ButtonState.Pressed;

                                switch (map.Target.Type)
                                {
                                    case ConfigurationType.Axis:
                                        throw new NotImplementedException();
                                        break;

                                    case ConfigurationType.Button:
                                        pad.SetButton(target_button, pressed);
                                        break;
                                }
                            }
                            break;
                    }
                }
            }

            return pad;
        }
Example #40
0
        protected void UpdateInput()
        {
            KeyboardState currentKeyState     = Keyboard.GetState();
            GamePadState  currentGamePadState = GamePad.GetState(PlayerIndex.One);

            bool engineon = false;

            if (currentGamePadState.IsConnected)
            {
                //rotate the model using the left thumbstick, and scale it down

                modelYaw -= currentGamePadState.ThumbSticks.Left.X * 0.10f;

                //create some velocity if the right trigger is down

                Vector3 modelVelocityAdd = Vector3.Zero;

                //findout what direction we should be thrusting using rotation
                modelVelocityAdd.X = -(float)Math.Sin(modelYaw);
                modelVelocityAdd.Z = -(float)(Math.Cos(modelYaw) * Math.Cos(modelPitch));
                modelVelocityAdd.Y = (float)(Math.Cos(modelYaw) * Math.Sin(modelPitch));

                //Now scale our direction by how hard the trigger is down
                modelVelocityAdd *= currentGamePadState.Triggers.Right;

                if (currentGamePadState.Triggers.Right != 0f)
                {
                    engineon = true;
                }

                //finally, add this vector to our velocity
                //modelVelocity += modelVelocityAdd;

                GamePad.SetVibration(PlayerIndex.One, currentGamePadState.Triggers.Right, currentGamePadState.Triggers.Right);

                //In case you get lost, press A to warp back to center
                if (currentGamePadState.Buttons.A == ButtonState.Pressed)
                {
                    //modelPosition = startPosition;
                    //modelVelocity = Vector3.Zero;
                    modelYaw = 0.0f;
                }
            }

            if (currentKeyState.IsKeyDown(Keys.A))
            {
                BEPUutilities.Vector3 rot = physicsObject.WorldTransform.Up;
                physicsObject.ApplyAngularImpulse(ref rot);
            }

            if (currentKeyState.IsKeyDown(Keys.D))
            {
                BEPUutilities.Vector3 rot = physicsObject.WorldTransform.Down;
                physicsObject.ApplyAngularImpulse(ref rot);
            }

            if (currentKeyState.IsKeyDown(Keys.S))
            {
                BEPUutilities.Vector3 rot = physicsObject.WorldTransform.Right;
                physicsObject.ApplyAngularImpulse(ref rot);
            }

            if (currentKeyState.IsKeyDown(Keys.X))
            {
                BEPUutilities.Vector3 rot = physicsObject.WorldTransform.Left;
                physicsObject.ApplyAngularImpulse(ref rot);
            }

            if (currentKeyState.IsKeyDown(Keys.Q))
            {
                BEPUutilities.Vector3 rot = physicsObject.WorldTransform.Backward;
                physicsObject.ApplyAngularImpulse(ref rot);
            }

            if (currentKeyState.IsKeyDown(Keys.E))
            {
                BEPUutilities.Vector3 rot = physicsObject.WorldTransform.Forward;
                physicsObject.ApplyAngularImpulse(ref rot);
            }

            if (currentKeyState.IsKeyDown(Keys.W))
            {
                physicsObject.ApplyImpulse(physicsObject.Position, physicsObject.WorldTransform.Forward);
                engineon = true;
            }

            if (currentKeyState.IsKeyDown(Keys.P))
            {
                //modelPosition = Vector3.Zero;
                // modelVelocity = Vector3.Zero;
                soundHyperSpaceActivation.Play();
            }

            if (engineon)
            {
                if (soundEngineInstance.State == SoundState.Stopped)
                {
                    soundEngineInstance.Volume   = 0.75f;
                    soundEngineInstance.IsLooped = true;
                    soundEngineInstance.Play();
                }
                else
                {
                    soundEngineInstance.Resume();
                }
            }
            else
            {
                soundEngineInstance.Pause();
            }
        }
 public void UpdateState()
 {
     this.caps = GamePad.GetCapabilities(this.deviceIndex);
     this.state = GamePad.GetState(this.deviceIndex);
 }
Example #42
0
        void UpdateTitle(GameTime gameTime)
        {
            elapsedMilliseconds -= gameTime.ElapsedGameTime.Milliseconds;

            if (toMenu)
            {
                //Runs once every time the game returns to the menu (not on every loop), use this for single functions
                printString.Do(this, new Vector2(65, 180), "start game", 0.1f, 35, fontSheetSprite, fontSheetTexture);
                printString.Do(this, new Vector2(65, 230), "options", 0.1f, 35, fontSheetSprite, fontSheetTexture);
                printString.Do(this, new Vector2(58, 280), "bonus content", 0.1f, 35, fontSheetSprite, fontSheetTexture);
                printString.Do(this, new Vector2(65, 330), "exit", 0.1f, 35, fontSheetSprite, fontSheetTexture);

                printString.Do(this, new Vector2(0, 0), "Hello", 0.1f, 35, fontSheetSprite, fontSheetTexture);

                toMenu = false;
            }

            currentKeyState = Keyboard.GetState();

            if (oldKeyState == null)
            {
                oldKeyState = currentKeyState;
            }

            currentPadState = GamePad.GetState(PlayerIndex.One);

            if (oldPadState == null)
            {
                oldPadState = currentPadState;
            }

            if ((currentKeyState.IsKeyDown(Keys.Down))) // For navigating the Main Menu     && (oldKeyState.IsKeyUp(Keys.Down)
            {
                if (pointIndex < 3)
                {
                    pointIndex++;
                }
                else
                {
                    pointIndex = 0;
                }
            }
            if ((currentKeyState.IsKeyDown(Keys.S)) && (oldKeyState.IsKeyUp(Keys.S))) // Alternate button navigation (WASD) ((Subject to change when options are up))
            {
                if (pointIndex < 3)
                {
                    pointIndex++;
                }
                else
                {
                    pointIndex = 0;
                }
            }
            if ((currentKeyState.IsKeyDown(Keys.Up)) && (oldKeyState.IsKeyUp(Keys.Up))) // For navigating the Main Menu
            {
                if (pointIndex > 0)
                {
                    pointIndex--;
                }
                else
                {
                    pointIndex = 3;
                }
            }
            if ((currentKeyState.IsKeyDown(Keys.W)) && (oldKeyState.IsKeyUp(Keys.W))) // Alternate button navigation (WASD) ((Subject to change when options are up))
            {
                if (pointIndex > 0)
                {
                    pointIndex--;
                }
                else
                {
                    pointIndex = 3;
                }
            }


            if (pointIndex == 0)
            {
                CurrentPoint = PointingAt.PLAY;

                pointerSprite.UpperLeft = new Vector2(10, 170);
            }
            if (pointIndex == 1)
            {
                CurrentPoint = PointingAt.OPTIONS;

                pointerSprite.UpperLeft = new Vector2(10, 220);
            }
            if (pointIndex == 2)
            {
                CurrentPoint = PointingAt.BONUS;

                pointerSprite.UpperLeft = new Vector2(10, 270);
            }
            if (pointIndex == 3)
            {
                CurrentPoint = PointingAt.EXIT;

                pointerSprite.UpperLeft = new Vector2(10, 320);
            }

            if ((currentKeyState.IsKeyDown(Keys.Enter)) && (oldKeyState.IsKeyUp(Keys.Enter)))
            {
                if (CurrentPoint == PointingAt.PLAY)
                {
                }
                if (CurrentPoint == PointingAt.OPTIONS)
                {
                }
                if (CurrentPoint == PointingAt.BONUS)
                {
                }
                if (CurrentPoint == PointingAt.EXIT)
                {
                    Exit();
                }
            }

            oldKeyState = currentKeyState;
        }
 ////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////
 private void BuildGamePadEvent(GamePadState state, GamePadButton button, ref GamePadEventArgs e)
 {
     e.State = state;
       e.Button = button;
       //e.Vectors.LeftStick = new Vector2(state.ThumbSticks.Left.X, state.ThumbSticks.Left.Y);
       //e.Vectors.RightStick = new Vector2(state.ThumbSticks.Right.X, state.ThumbSticks.Right.Y);
       //e.Vectors.LeftTrigger = state.Triggers.Left;
       //e.Vectors.RightTrigger = state.Triggers.Right;
 }
        /// <summary>
        /// Makes sure the sprite is updated properly.
        /// </summary>
        /// <param name="gameTime"></param>
        public void Update(GameTime gameTime)
        {
            //updating the game input data
            previousGamePadState = gamePadState;
            gamePadState         = GamePad.GetState(0);

            previousKeyboardState = keyboardState;
            keyboardState         = Keyboard.GetState();

            float   t            = (float)gameTime.ElapsedGameTime.TotalSeconds;
            Vector2 acceleration = new Vector2(0, 0);

            //User input
            if (!dead)
            {
                //Gamepad input
                position += gamePadState.ThumbSticks.Left * new Vector2(1, 1);
                if (gamePadState.ThumbSticks.Left.X < 0)
                {
                    flipped = true;
                }
                if (gamePadState.ThumbSticks.Left.X > 0)
                {
                    flipped = false;
                }



                //Keyboard input
                if (keyboardState.IsKeyDown(Keys.W))
                {
                    //position += new Vector2(0, -2);
                    acceleration.Y += -1.1f;
                }
                if (keyboardState.IsKeyDown(Keys.S))
                {
                    //position += new Vector2(0, 2);
                    acceleration.Y += 1.1f;
                }
                if (keyboardState.IsKeyDown(Keys.D))
                {
                    //position += new Vector2(2, 0);
                    acceleration.X += 1.1f;
                    flipped         = false;
                }
                if (keyboardState.IsKeyDown(Keys.A))
                {
                    //position += new Vector2(-2, 0);
                    acceleration.X += -1.1f;
                    flipped         = true;
                }
                if (keyboardState.IsKeyDown(Keys.W) && previousKeyboardState.IsKeyUp(Keys.W))
                {
                    movement.Play();
                }
                if (keyboardState.IsKeyDown(Keys.S) && previousKeyboardState.IsKeyUp(Keys.S))
                {
                    movement.Play();
                }
                if (keyboardState.IsKeyDown(Keys.D) && previousKeyboardState.IsKeyUp(Keys.D))
                {
                    movement.Play();
                }
                if (keyboardState.IsKeyDown(Keys.A) && previousKeyboardState.IsKeyUp(Keys.A))
                {
                    movement.Play();
                }


                velocity += acceleration * t * 150;
                position += velocity * t;
                velocity *= 0.97f;
                if (Math.Abs(velocity.X) <= 2.1)
                {
                    velocity.X = 0;
                }
                if (Math.Abs(velocity.Y) <= 2.1)
                {
                    velocity.Y = 0;
                }


                //Attacking input
                if (keyboardState.IsKeyDown(Keys.Up) && previousKeyboardState.IsKeyUp(Keys.Up))
                {
                    attack = Attack.Up;
                    swordSwing.Play();
                }
                else if (keyboardState.IsKeyDown(Keys.Right) && previousKeyboardState.IsKeyUp(Keys.Right))
                {
                    attack  = Attack.Right;
                    flipped = false;
                    swordSwing.Play();
                }
                else if (keyboardState.IsKeyDown(Keys.Down) && previousKeyboardState.IsKeyUp(Keys.Down))
                {
                    attack = Attack.Down;
                    swordSwing.Play();
                }
                else if (keyboardState.IsKeyDown(Keys.Left) && previousKeyboardState.IsKeyUp(Keys.Left))
                {
                    attack  = Attack.Left;
                    flipped = true;
                    swordSwing.Play();
                }
                else //if(keyboardState.IsKeyUp(Keys.Up) && keyboardState.IsKeyUp(Keys.Right) && keyboardState.IsKeyUp(Keys.Down) && keyboardState.IsKeyUp(Keys.Left))
                {
                    attack = Attack.None;
                }

                if (position.X < 25)
                {
                    position = new Vector2(25, position.Y);
                }
                if (position.Y < 25)
                {
                    position = new Vector2(position.X, 25);
                }
                if (position.X > _worldLength - 100)
                {
                    position = new Vector2(_worldLength - 100, position.Y);
                }
                if (position.Y > 480)
                {
                    position = new Vector2(position.X, 480);
                }
            }

            //collision
            bounds.X = position.X - 10;
            bounds.Y = position.Y - 12;

            swordBoundUp.X    = position.X + 3;
            swordBoundUp.Y    = position.Y - 48;
            swordBoundRight.X = position.X + 16;
            swordBoundRight.Y = position.Y - 2;
            swordBoundDown.X  = position.X;
            swordBoundDown.Y  = position.Y + 16;
            swordBoundLeft.X  = position.X - 48;
            swordBoundLeft.Y  = position.Y - 15;
        }
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////
        private void UpdateGamePad(PlayerIndex playerIndex, GamePadState state, GameTime gameTime)
        {
            GamePadEventArgs e = new GamePadEventArgs(playerIndex);

              //if (state.ThumbSticks.Left != gamePadState.ThumbSticks.Left ||
              //    state.ThumbSticks.Right != gamePadState.ThumbSticks.Right ||
              //    state.Triggers.Left != gamePadState.Triggers.Left ||
              //    state.Triggers.Right != gamePadState.Triggers.Right)
              //{
              //  BuildGamePadEvent(state, GamePadButton.None, ref e);
              //  if (GamePadMove != null) GamePadMove.Invoke(this, e);
              //}

              foreach (InputGamePadButton btn in gamePadButtons)
              {
              ButtonState bs; ;

            if (btn.Button == GamePadButton.None) continue;
            //else if (btn.Button == GamePadButton.A) bs = state.Buttons.A;
            //else if (btn.Button == GamePadButton.B) bs = state.Buttons.B;
            //else if (btn.Button == GamePadButton.Back) bs = state.Buttons.Back;
            //else if (btn.Button == GamePadButton.Down) bs = state.DPad.Down;
            //else if (btn.Button == GamePadButton.Left) bs = state.DPad.Left;
            //else if (btn.Button == GamePadButton.Right) bs = state.DPad.Right;
            //else if (btn.Button == GamePadButton.Start) bs = state.Buttons.Start;
            //else if (btn.Button == GamePadButton.Up) bs = state.DPad.Up;
            //else if (btn.Button == GamePadButton.X) bs = state.Buttons.X;
            //else if (btn.Button == GamePadButton.Y) bs = state.Buttons.Y;
            //else if (btn.Button == GamePadButton.BigButton) bs = state.Buttons.BigButton;
            //else if (btn.Button == GamePadButton.LeftShoulder) bs = state.Buttons.LeftShoulder;
            //else if (btn.Button == GamePadButton.RightShoulder) bs = state.Buttons.RightShoulder;
            //else if (btn.Button == GamePadButton.LeftStick) bs = state.Buttons.LeftStick;
            //else if (btn.Button == GamePadButton.RightStick) bs = state.Buttons.RightStick;
            else bs = GetVectorState(btn.Button, state);

            bool pressed = bs.Pressed;
            if (pressed)
            {
              double ms = gameTime.ElapsedGameTime.TotalMilliseconds;
              if (pressed) btn.Countdown -= ms;
            }

            if ((pressed) && (!btn.Pressed))
            {
              btn.Pressed = true;
              BuildGamePadEvent(state, btn.Button, ref e);

              if (GamePadDown != null) GamePadDown.Invoke(this, e);
              if (GamePadPress != null) GamePadPress.Invoke(this, e);
            }
            else if ((!pressed) && (btn.Pressed))
            {
              btn.Pressed = false;
              btn.Countdown = RepeatDelay;
              BuildGamePadEvent(state, btn.Button, ref e);

              if (GamePadUp != null) GamePadUp.Invoke(this, e);
            }
            else if (btn.Pressed && btn.Countdown < 0)
            {
              e.Button = btn.Button;
              btn.Countdown = RepeatRate;
              BuildGamePadEvent(state, btn.Button, ref e);

              if (GamePadPress != null) GamePadPress.Invoke(this, e);
            }
              }
              gamePadState = state;
        }
        public ISpriteGamePadState HandleInput(Sprite player, GamePadCapabilities cap, GamePadState state)
        {
            if (!IsFiring(state))
            {
                return(new HoldingState());
            }

            if (_shootDelay <= 0)
            {
                state = GamePad.GetState(PlayerIndex.One, GamePadDeadZone.Circular);
                float rotation = state.ThumbSticks.Right.Angle();

                GetNextBullet(rotation, player);
                // TODO: Ammunition check
                //if (GetNextBullet(rotation, player) == null)
                //{
                //    // switch to pistol
                //}
                _shootDelay = ActiveWeapon.ShootDelay;
            }
            return(null);
        }
Example #47
0
 /// <summary>
 /// Updates the specified game pad index.
 /// </summary>
 /// <param name="gamePadIndex">Index of the game pad.</param>
 public override void Update(int gamePadIndex)
 {
     if (XenkoInputDevice.NativeInputManager.HasGamePad)
     {
         state = XenkoInputDevice.NativeInputManager.GetGamePad(0);
     }
 }
Example #48
0
        private void ProcessInput()
        {
            float deltaTime = (float)Game.UpdateTime.Elapsed.TotalSeconds;

            translation = Vector3.Zero;
            yaw         = 0f;
            pitch       = 0f;

            // Keyboard and Gamepad based movement
            {
                // Our base speed is: one unit per second:
                //    deltaTime contains the duration of the previous frame, let's say that in this update
                //    or frame it is equal to 1/60, that means that the previous update ran 1/60 of a second ago
                //    and the next will, in most cases, run in around 1/60 of a second from now. Knowing that,
                //    we can move 1/60 of a unit on this frame so that in around 60 frames(1 second)
                //    we will have travelled one whole unit in a second.
                //    If you don't use deltaTime your speed will be dependant on the amount of frames rendered
                //    on screen which often are inconsistent, meaning that if the player has performance issues,
                //    this entity will move around slower.
                float speed = 1f * deltaTime;

                Vector3 dir = Vector3.Zero;

                if (Gamepad && Input.HasGamePad)
                {
                    GamePadState padState = Input.DefaultGamePad.State;
                    // LeftThumb can be positive or negative on both axis (pushed to the right or to the left)
                    dir.Z += padState.LeftThumb.Y;
                    dir.X += padState.LeftThumb.X;

                    // Triggers are always positive, in this case using one to increase and the other to decrease
                    dir.Y -= padState.LeftTrigger;
                    dir.Y += padState.RightTrigger;

                    // Increase speed when pressing A, LeftShoulder or RightShoulder
                    // Here:does the enum flag 'Buttons' has one of the flag ('A','LeftShoulder' or 'RightShoulder') set
                    if ((padState.Buttons & (GamePadButton.A | GamePadButton.LeftShoulder | GamePadButton.RightShoulder)) != 0)
                    {
                        speed *= SpeedFactor;
                    }
                }

                if (Input.HasKeyboard)
                {
                    // Move with keyboard
                    // Forward/Backward
                    if (Input.IsKeyDown(Keys.W) || Input.IsKeyDown(Keys.Up))
                    {
                        dir.Z += 1;
                    }
                    if (Input.IsKeyDown(Keys.S) || Input.IsKeyDown(Keys.Down))
                    {
                        dir.Z -= 1;
                    }

                    // Left/Right
                    if (Input.IsKeyDown(Keys.A) || Input.IsKeyDown(Keys.Left))
                    {
                        dir.X -= 1;
                    }
                    if (Input.IsKeyDown(Keys.D) || Input.IsKeyDown(Keys.Right))
                    {
                        dir.X += 1;
                    }

                    // Down/Up
                    if (Input.IsKeyDown(Keys.Q))
                    {
                        dir.Y -= 1;
                    }
                    if (Input.IsKeyDown(Keys.E))
                    {
                        dir.Y += 1;
                    }

                    // Increase speed when pressing shift
                    if (Input.IsKeyDown(Keys.LeftShift) || Input.IsKeyDown(Keys.RightShift))
                    {
                        speed *= SpeedFactor;
                    }

                    // If the player pushes down two or more buttons, the direction and ultimately the base speed
                    // will be greater than one (vector(1, 1) is farther away from zero than vector(0, 1)),
                    // normalizing the vector ensures that whichever direction the player chooses, that direction
                    // will always be at most one unit in length.
                    // We're keeping dir as is if isn't longer than one to retain sub unit movement:
                    // a stick not entirely pushed forward should make the entity move slower.
                    if (dir.Length() > 1f)
                    {
                        dir = Vector3.Normalize(dir);
                    }
                }

                // Finally, push all of that to the translation variable which will be used within UpdateTransform()
                translation += dir * KeyboardMovementSpeed * speed;
            }

            // Keyboard and Gamepad based Rotation
            {
                // See Keyboard & Gamepad translation's deltaTime usage
                float   speed    = 1f * deltaTime;
                Vector2 rotation = Vector2.Zero;
                if (Gamepad && Input.HasGamePad)
                {
                    GamePadState padState = Input.DefaultGamePad.State;
                    rotation.X += padState.RightThumb.Y;
                    rotation.Y += -padState.RightThumb.X;
                }

                if (Input.HasKeyboard)
                {
                    if (Input.IsKeyDown(Keys.NumPad2))
                    {
                        rotation.X += 1;
                    }
                    if (Input.IsKeyDown(Keys.NumPad8))
                    {
                        rotation.X -= 1;
                    }

                    if (Input.IsKeyDown(Keys.NumPad4))
                    {
                        rotation.Y += 1;
                    }
                    if (Input.IsKeyDown(Keys.NumPad6))
                    {
                        rotation.Y -= 1;
                    }

                    // See Keyboard & Gamepad translation's Normalize() usage
                    if (rotation.Length() > 1f)
                    {
                        rotation = Vector2.Normalize(rotation);
                    }
                }

                // Modulate by speed
                rotation *= KeyboardRotationSpeed * speed;

                // Finally, push all of that to pitch & yaw which are going to be used within UpdateTransform()
                pitch += rotation.X;
                yaw   += rotation.Y;
            }

            // Mouse movement and gestures
            {
                // This type of input should not use delta time at all, they already are frame-rate independent.
                //    Lets say that you are going to move your finger/mouse for one second over 40 units, it doesn't matter
                //    the amount of frames occuring within that time frame, each frame will receive the right amount of delta:
                //    a quarter of a second -> 10 units, half a second -> 20 units, one second -> your 40 units.

                if (Input.HasMouse)
                {
                    // Rotate with mouse
                    if (Input.IsMouseButtonDown(MouseButton.Right))
                    {
                        Input.LockMousePosition();
                        Game.IsMouseVisible = false;

                        yaw   -= Input.MouseDelta.X * MouseRotationSpeed.X;
                        pitch -= Input.MouseDelta.Y * MouseRotationSpeed.Y;
                    }
                    else
                    {
                        Input.UnlockMousePosition();
                        Game.IsMouseVisible = true;
                    }
                }

                // Handle gestures
                foreach (var gestureEvent in Input.GestureEvents)
                {
                    switch (gestureEvent.Type)
                    {
                    // Rotate by dragging
                    case GestureType.Drag:
                        var drag         = (GestureEventDrag)gestureEvent;
                        var dragDistance = drag.DeltaTranslation;
                        yaw   = -dragDistance.X * TouchRotationSpeed.X;
                        pitch = -dragDistance.Y * TouchRotationSpeed.Y;
                        break;

                    // Move along z-axis by scaling and in xy-plane by multi-touch dragging
                    case GestureType.Composite:
                        var composite = (GestureEventComposite)gestureEvent;
                        translation.X = -composite.DeltaTranslation.X * TouchMovementSpeed.X;
                        translation.Y = -composite.DeltaTranslation.Y * TouchMovementSpeed.Y;
                        translation.Z = (float)Math.Log(composite.DeltaScale + 1) * TouchMovementSpeed.Z;
                        break;
                    }
                }
            }
        }
Example #49
0
        public GamePadState GetState(int index)
        {
            JoystickState joy = Joystick.GetState(index);
            GamePadState pad = new GamePadState();

            if (joy.IsConnected)
            {
                pad.SetConnected(true);
                pad.SetPacketNumber(joy.PacketNumber);

                GamePadConfiguration configuration = GetConfiguration(Joystick.GetGuid(index));

                foreach (GamePadConfigurationItem map in configuration)
                {
                    switch (map.Source.Type)
                    {
                        case ConfigurationType.Axis:
                            {
                                // JoystickAxis -> Buttons/GamePadAxes mapping
                                JoystickAxis source_axis = map.Source.Axis;
                                short value = joy.GetAxisRaw(source_axis);

                                switch (map.Target.Type)
                                {
                                    case ConfigurationType.Axis:
                                        pad.SetAxis(map.Target.Axis, value);
                                        break;

                                    case ConfigurationType.Button:
                                        // Todo: if SDL2 GameController config is ever updated to
                                        // distinguish between negative/positive axes, then remove
                                        // Math.Abs below.
                                        // Button is considered press when the axis is >= 0.5 from center
                                        pad.SetButton(map.Target.Button, Math.Abs(value) >= short.MaxValue >> 1);
                                        break;
                                }
                            }
                            break;

                        case ConfigurationType.Button:
                            {
                                // JoystickButton -> Buttons/GamePadAxes mapping
                                JoystickButton source_button = map.Source.Button;
                                bool pressed = joy.GetButton(source_button) == ButtonState.Pressed;

                                switch (map.Target.Type)
                                {
                                    case ConfigurationType.Axis:
                                        // Todo: if SDL2 GameController config is ever updated to
                                        // distinguish between negative/positive axes, then update
                                        // the following line to support both.
                                        short value = pressed ?
                                            short.MaxValue :
                                            (map.Target.Axis & (GamePadAxes.LeftTrigger | GamePadAxes.RightTrigger)) != 0 ?
                                                short.MinValue :
                                                (short)0;
                                        pad.SetAxis(map.Target.Axis, value);
                                        break;

                                    case ConfigurationType.Button:
                                        pad.SetButton(map.Target.Button, pressed);
                                        break;
                                }
                            }
                            break;

                        case ConfigurationType.Hat:
                            {
                                // JoystickHat -> Buttons/GamePadAxes mapping
                                JoystickHat source_hat = map.Source.Hat;
                                JoystickHatState state = joy.GetHat(source_hat);

                                bool pressed = false;
                                switch (map.Source.HatPosition)
                                {
                                    case HatPosition.Down:
                                        pressed = state.IsDown;
                                        break;

                                    case HatPosition.Up:
                                        pressed = state.IsUp;
                                        break;

                                    case HatPosition.Left:
                                        pressed = state.IsLeft;
                                        break;

                                    case HatPosition.Right:
                                        pressed = state.IsRight;
                                        break;
                                }

                                switch (map.Target.Type)
                                {
                                    case ConfigurationType.Axis:
                                        // Todo: if SDL2 GameController config is ever updated to
                                        // distinguish between negative/positive axes, then update
                                        // the following line to support both.
                                        short value = pressed ?
                                            short.MaxValue :
                                            (map.Target.Axis & (GamePadAxes.LeftTrigger | GamePadAxes.RightTrigger)) != 0 ?
                                                short.MinValue :
                                                (short)0;
                                        pad.SetAxis(map.Target.Axis, value);
                                        break;

                                    case ConfigurationType.Button:
                                        pad.SetButton(map.Target.Button, pressed);
                                        break;
                                }
                            }
                            break;
                    }
                }
            }

            return pad;
        }
Example #50
0
        protected override void Update(GameTime gameTime)
        {
            if (MediaPlayer.State == MediaState.Stopped)
            {
                MediaPlayer.Play(backgroundSong);
            }
            prevState = state;
            state     = GamePad.GetState(PlayerIndex.One);
            state2    = GamePad.GetState(PlayerIndex.Two);
            state3    = GamePad.GetState(PlayerIndex.Three);
            state4    = GamePad.GetState(PlayerIndex.Four);
            if (!state.IsConnected)
            {
                player1.Visible = false;
            }
            else if (!state2.IsConnected)
            {
                player2.Visible = false;
            }
            if (!state3.IsConnected)
            {
                player3.Visible = false;
            }
            if (!state4.IsConnected)
            {
                player4.Visible = false;
            }

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

            // TODO: Add your update logic here
            if (state.Buttons.Start == ButtonState.Pressed && prevState.Buttons.Start != ButtonState.Pressed)
            {
                paused = !paused;
            }

            if (!paused)
            {
                if (screen == ScreenState.Home)
                {
                    if (state.Buttons.A == ButtonState.Pressed)
                    {
                        screen = ScreenState.Single;
                    }
                    else if (state.Buttons.B == ButtonState.Pressed)
                    {
                        screen = ScreenState.Multi;
                    }
                }
                else
                {
                    player1.Update(GraphicsDevice.Viewport.Bounds, projectileSprite, gameTime, PlayerIndex.One);
                    if (screen == ScreenState.Single)
                    {
                        for (int i = 0; i < Denis.projectiles.Count; i++)
                        {
                            if (Denis.projectiles[i].Hitbox.Intersects(player1.Hitbox))
                            {
                                player1.Visible = false;
                            }
                        }
                        Denis.Update(GraphicsDevice.Viewport.Bounds, gameTime, player1.projectiles, projectileSprite, player1.Position, 10);
                        player1.Points = Denis.Points;
                    }
                    else if (screen == ScreenState.Multi)
                    {
                        player2.Update(GraphicsDevice.Viewport.Bounds, projectileSprite, gameTime, PlayerIndex.Two);
                        player3.Update(GraphicsDevice.Viewport.Bounds, projectileSprite, gameTime, PlayerIndex.Three);
                        for (int i = 0; i < player1.projectiles.Count; i++)
                        {
                            if (player1.projectiles[i].Hitbox.Intersects(player2.Hitbox))
                            {
                                player2.Visible = false;
                            }
                            else if (player1.projectiles[i].Hitbox.Intersects(player3.Hitbox))
                            {
                                player3.Visible = false;
                            }
                            else if (player1.projectiles[i].Hitbox.Intersects(player4.Hitbox))
                            {
                                player4.Visible = false;
                            }
                        }
                        for (int i = 0; i < player2.projectiles.Count; i++)
                        {
                            if (player2.projectiles[i].Hitbox.Intersects(player1.Hitbox))
                            {
                                player1.Visible = false;
                            }
                            else if (player2.projectiles[i].Hitbox.Intersects(player3.Hitbox))
                            {
                                player3.Visible = false;
                            }
                            else if (player2.projectiles[i].Hitbox.Intersects(player4.Hitbox))
                            {
                                player4.Visible = false;
                            }
                        }
                        for (int i = 0; i < player3.projectiles.Count; i++)
                        {
                            if (player3.projectiles[i].Hitbox.Intersects(player1.Hitbox))
                            {
                                player1.Visible = false;
                            }
                            else if (player3.projectiles[i].Hitbox.Intersects(player2.Hitbox))
                            {
                                player2.Visible = false;
                            }
                            if (player4.projectiles[i].Hitbox.Intersects(player4.Hitbox))
                            {
                                player4.Visible = false;
                            }
                        }
                        for (int i = 0; i < player4.projectiles.Count; i++)
                        {
                            if (player4.projectiles[i].Hitbox.Intersects(player1.Hitbox))
                            {
                                player1.Visible = false;
                            }
                            else if (player4.projectiles[i].Hitbox.Intersects(player2.Hitbox))
                            {
                                player3.Visible = false;
                            }
                            else if (player4.projectiles[i].Hitbox.Intersects(player3.Hitbox))
                            {
                                player4.Visible = false;
                            }
                        }
                    }
                }
            }

            else
            {
                if (state.Buttons.Y == ButtonState.Pressed)
                {
                    paused = false;
                    screen = ScreenState.Home;
                }
            }

            if (screen == ScreenState.Single)
            {
                if ((state.Buttons.LeftShoulder == ButtonState.Pressed || state2.Buttons.LeftShoulder == ButtonState.Pressed) && !player1.Visible)
                {
                    player1.Position = Vector2.Zero;
                    player1.Visible  = true;
                    player1.Points   = 0;
                    Denis.Points     = 0;
                }
            }

            else if (screen == ScreenState.Multi)
            {
                if ((state.Buttons.LeftShoulder == ButtonState.Pressed || state2.Buttons.LeftShoulder == ButtonState.Pressed || state3.Buttons.LeftShoulder == ButtonState.Pressed || state4.Buttons.LeftShoulder == ButtonState.Pressed) && (!player1.Visible || !player2.Visible || !player3.Visible || !player4.Visible) && screen == ScreenState.Multi)
                {
                    player1.Position = Vector2.Zero;
                    player2.Position = new Vector2(GraphicsDevice.Viewport.Width - characterTexture.Width, GraphicsDevice.Viewport.Height - characterTexture.Height);
                    player3.Position = new Vector2(0, GraphicsDevice.Viewport.Height - characterTexture.Height);
                    player4.Position = new Vector2(GraphicsDevice.Viewport.Width - characterTexture.Width, 0);
                    player1.Visible  = true;
                    player2.Visible  = true;
                    player3.Visible  = true;
                    player4.Visible  = true;
                }
            }
            base.Update(gameTime);
        }
        /// <summary>
        /// Allows this instance to execute custom logic during its <c>Update</c>.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <remarks>
        /// This method will not be executed if it are not <c>Active</c>.
        /// </remarks>
        protected override void Update(TimeSpan gameTime)
        {
            MyScene myscene = this.Scene as MyScene;

            // Set Default
            myscene.buttonA.IsVisible = false;
            myscene.buttonB.IsVisible = false;
            myscene.buttonX.IsVisible = false;
            myscene.buttonY.IsVisible = false;
            myscene.buttonBack.IsVisible = false;
            myscene.buttonStart.IsVisible = false;
            myscene.dpadUp.IsVisible = false;
            myscene.dpadDown.IsVisible = false;
            myscene.dpadLeft.IsVisible = false;
            myscene.dpadRight.IsVisible = false;
            myscene.rightJoystick.FindComponent<SpriteAtlas>().TextureName = "JoyStick";
            myscene.leftJoystick.FindComponent<SpriteAtlas>().TextureName = "JoyStick";
            myscene.leftShoulder.IsVisible = false;
            myscene.rightShoulder.IsVisible = false;
            myscene.leftTrigger.IsVisible = false;
            myscene.rightTrigger.IsVisible = false;

            var inputService = WaveServices.Input;
            if (inputService.GamePadState.IsConnected)
            {
                // A
                if (inputService.GamePadState.Buttons.A == ButtonState.Pressed)
                {
                    myscene.buttonA.IsVisible = true;
                }

                // B
                if (inputService.GamePadState.Buttons.B == ButtonState.Pressed)
                {
                    myscene.buttonB.IsVisible = true;
                }

                // X
                if (inputService.GamePadState.Buttons.X == ButtonState.Pressed)
                {
                    myscene.buttonX.IsVisible = true;
                }

                // Y
                if (inputService.GamePadState.Buttons.Y == ButtonState.Pressed)
                {
                    myscene.buttonY.IsVisible = true;
                }

                // RightShoulder
                if (inputService.GamePadState.Buttons.RightShoulder == ButtonState.Pressed)
                {
                    myscene.rightShoulder.IsVisible = true;
                }

                // LeftShoulder
                if (inputService.GamePadState.Buttons.LeftShoulder == ButtonState.Pressed)
                {
                    myscene.leftShoulder.IsVisible = true;
                }

                // RightStick
                if (inputService.GamePadState.Buttons.RightStick == ButtonState.Pressed)
                {
                    myscene.rightJoystick.FindComponent<SpriteAtlas>().TextureName = "JoyStickPressed";
                }

                // LeftStick
                if (inputService.GamePadState.Buttons.LeftStick == ButtonState.Pressed)
                {
                    myscene.leftJoystick.FindComponent<SpriteAtlas>().TextureName = "JoyStickPressed";
                }

                // Start
                if (inputService.GamePadState.Buttons.Start == ButtonState.Pressed)
                {
                    myscene.buttonStart.IsVisible = true;
                }

                // Back
                if (inputService.GamePadState.Buttons.Back == ButtonState.Pressed)
                {
                    myscene.buttonBack.IsVisible = true;
                }

                // DPad Right
                if (inputService.GamePadState.DPad.Right == ButtonState.Pressed)
                {
                    myscene.dpadRight.IsVisible = true;
                }

                // DPad Left
                if (inputService.GamePadState.DPad.Left == ButtonState.Pressed)
                {
                    myscene.dpadLeft.IsVisible = true;
                }

                // DPad Up
                if (inputService.GamePadState.DPad.Up == ButtonState.Pressed)
                {
                    myscene.dpadUp.IsVisible = true;
                }

                // DPad Down
                if (inputService.GamePadState.DPad.Down == ButtonState.Pressed)
                {
                    myscene.dpadDown.IsVisible = true;
                }

                // Triggers
                if (inputService.GamePadState.Triggers.Right > 0)
                {
                    myscene.rightTrigger.IsVisible = true;
                    myscene.rightTriggerText.Text = "RightTrigger: " + inputService.GamePadState.Triggers.Right;
                }
                else
                {
                    myscene.rightTriggerText.Text = "RightTrigger: 0";
                }

                if (inputService.GamePadState.Triggers.Left > 0)
                {
                    myscene.leftTrigger.IsVisible = true;
                    myscene.leftTriggerText.Text = "LeftTrigger: " + inputService.GamePadState.Triggers.Left;
                }
                else
                {
                    myscene.leftTriggerText.Text = "LeftTrigger: 0";
                }

                // Sticks                              
                myscene.leftJoystick.FindComponent<Transform2D>().LocalX = inputService.GamePadState.ThumbStricks.Left.X * 10;
                myscene.leftJoystick.FindComponent<Transform2D>().LocalY = -inputService.GamePadState.ThumbStricks.Left.Y * 10;
                myscene.leftStickText.Text = "LeftStick: " + inputService.GamePadState.ThumbStricks.Left;

                myscene.rightJoystick.FindComponent<Transform2D>().LocalX = inputService.GamePadState.ThumbStricks.Right.X * 10;
                myscene.rightJoystick.FindComponent<Transform2D>().LocalY = -inputService.GamePadState.ThumbStricks.Right.Y * 10;
                myscene.rightStickText.Text = "RightStick: " + inputService.GamePadState.ThumbStricks.Right;


                beforeGamepadState = inputService.GamePadState;
            }
        }
Example #52
0
        /// <summary>
        /// Updates the state of the camera.
        /// </summary>
        /// <param name="dt">Time since the last frame in seconds.</param>
        /// <param name="keyboardInput">Input for this frame from the keyboard.</param>
        /// <param name="oldMouseInput">Input from the previous frame from the mouse.</param>
        /// <param name="mouseInput">Input for this frame from the mouse.</param>
        /// <param name="gamePadInput">Input for this frame from the game pad.</param>
#if !WINDOWS
        public void Update(float dt, KeyboardState keyboardInput, GamePadState gamePadInput)
        {
            yaw   += gamePadInput.ThumbSticks.Right.X * -1.5f * dt;
            pitch += gamePadInput.ThumbSticks.Right.Y * 1.5f * dt;
 public static bool IsFiring(GamePadState state)
 {
     return(state.Buttons.RightShoulder == ButtonState.Pressed);
 }
Example #54
0
        private void DrawState(ref GamePadState gamepadState)
        {
            var sendState = false;

            // Left & Right Bumpers - Triggers
            if (gamepadState.Buttons.LeftShoulder == ButtonState.Pressed)
            {
                sendState = true;
                spriteBatch.Draw(Textures["LB"], new Vector2(100, 97));
            }
            if (gamepadState.Triggers.Left == 1)
            {
                sendState = true;
                spriteBatch.Draw(Textures["LT"], new Vector2(160, 41));
            }
            if (gamepadState.Buttons.RightShoulder == ButtonState.Pressed)
            {
                sendState = true;
                spriteBatch.Draw(Textures["RB"], new Vector2(514, 97));
            }
            if (gamepadState.Triggers.Right == 1)
            {
                sendState = true;
                spriteBatch.Draw(Textures["RT"], new Vector2(535, 41));
            }

            // Key Buttons
            if (gamepadState.Buttons.A == ButtonState.Pressed)
            {
                sendState = true;
                spriteBatch.Draw(Textures["A"], new Vector2(547, 269));
            }

            if (gamepadState.Buttons.B == ButtonState.Pressed)
            {
                sendState = true;
                spriteBatch.Draw(Textures["B"], new Vector2(606, 221));
            }

            if (gamepadState.Buttons.Y == ButtonState.Pressed)
            {
                sendState = true;
                spriteBatch.Draw(Textures["Y"], new Vector2(553, 177));
            }

            if (gamepadState.Buttons.X == ButtonState.Pressed)
            {
                sendState = true;
                spriteBatch.Draw(Textures["X"], new Vector2(497, 226));
            }

            // Sticks
            if (gamepadState.Buttons.LeftStick == ButtonState.Pressed)
            {
                sendState = true;
                spriteBatch.Draw(Textures["LeftStickClick"], new Vector2(119, 233));
            }

            if (gamepadState.Buttons.RightStick == ButtonState.Pressed)
            {
                sendState = true;
                spriteBatch.Draw(Textures["LeftStickClick"], new Vector2(423, 335));
            }

            if (gamepadState.ThumbSticks.Left.X != 0 || gamepadState.ThumbSticks.Left.Y != 0)
            {
                sendState = true;
                var xStart = 162;
                var yStart = 270;
                var point1 = new Vector2(xStart, yStart);
                var point2 = GetStickDirection(ref gamepadState, xStart, yStart, true);
                DrawLine(point1, point2);
            }

            if (gamepadState.ThumbSticks.Right.X != 0 || gamepadState.ThumbSticks.Right.Y != 0)
            {
                sendState = true;
                var xStart = 467;
                var yStart = 373;
                var point1 = new Vector2(xStart, yStart);
                var point2 = GetStickDirection(ref gamepadState, xStart, yStart, false);
                DrawLine(point1, point2);
            }

            // D-Pad
            if (gamepadState.DPad.Left == ButtonState.Pressed)
            {
                sendState = true;
                spriteBatch.Draw(Textures["DPadLeft"], new Vector2(215, 336));
            }

            if (gamepadState.DPad.Down == ButtonState.Pressed)
            {
                sendState = true;
                spriteBatch.Draw(Textures["DPadDown"], new Vector2(241, 369));
            }

            if (gamepadState.DPad.Right == ButtonState.Pressed)
            {
                sendState = true;
                spriteBatch.Draw(Textures["DPadRight"], new Vector2(287, 340));
            }

            if (gamepadState.DPad.Up == ButtonState.Pressed)
            {
                sendState = true;
                spriteBatch.Draw(Textures["DPadUp"], new Vector2(243, 315));
            }

            // Menus
            if (gamepadState.Buttons.Start == ButtonState.Pressed)
            {
                sendState = true;
                spriteBatch.Draw(Textures["Start"], new Vector2(428, 237));
            }

            if (gamepadState.Buttons.Back == ButtonState.Pressed)
            {
                sendState = true;
                spriteBatch.Draw(Textures["Back"], new Vector2(279, 236));
            }
            if (sendState && SynchronousSocketClient.delayState.ElapsedMilliseconds > Program.config.ClientUpdateRate)
            {
                sendState = true;
                SynchronousSocketClient.SendQueue.Enqueue(JsonConvert.SerializeObject(new
                {
                    Buttons     = gamepadState.Buttons,
                    Triggers    = gamepadState.Triggers,
                    DPad        = gamepadState.DPad,
                    leftstickX  = gamepadState.ThumbSticks.Left.X,
                    leftstickY  = gamepadState.ThumbSticks.Left.Y,
                    rightstickX = gamepadState.ThumbSticks.Right.X,
                    rightstickY = gamepadState.ThumbSticks.Right.Y
                }));
                SynchronousSocketClient.delayState.Restart();
            }
        }