예제 #1
0
        internal ControllerState Update(GameTime time)
        {
            lastState    = currentState;
            currentState = GamePad.GetState(PlayerIndex.One);
            if (currentState.IsConnected == false)
            {
                _disconnected = true;
            }
            else if (currentState.IsConnected == true)
            {
                _disconnected = false;
            }

            // Allows the game to exit
            if (currentState.Buttons.Back == ButtonState.Pressed)
            {
                return(ControllerState.Exit);
            }
            if (currentState.Buttons.Start == ButtonState.Pressed && lastState.Buttons.Start == ButtonState.Released)
            {
                _paused = (_paused) ? false : true;
            }

            if (!_paused)
            {
                Vector2 moveUnit = new Vector2(currentState.ThumbSticks.Left.X,
                                               currentState.ThumbSticks.Left.Y);
                if (moveUnit.Length() > 0.1f)
                {
                    Console.Out.WriteLine(moveUnit.ToString());
                    unit.MoveUnit(moveUnit);
                }

                unit.MoveAimer(new Vector2(currentState.ThumbSticks.Right.X,
                                           currentState.ThumbSticks.Right.Y));
            }

            if (currentState.Buttons.RightShoulder == ButtonState.Pressed)
            {
                unit.Fire();
            }

            return(ControllerState.Normal);
        }